Skip to content

Commit

Permalink
feat: add matchKeys function
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Jun 26, 2024
1 parent 23e8a1e commit 03ec44b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/curry/matchKeys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { isArray } from 'radashi'

export type KeyFilter<T extends object, Key extends keyof T = keyof T> =
| KeyMatcher<T>
| Key[]

export type KeyMatcher<T extends object> = (
value: T[keyof T],
key: keyof T,
obj: T
) => boolean

export const matchKeys = <T extends object, Key extends keyof T = keyof T>(
keys: KeyFilter<T, Key>
): KeyMatcher<T> =>
isArray(keys)
? (_, key, obj) =>
Object.hasOwnProperty.call(obj, key) && keys.includes(key as Key)
: keys
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export * from './curry/callable'
export * from './curry/chain'
export * from './curry/compose'
export * from './curry/debounce'
export * from './curry/matchKeys'
export * from './curry/memo'
export * from './curry/partial'
export * from './curry/partob'
Expand Down

0 comments on commit 03ec44b

Please sign in to comment.