Gathering detailed insights and metrics for dot-object
Gathering detailed insights and metrics for dot-object
Gathering detailed insights and metrics for dot-object
Gathering detailed insights and metrics for dot-object
npm install dot-object
96.2
Supply Chain
99.1
Quality
75.9
Maintenance
100
Vulnerability
98.6
License
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
472 Stars
331 Commits
46 Forks
6 Watching
14 Branches
12 Contributors
Updated on 22 Nov 2024
Minified
Minified + Gzipped
JavaScript (99.53%)
Smarty (0.47%)
Cumulative downloads
Total Downloads
Last day
-1%
68,680
Compared to previous day
Last week
5.1%
386,231
Compared to previous week
Last month
2.9%
1,580,354
Compared to previous month
Last year
26.7%
17,649,615
Compared to previous year
Dot-Object makes it possible to transform javascript objects using dot notation.
Install from npm:
npm install dot-object --save
Install from bower:
bower install dot-object --save
1var dot = require('dot-object'); 2 3var obj = { 4 'first_name': 'John', 5 'last_name': 'Doe' 6}; 7 8dot.move('first_name', 'contact.firstname', obj); 9dot.move('last_name', 'contact.lastname', obj); 10 11console.log(obj); 12 13{ 14 contact: { 15 firstname: 'John', 16 lastname: 'Doe' 17 } 18} 19
1var dot = require('dot-object'); 2 3var src = { 4 name: 'John', 5 stuff: { 6 phone: { 7 brand: 'iphone', 8 version: 6 9 } 10 } 11}; 12 13var tgt = {name: 'Brandon'}; 14 15dot.copy('stuff.phone', 'wanna.haves.phone', src, tgt); 16 17console.log(tgt); 18 19{ 20 name: 'Brandon', 21 wanna: { 22 haves: { 23 phone: { 24 brand: 'iphone', 25 version: 6 26 } 27 } 28 } 29} 30
Does the same as copy but removes the value from the source object:
1dot.transfer('stuff.phone', 'wanna.haves.phone', src, tgt); 2 3// src: {"name":"John","stuff":{}} 4// tgt: {"name":"Brandon","wanna":{"haves":{"phone":{"brand":"iphone","version":6}}}
1var dot = require('dot-object'); 2 3var row = { 4 'id': 2, 5 'contact.name.first': 'John', 6 'contact.name.last': 'Doe', 7 'contact.email': 'example@gmail.com', 8 'contact.info.about.me': 'classified', 9 'devices[0]': 'mobile', 10 'devices[1]': 'laptop', 11 'some.other.things.0': 'this', 12 'some.other.things.1': 'that' 13}; 14 15dot.object(row); 16 17console.log(row); 18 19{ 20 "id": 2, 21 "contact": { 22 "name": { 23 "first": "John", 24 "last": "Doe" 25 }, 26 "email": "example@gmail.com", 27 "info": { 28 "about": { 29 "me": "classified" 30 } 31 } 32 }, 33 "devices": [ 34 "mobile", 35 "laptop" 36 ], 37 "some": { 38 "other": { 39 "things": [ 40 "this", 41 "that" 42 ] 43 } 44 } 45}
To convert manually per string use:
1var dot = require('dot-object'); 2 3var tgt = { val: 'test' }; 4dot.str('this.is.my.string', 'value', tgt); 5 6console.log(tgt); 7 8{ 9 "val": "test", 10 "this": { 11 "is": { 12 "my": { 13 "string": "value" 14 } 15 } 16 } 17}
Picks a value from the object without removing it.
1var dot = require('dot-object'); 2 3var obj = { 4 some: { 5 nested: { 6 value: 'Hi there!' 7 } 8 } 9}; 10 11var val = dot.pick('some.nested.value', obj); 12console.log(val); 13 14Hi there!
Remove and delete mostly behave the same, but in case of a path addressing array items:
delete
will re-index the array.remove
will retain array indexes1var dot = require('dot-object'); 2 3var obj = { 4 a: 'Hi There!', 5 nested: { 6 array: [ 7 'Veni', 8 'Vidi', 9 'Vici', 10 ] 11 } 12}; 13 14var val = dot.delete('a', obj); 15console.log(val); 16 17Hi There! 18 19// To remove an item and directly update any array indexes use: 20var val = dot.delete('nested.array[1]', obj); 21console.log(val); 22 23Vidi 24 25// Remove a value but retain array indexes. 26var val = dot.remove('nested.array[1]', obj); 27 28// To remove multiple paths at once: 29var val = dot.remove(['nested.array[0]', 'nested.array[2]'], obj);
You can use modifiers to translate values on the fly.
This example uses the underscore.string library.
1var dot = require('dot-object'); 2 3var _s = require('underscore.string'); 4 5var row = { 6 'nr': 200, 7 'doc.name': ' My Document ' 8}; 9 10var mods = { 11 "doc.name": [_s.trim, _s.underscored], 12}; 13 14dot.object(row, mods); 15 16console.log(row);
{
"nr": 200,
"doc": {
"name": "my_document"
}
}
Or using .str() directy:
1 2var dot = require('dot-object'); 3var _s = require('underscore.string'); 4var obj = { id: 100 }; 5 6// use one modifier 7dot.str('my.title', 'this is my title', obj, _s.slugify); 8 9// multiple modifiers 10dot.str('my.title', ' this is my title ', obj, [_s.trim, _s.slugify]); 11 12console.log(obj);
Result:
1{ 2 "id": 100, 3 "my": { 4 "title": "this-is-my-title" 5 } 6}
1var dot = require('dot-object'); 2 3var source = { 4 "id": 1, 5 "contact": { 6 "firstName": "John", 7 "lastName": "Doe", 8 "email": "example@gmail.com", 9 } 10} 11 12var recipe = { 13 'id': 'nr', 14 'contact.firstName': 'name.first', 15 'contact.lastName': 'name.last', 16 'contact.email': 'email' 17}; 18 19var tgt = {} 20dot.transform(recipe, source, tgt); 21 22// OR 23 24var tgt = dot.transform(recipe, source); 25 26console.log(tgt); 27{ 28 "nr": 1, 29 "name": { 30 "first": "John", 31 "last": "Doe" 32 }, 33 "email": "example@gmail.com" 34}
1var dot = require('dot-object'); 2 3var obj = { 4 id: 'my-id', 5 nes: { ted: { value: true } }, 6 other: { nested: { stuff: 5 } }, 7 some: { array: ['A', 'B'] } 8}; 9 10var tgt = dot.dot(obj); 11 12// or 13 14var tgt = {}; 15dot.dot(obj, tgt); 16 17console.log(tgt);
Result:
1{ 2 "id": "my-id", 3 "nes.ted.value": true, 4 "other.nested.stuff": 5, 5 "some.array[0]": "A", 6 "some.array[1]": "B" 7}
Set keepArray to true.
1var dot = require('dot-object'); 2 3var obj = { 4 id: 'my-id', 5 other: [1, 2, 3], 6 some: { array: ['A', 'B'] } 7}; 8 9dot.keepArray = true; 10var tgt = dot.dot(obj); 11 12console.log(tgt);
Result:
1{ 2 "id": "my-id", 3 "other": [1, 2, 3], 4 "some.array": ["A", "B"] 5}
If you do not like dot notation, you are free to specify a different separator.
1var Dot = require('dot-object'); 2 3var dot = new Dot('->'); 4 5var _s = require('underscore.string'); 6 7var row = { 8 'nr': 200, 9 'doc->name': ' My Document ' 10}; 11 12var mods = { 13 "doc->name": [_s.trim, _s.underscored], 14}; 15 16dot.object(row, mods); 17 18console.log(row);
{
"nr": 200,
"doc": {
"name": "my_document"
}
}
SQL translation on the fly:
1 // TODO 2
Copyright © 2013 Rob Halff, released under the MIT license
The latest stable version of the package.
Stable Version
1
6.3/10
Summary
Prototype Pollution in dot-object
Affected Versions
< 2.1.3
Patched Versions
2.1.3
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 4/26 approved changesets -- score normalized to 1
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
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