Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 4 additions & 1 deletion packages/utils/CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
Changes that have landed but are not yet released.

### New Features
- Added `objectEntries`

## [0.1.0] - March 1, 2019

Initial release
Initial release
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