Skip to content

Commit bd49de0

Browse files
authored
feat(utils): Add objectEntries to utils package (#271)
Summary: Add objectEntries to utils package Test plan: Unit tests
1 parent fe0b904 commit bd49de0

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

packages/utils/CHANGELOG.MD

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77
## [Unreleased]
88
Changes that have landed but are not yet released.
99

10+
### New Features
11+
- Added `objectEntries`
12+
1013
## [0.1.0] - March 1, 2019
1114

12-
Initial release
15+
Initial release

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)