npm.io
2.0.1 • Published 4 years ago

pick-omit

Licence
MIT
Version
2.0.1
Deps
1
Size
26 kB
Vulns
0
Weekly
0
Stars
2

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

Keywords