Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Create nested getter properties and any intermediary dot notation (`'a.b.c'`) paths
The set-getter npm package is a utility for defining properties on an object that can be accessed and modified using dot notation. It simplifies the process of setting and getting nested properties.
Setting Nested Properties
This feature allows you to set a nested property on an object using a dot-notated string. The package will create any necessary intermediate objects.
const set = require('set-getter');
let obj = {};
set(obj, 'a.b.c', 'value');
console.log(obj); // { a: { b: { c: 'value' } } }
Getting Nested Properties
Although set-getter is primarily for setting properties, it works well with get-value for retrieving nested properties. This example shows how to get a nested property using a dot-notated string.
const get = require('get-value');
let obj = { a: { b: { c: 'value' } } };
let value = get(obj, 'a.b.c');
console.log(value); // 'value'
Lodash's set function provides similar functionality for setting nested properties. It is part of the larger Lodash utility library, which offers a wide range of functions for manipulating objects, arrays, and other data types. Compared to set-getter, lodash.set is more versatile and is part of a well-maintained and widely-used library.
The dot-prop package allows you to get, set, delete, and check properties on an object using dot notation. It offers a more comprehensive set of features compared to set-getter, including the ability to delete properties and check for their existence.
Create nested getter properties and any intermediary dot notation (
'a.b.c'
) paths
Please consider following this project's author, Brian Woodward, and consider starring the project to show your :heart: and support.
Install with npm:
$ npm install --save set-getter
var getter = require('set-getter');
set-getter works like set-value by adding a property to an object or an object hierarchy using dot notation. The main difference is that the property is added using Object.defineProperty
and is expected to be a getter function that returns a value.
Example
var obj = {};
// root level property
getter(obj, 'foo', function() {
return 'bar';
});
console.log(obj.foo);
//=> 'bar'
// property dot notation
getter(obj, 'bar.baz', function() {
return 'qux';
});
console.log(obj.bar.baz);
//=> 'qux'
// property array notation
getter(obj, ['beep', 'boop'], function() {
return 'bop';
});
console.log(obj.beep.boop);
//=> 'bop'
Defines a getter function on an object using property path notation.
Params
obj
{Object}: Object to add property to.prop
{String|Array}: Property string or array to add.getter
{Function}: Getter function to add as a property.Example
var obj = {};
getter(obj, 'foo', function() {
return 'bar';
});
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
$ npm install && npm test
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb#dev verb-generate-readme && verb
Brian Woodward
Copyright © 2021, Brian Woodward. Released under the MIT License.
This file was generated by verb-generate-readme, v0.8.0, on June 18, 2021.
FAQs
Create nested getter properties and any intermediary dot notation (`'a.b.c'`) paths
We found that set-getter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
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.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.