diff --git a/src/__snapshots__/index.spec.ts.snap b/src/__snapshots__/index.spec.ts.snap index 72088a3..c3aab77 100644 --- a/src/__snapshots__/index.spec.ts.snap +++ b/src/__snapshots__/index.spec.ts.snap @@ -106,6 +106,7 @@ Array [ "$objectFormat", "$objectDefaults", "$objectAssign", + "$objectKeys", "OBJECT_EXPRESSIONS", "$string", "$stringStartsWith", diff --git a/src/expressions/object.spec.ts b/src/expressions/object.spec.ts index cf8fed2..cd3fc34 100644 --- a/src/expressions/object.spec.ts +++ b/src/expressions/object.spec.ts @@ -359,3 +359,21 @@ describe('$objectAssign', () => { }) }) }) + +test('$objectKeys', () => { + expect( + evaluate( + { + interpreters, + scope: { + $$VALUE: { + key1: 'value1', + key2: 'value2', + key3: 'value3', + }, + }, + }, + ['$objectKeys'] + ) + ).toEqual(['key1', 'key2', 'key3']) +}) diff --git a/src/expressions/object.ts b/src/expressions/object.ts index 854f5cd..d1d9115 100644 --- a/src/expressions/object.ts +++ b/src/expressions/object.ts @@ -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, }