Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
The dottie npm package is a utility for safely reading and writing deep properties of objects in JavaScript. It uses dot notation strings to access deeply nested properties and provides a set of functions to manipulate these properties without worrying about whether the intermediate properties exist.
Get
Retrieve the value of a nested property using a dot notation string.
const dottie = require('dottie');
const value = dottie.get({a: {b: {c: 'd'}}}, 'a.b.c'); // 'd'
Set
Set the value of a nested property using a dot notation string. If intermediate properties do not exist, they are created.
const dottie = require('dottie');
const obj = {};
dottie.set(obj, 'a.b.c', 'd'); // obj is now {a: {b: {c: 'd'}}}
Transform
Transform an object with dot notation string keys into a nested object structure.
const dottie = require('dottie');
const obj = { 'a.b.c': 'd' };
const transformed = dottie.transform(obj); // transformed is now {a: {b: {c: 'd'}}}
Exists
Check if a nested property exists within an object using a dot notation string.
const dottie = require('dottie');
const exists = dottie.exists({a: {b: {c: 'd'}}}, 'a.b.c'); // true
Paths
Get an array of dot notation paths for all properties in an object.
const dottie = require('dottie');
const paths = dottie.paths({a: {b: {c: 'd'}}}); // ['a.b.c']
lodash.get is a method from the Lodash library that allows you to access deep properties of an object safely. It is similar to dottie's get function but is part of a larger utility library.
deep-get-set is a small library that provides get and set functions for deep properties of an object, similar to dottie. It does not have as many features as dottie but is lightweight.
object-path is another utility that provides access to deep properties using a similar dot notation. It offers a rich set of methods like dottie and includes additional functionality such as del (delete) and has (check existence).
Dottie helps you easily (and without sacrificing too much performance) look up and play with nested keys in objects, without them throwing up in your face.
npm install dottie
For detailed usage, check source or tests.
Gets nested value, or undefined if unreachable, or a default value if passed.
var values = {
some: {
nested: {
key: 'foobar';
}
},
'some.dot.included': {
key: 'barfoo'
}
}
dottie.get(values, 'some.nested.key'); // returns 'foobar'
dottie.get(values, 'some.undefined.key'); // returns undefined
dottie.get(values, 'some.undefined.key', 'defaultval'); // returns 'defaultval'
dottie.get(values, ['some.dot.included', 'key']); // returns 'barfoo'
Note: lodash.get() also works fine for this
Sets nested value, creates nested structure if needed
dottie.set(values, 'some.nested.value', someValue);
dottie.set(values, ['some.dot.included', 'value'], someValue);
dottie.set(values, 'some.nested.object', someValue, {
force: true // force overwrite defined non-object keys into objects if needed
});
Transform object from keys with dottie notation to nested objects
var values = {
'user.name': 'Gummy Bear',
'user.email': 'gummybear@candymountain.com',
'user.professional.title': 'King',
'user.professional.employer': 'Candy Mountain'
};
var transformed = dottie.transform(values);
/*
{
user: {
name: 'Gummy Bear',
email: 'gummybear@candymountain.com',
professional: {
title: 'King',
employer: 'Candy Mountain'
}
}
}
*/
var values = {
'user_name': 'Mick Hansen',
'user_email': 'maker@mhansen.io'
};
var transformed = dottie.transform(values, { delimiter: '_' });
/*
{
user: {
name: 'Mick Hansen',
email: 'maker@mhansen.io'
}
}
*/
var object = {
a: 1,
b: {
c: 2,
d: { e: 3 }
}
};
dottie.paths(object); // ["a", "b.c", "b.d.e"];
0.3.1
and up ships with dottie.memoizePath: true
by default, if this causes any bugs, please try setting it to false
FAQs
Fast and safe nested object access and manipulation in JavaScript
The npm package dottie receives a total of 1,384,164 weekly downloads. As such, dottie popularity was classified as popular.
We found that dottie demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.