Skip to content

Commit

Permalink
feat: add $objectKeys expression
Browse files Browse the repository at this point in the history
  • Loading branch information
simonfan committed Feb 23, 2021
1 parent 55e873e commit e8930cf
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ Array [
"$objectFormat",
"$objectDefaults",
"$objectAssign",
"$objectKeys",
"OBJECT_EXPRESSIONS",
"$string",
"$stringStartsWith",
Expand Down
18 changes: 18 additions & 0 deletions src/expressions/object.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,21 @@ describe('$objectAssign', () => {
})
})
})

test('$objectKeys', () => {
expect(
evaluate(
{
interpreters,
scope: {
$$VALUE: {
key1: 'value1',
key2: 'value2',
key3: 'value3',
},
},
},
['$objectKeys']
)
).toEqual(['key1', 'key2', 'key3'])
})
11 changes: 11 additions & 0 deletions src/expressions/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,20 @@ export const $objectAssign = interpreter(
['object', 'object']
)

/**
* @function $objectKeys
* @param {Object} object
* @returns {String[]}
*/
export const $objectKeys = interpreter(
(obj: PlainObject): string[] => Object.keys(obj),
['object']
)

export const OBJECT_EXPRESSIONS = {
$objectMatches,
$objectFormat,
$objectDefaults,
$objectAssign,
$objectKeys,
}

0 comments on commit e8930cf

Please sign in to comment.