pick-omit
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

pick-omit

The two missing object methods we always need.

npm i pick-omit pnpm add pick-omit yarn add pick-omit

API

# ObjectFilterFn src/pick-omit.ts#L3

    # (entry)

      # entry

        [ string, unknown ]

      (entry)  =>

        boolean

# filter(obj, fn) – Filter object with filter function fn. src/pick-omit.ts#L12

    # obj – Object to filter.
    # fn – Filter function receiving [key, value].

    filter<T>(obj, fn)  =>

      Partial<T>
# nonNull(obj) – Filter out nullish values from object. src/pick-omit.ts#L23

    # obj – Object to filter.

    nonNull<T>(obj)  =>

      Pick<T, keyof NonNull<T>>
# omit(obj, props) – Create a new object with certain properties omitted. src/pick-omit.ts#L46

    # obj – Object to omit from.
    # props – Properties to omit.

    omit<T, K>(obj, props)  =>

      Omit<T, K extends readonly U [] ? U : never>
# pick(obj, props) – Pick properties from an object into a new object. src/pick-omit.ts#L33

    # obj – Object to pick from.
    # props – Properties to pick.

    pick<T, K>(obj, props)  =>

      Pick<T, K extends readonly U [] ? U : never>

Credits

Contributing

Fork or edit and submit a PR.

All contributions are welcome!

License

MIT © 2022 stagas

Package Sidebar

Install

npm i pick-omit

Weekly Downloads

73

Version

2.0.1

License

MIT

Unpacked Size

26.5 kB

Total Files

18

Last publish

Collaborators

  • stagas