Socket
Socket
Sign inDemoInstall

set-value

Package Overview
Dependencies
2
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    set-value

Create nested values and any intermediaries using dot notation (`'a.b.c'`) paths.


Version published
Maintainers
1
Install size
16.9 kB
Created

Package description

What is set-value?

The set-value npm package is a utility for setting deeply nested values within an object using dot-path notation or by providing a path array. It is useful for updating values in a mutable way without directly accessing properties, especially when dealing with complex or deeply nested objects.

What are set-value's main functionalities?

Set nested values using dot-path

This feature allows you to set a value at a nested path within an object using a string dot-path notation.

const setValue = require('set-value');
const obj = {};
setValue(obj, 'a.b.c', 'value');
console.log(obj); //=> { a: { b: { c: 'value' } } }

Set nested values using array-path

This feature allows you to set a value at a nested path within an object using an array to describe the path.

const setValue = require('set-value');
const obj = {};
setValue(obj, ['a', 'b', 'c'], 'value');
console.log(obj); //=> { a: { b: { c: 'value' } } }

Set multiple values

This feature allows you to set multiple values at different paths within the same object.

const setValue = require('set-value');
const obj = {};
setValue(obj, 'a.b.c', 'value1');
setValue(obj, 'x.y.z', 'value2');
console.log(obj); //=> { a: { b: { c: 'value1' } }, x: { y: { z: 'value2' } } }

Other packages similar to set-value

Readme

Source

set-value NPM version Build Status

Create nested values and any intermediaries using dot notation ('a.b.c') paths.

Install with npm

npm i set-value --save

Usage

var set = require('set-value');

var obj = {};
set(obj, 'a.b.c', 'd');
console.log(obj);
//=> {a: {b: c: 'd'}}
  • any: Returns true if a value exists in the given string, array or object.
  • get-value: Use property paths ( a.b.c) get a nested value from an object.
  • has-own-deep: Returns true if an object has an own, nested property using dot notation paths ('a.b.c').
  • has-value: Returns true if a value exists, false if empty. Works with deeply nested values using… more
  • has-any: Returns true if an object has any of the specified keys.
  • has-any-deep: Return true if key exists deeply on the given object.

Running tests

Install dev dependencies:

npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Author

Jon Schlinkert

License

Copyright (c) 2015 Jon Schlinkert Released under the MIT license.


This file was generated by verb-cli on May 12, 2015.

Keywords

FAQs

Last updated on 12 May 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc