Gathering detailed insights and metrics for dot-prop
Gathering detailed insights and metrics for dot-prop
Gathering detailed insights and metrics for dot-prop
Gathering detailed insights and metrics for dot-prop
Get, set, or delete a property from a nested object using a dot path
npm install dot-prop
99.3
Supply Chain
99.5
Quality
76.9
Maintenance
100
Vulnerability
99.6
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
817 Stars
115 Commits
79 Forks
14 Watching
1 Branches
23 Contributors
Updated on 01 Nov 2024
Minified
Minified + Gzipped
JavaScript (95.73%)
TypeScript (4.27%)
Cumulative downloads
Total Downloads
Last day
-8.2%
4,001,132
Compared to previous day
Last week
2%
23,977,987
Compared to previous week
Last month
17%
97,321,737
Compared to previous month
Last year
2.9%
952,798,927
Compared to previous year
1
5
Get, set, or delete a property from a nested object using a dot path
1npm install dot-prop
1import {getProperty, setProperty, hasProperty, deleteProperty} from 'dot-prop'; 2 3// Getter 4getProperty({foo: {bar: 'unicorn'}}, 'foo.bar'); 5//=> 'unicorn' 6 7getProperty({foo: {bar: 'a'}}, 'foo.notDefined.deep'); 8//=> undefined 9 10getProperty({foo: {bar: 'a'}}, 'foo.notDefined.deep', 'default value'); 11//=> 'default value' 12 13getProperty({foo: {'dot.dot': 'unicorn'}}, 'foo.dot\\.dot'); 14//=> 'unicorn' 15 16getProperty({foo: [{bar: 'unicorn'}]}, 'foo[0].bar'); 17//=> 'unicorn' 18 19// Setter 20const object = {foo: {bar: 'a'}}; 21setProperty(object, 'foo.bar', 'b'); 22console.log(object); 23//=> {foo: {bar: 'b'}} 24 25const foo = setProperty({}, 'foo.bar', 'c'); 26console.log(foo); 27//=> {foo: {bar: 'c'}} 28 29setProperty(object, 'foo.baz', 'x'); 30console.log(object); 31//=> {foo: {bar: 'b', baz: 'x'}} 32 33setProperty(object, 'foo.biz[0]', 'a'); 34console.log(object); 35//=> {foo: {bar: 'b', baz: 'x', biz: ['a']}} 36 37// Has 38hasProperty({foo: {bar: 'unicorn'}}, 'foo.bar'); 39//=> true 40 41// Deleter 42const object = {foo: {bar: 'a'}}; 43deleteProperty(object, 'foo.bar'); 44console.log(object); 45//=> {foo: {}} 46 47object.foo.bar = {x: 'y', y: 'x'}; 48deleteProperty(object, 'foo.bar.x'); 49console.log(object); 50//=> {foo: {bar: {y: 'x'}}}
Get the value of the property at the given path.
Returns the value if any.
Set the property at the given path to the given value.
Returns the object.
Check whether the property at the given path exists.
Returns a boolean.
Delete the property at the given path.
Returns a boolean of whether the property existed before being deleted.
Escape special characters in a path. Useful for sanitizing user input.
1import {getProperty, escapePath} from 'dot-prop'; 2 3const object = { 4 foo: { 5 bar: '👸🏻 You found me Mario!', 6 }, 7 'foo.bar' : '🍄 The princess is in another castle!', 8}; 9const escapedPath = escapePath('foo.bar'); 10 11console.log(getProperty(object, escapedPath)); 12//=> '🍄 The princess is in another castle!'
Returns an array of every path. Non-empty plain objects and arrays are deeply recursed and are not themselves included.
This can be useful to help flatten an object for an API that only accepts key-value pairs or for a tagged template literal.
1import {getProperty, deepKeys} from 'dot-prop'; 2 3const user = { 4 name: { 5 first: 'Richie', 6 last: 'Bendall', 7 }, 8 activeTasks: [], 9 currentProject: null 10}; 11 12for (const property of deepKeys(user)) { 13 console.log(`${property}: ${getProperty(user, property)}`); 14 //=> name.first: Richie 15 //=> name.last: Bendall 16 //=> activeTasks: [] 17 //=> currentProject: null 18}
Sparse arrays are supported. In general, avoid using sparse arrays.
Type: object | array
Object or array to get, set, or delete the path
value.
You are allowed to pass in undefined
as the object to the get
and has
functions.
Type: string
Path of the property in the object, using .
to separate each nested key.
Use \\.
if you have a .
in the key.
The following path components are invalid and results in undefined
being returned: __proto__
, prototype
, constructor
.
Type: unknown
Value to set at path
.
Type: unknown
Default value.
The latest stable version of the package.
Stable Version
2
7.3/10
Summary
dot-prop Prototype Pollution vulnerability
Affected Versions
>= 5.0.0, < 5.1.1
Patched Versions
5.1.1
7.3/10
Summary
dot-prop Prototype Pollution vulnerability
Affected Versions
< 4.2.1
Patched Versions
4.2.1
Reason
no dangerous workflow patterns detected
Reason
security policy file detected
Details
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 16/30 approved changesets -- score normalized to 5
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More