visulima object
Helper functions for working with objects, build on top of
[is-plain-obj][is-plain-obj],
[dot-prop][dot-prop],
[deeks][deeks] and
[type-fest][type-fest]
[][typescript-url] [![npm-image]][npm-url] [![license-image]][license-url]
Daniel Bannert's open source work is supported by the community on GitHub Sponsors
Install
npm install @visulima/object
yarn add @visulima/object
pnpm add @visulima/object
Usage
deleteProperty
escapePath
getProperty
hasProperty
setProperty
deepKeys
deepKeysFromList
isPlainObject
pick
With pick
you pass an object and an array of keys of an object - the props which may stay.
import { pick } from "@visulima/object";
const squirtle = { id: "007", name: "Squirtle", type: "water" };
const newObject = pick(squirtle, ["name", "type"]);
// returns { name: 'Squirtle', type: 'water' }
const doc = { items: { keep: "📌", discard: "✂️" } };
pick(doc, ["items.keep"]);
// returns {items: {keep: '📌'}}
omit
With omit
you pass an object and an array of keys of an object - the props which should be removed.
import { omit } from "@visulima/object";
const squirtle = { id: "007", name: "Squirtle", type: "water" };
const withoutId = omit(squirtle, ["id"]);
// returns { name: 'Squirtle', type: 'water' }
const doc = { items: { keep: "📌", discard: "✂️" } };
omit(doc, ["items.discard"]);
// returns {items: {keep: '📌'}}
Related
- is-plain-object - Returns true if the given value is an object created by the Object constructor.
- [is-plain-obj][is-plain-obj] - Check if a value is a plain object.
- [dot-prop][dot-prop] - Get, set, or delete a property from a nested object using a dot path.
- ts-dot-prop - TypeScript utility to transform nested objects using a dot notation path.
- dset - A tiny (194B) utility for safely writing deep Object values~!
- filter-anything - A simple (TypeScript) integration of "pick" and "omit" to filter props of an object.
Supported Node.js Versions
Libraries in this ecosystem make the best effort to track Node.js’ release schedule.
Here’s a post on why we think this is important.
Contributing
If you would like to help take a look at the list of issues and check our Contributing guidelines.
Note: please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
Credits
License
The visulima object is open-sourced software licensed under the [MIT][license-url]
[typescript-url]: https://www.typescriptlang.org/ "TypeScript" "typescript"
[license-image]: https://img.shields.io/npm/l/@visulima/object?color=blueviolet&style=for-the-badge
[license-url]: LICENSE.md "license"
[npm-image]: https://img.shields.io/npm/v/@visulima/object/latest.svg?style=for-the-badge&logo=npm
[npm-url]: https://www.npmjs.com/package/@visulima/object/v/latest "npm"
[is-plain-obj]: https://github.com/sindresorhus/is-plain-obj
[dot-prop]: https://github.com/sindresorhus/dot-prop
[deeks]: https://github.com/mrodrig/deeks
[type-fest]: https://github.com/sindresorhus/type-fest