Skip to content

Commit

Permalink
fix(shared): correct to ignore undefined (#1601)
Browse files Browse the repository at this point in the history
  • Loading branch information
hchlq committed May 15, 2022
1 parent 5f49c09 commit 0aecfe6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion packages/shared/utils/index.test.ts
@@ -1,5 +1,5 @@
import { ref } from 'vue-demi'
import { createFilterWrapper, debounceFilter, increaseWithUnit, throttleFilter } from '.'
import { createFilterWrapper, debounceFilter, increaseWithUnit, objectPick, throttleFilter } from '.'

describe('utils', () => {
it('increaseWithUnit', () => {
Expand All @@ -12,6 +12,11 @@ describe('utils', () => {
expect(increaseWithUnit('100 %', 10)).toEqual('110 %')
expect(increaseWithUnit('var(--cool)', -5)).toEqual('var(--cool)')
})

it('objectPick', () => {
expect(objectPick({ a: 1, b: 2, c: 3 }, ['a', 'b'])).toEqual({ a: 1, b: 2 })
expect(objectPick({ a: 1, b: 2, c: undefined }, ['a', 'b'], true)).toEqual({ a: 1, b: 2 })
})
})

describe('filters', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/utils/index.ts
Expand Up @@ -95,7 +95,7 @@ export function increaseWithUnit(target: string | number, delta: number): string
export function objectPick<O, T extends keyof O>(obj: O, keys: T[], omitUndefined = false) {
return keys.reduce((n, k) => {
if (k in obj) {
if (!omitUndefined || !obj[k] === undefined)
if (!omitUndefined || obj[k] !== undefined)
n[k] = obj[k]
}
return n
Expand Down

0 comments on commit 0aecfe6

Please sign in to comment.