Skip to content

Commit 3c7224f

Browse files
committed
update merge by keys: introduced validate or throw
1 parent 168d785 commit 3c7224f

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/builders/Operators.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,21 +173,29 @@ export class Operators implements WithTaskOptions<Operators> {
173173

174174
arrays = this.values(arrays) as [any, any]
175175

176-
if(arrays.length !== 2) {
177-
throw {
178-
operator: "Merge by keys",
179-
msg: "Expected an array of 2 elements.",
180-
value: arrays
176+
const validateOrThrow = (operator: string, items: any[]) => {
177+
const firstInvalid = items.find(item => !item.isValid)
178+
179+
if(firstInvalid) {
180+
throw {
181+
operator,
182+
...firstInvalid
183+
}
181184
}
182185
}
183186

184-
if(!keys) {
185-
throw {
186-
operator: "Merge by keys",
187+
validateOrThrow("Merge by keys", [
188+
{
189+
isValid: arrays.length === 2,
190+
msg: "Expected an array of 2 elements.",
191+
value: arrays
192+
},
193+
{
194+
isValid: keys,
187195
msg: "Expected a 'true' value for keys.",
188-
value: keys
196+
value: keys,
189197
}
190-
}
198+
])
191199

192200
const [array1, array2] = arrays
193201
const concreteKeys = Array.isArray(keys)

0 commit comments

Comments
 (0)