Skip to content

Commit 68d8cbc

Browse files
committed
fix: 'keys' method now returns empty array for non-object inputs
1 parent 6f4dc6a commit 68d8cbc

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

async.test.js

+6
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,12 @@ modes.forEach((logic) => {
626626
}
627627
})
628628
expect(answer).toStrictEqual(['a', 'b'])
629+
630+
const answer2 = await logic.run({
631+
keys: 'foo'
632+
})
633+
634+
expect(answer2).toStrictEqual([])
629635
})
630636

631637
test('substr', async () => {

defaultMethods.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ const defaultMethods = {
369369
'!': (value) => Array.isArray(value) ? !value[0] : !value,
370370
'!!': (value) => Boolean(Array.isArray(value) ? value[0] : value),
371371
cat: (arr) => (typeof arr === 'string' ? arr : arr.join('')),
372-
keys: (obj) => Object.keys(obj),
372+
keys: (obj) => typeof obj === 'object' ? Object.keys(obj) : [],
373373
eachKey: {
374374
traverse: false,
375375
method: (object, context, above, engine) => {

test.js

+6
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,12 @@ modes.forEach((logic) => {
652652
})
653653

654654
expect(answer).toStrictEqual(['a', 'b'])
655+
656+
const answer2 = logic.run({
657+
keys: 'foo'
658+
})
659+
660+
expect(answer2).toStrictEqual([])
655661
})
656662

657663
test('substr', () => {

0 commit comments

Comments
 (0)