Skip to content

feat(utils): Add objectEntries to utils package #271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 15, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/utils/__tests__/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// <reference types="jest" />
import { isValidEnum, groupBy, objectValues, find, keyBy, sprintf } from '../src'
import { isValidEnum, groupBy, objectEntries, objectValues, find, keyBy, sprintf } from '../src'

describe('utils', () => {
describe('isValidEnum', () => {
Expand Down Expand Up @@ -37,6 +37,12 @@ describe('utils', () => {
})
})

describe('objectEntries', () => {
it('should return object entries', () => {
expect(objectEntries({ foo: 'bar', bar: 123 })).toEqual([['foo', 'bar'], ['bar', 123]])
})
})

describe('objectValues', () => {
it('should return object values', () => {
expect(objectValues({ foo: 'bar', bar: 123 })).toEqual(['bar', 123])
Expand Down
4 changes: 4 additions & 0 deletions packages/utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ export function objectValues<K>(obj: { [key: string]: K }): K[] {
return Object.keys(obj).map(key => obj[key])
}

export function objectEntries<K>(obj: { [key: string]: K }): [string, K][] {
return Object.keys(obj).map(key => [key, obj[key]])
}

export function find<K>(arr: K[], cond: (arg: K) => boolean): K | undefined {
let found

Expand Down