Skip to content

Commit 69ec720

Browse files
author
Matt Carroll
committed
Add objectEntries to utils package
1 parent 057a219 commit 69ec720

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

packages/utils/__tests__/utils.spec.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// <reference types="jest" />
2-
import { isValidEnum, groupBy, objectValues, find, keyBy, sprintf } from '../src'
2+
import { isValidEnum, groupBy, objectEntries, objectValues, find, keyBy, sprintf } from '../src'
33

44
describe('utils', () => {
55
describe('isValidEnum', () => {
@@ -37,6 +37,12 @@ describe('utils', () => {
3737
})
3838
})
3939

40+
describe('objectEntries', () => {
41+
it('should return object entries', () => {
42+
expect(objectEntries({ foo: 'bar', bar: 123 })).toEqual([['foo', 'bar'], ['bar', 123]])
43+
})
44+
})
45+
4046
describe('objectValues', () => {
4147
it('should return object values', () => {
4248
expect(objectValues({ foo: 'bar', bar: 123 })).toEqual(['bar', 123])

packages/utils/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ export function objectValues<K>(obj: { [key: string]: K }): K[] {
6262
return Object.keys(obj).map(key => obj[key])
6363
}
6464

65+
export function objectEntries<K>(obj: { [key: string]: K }): [string, K][] {
66+
return Object.keys(obj).map(key => [key, obj[key]])
67+
}
68+
6569
export function find<K>(arr: K[], cond: (arg: K) => boolean): K | undefined {
6670
let found
6771

0 commit comments

Comments
 (0)