Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
expand-object
Advanced tools
Expand a string into a JavaScript object using a simple notation. Use the CLI or as a node.js lib.
Expand a string into a JavaScript object using a simple notation. Use the CLI or as a node.js lib.
(TOC generated by verb using markdown-toc)
Install with npm
$ npm i expand-object --save
Also see collapse-object, for doing the reverse of this library.
Examples
expand('a')
//=> {a: ''}
expand('a.b')
//=> {a: {b: ''}}
expand('a|b')
//=> {a: '', b: ''}
expand('a|b', {toBoolean: true})
//=> {a: true, b: true}
expand('a:b')
//=> {a: 'b'}
expand('a,b')
//=> ['a', 'b']
Introduced in v0.2.2, some values are cast to their JavaScript type.
Booleans
If the value is "true"
or "false"
it will be coerced to a boolean value.
expand('a:true')
//=> {a: true}
expand('a:false')
//=> {a: false}
Numbers
If the value is an integer it will be coerced to a number.
expand('a:1')
//=> {a: 1}
expand('a:123')
//=> {a: 123}
Regex
If the value is a simple regular expression it will be coerced to a new RegExp()
.
expand('a:/foo/')
//=> {a: /foo/}
expand('a.b.c:/^bar/gmi')
//=> {a: {b: {c: /^bar/gmi}}}
Install with npm
$ npm i expand-object --save
Usage with cli:
❯ expand-object --help
Usage: expand-object [options] <string>
Expand a string into a JavaScript object using a simple notation.
Options:
-h, --help output usage information
-V, --version output the version number
-r, --raw Output as raw javascript object - not stringified
Examples:
$ expand-object "a:b"
$ expand-object --raw "a:b"
$ echo "a:b" | expand-object
To use as a node.js library:
var expand = require('expand-object');
Expand dots into child objects:
expand('a')
//=> {a: ''}
expand('a.b')
//=> {a: {b: ''}}
expand('a.b.c')
//=> {a: {b: {c: ''}}}
expand('a.b.c.d')
//=> {a: {b: {c: {d: ''}}}}
expand-object supports two kinds of siblings, general and adjacent. It's much easier to understand the difference in the last example.
Use pipes (
|
) to expand general siblings:
expand('a|b')
//=> {a: '', b: ''}
expand('a|b|c')
//=> {a: '', b: '', c: ''}
expand('a|b|c|d')
//=> {a: '', b: '', c: '', d: ''}
expand('a:b|c:d')
//=> {a: 'b', c: 'd'}
Use plus (
+
) to expand adjacent siblings:
Adjacent siblings are objects that immediately follow one another.
expand('a:b+c:d')
//=> {a: 'b', c: 'd'}
expand('a.b:c+d:e')
//=> {a: {b: 'c', d: 'e'}}
In the example below:
d
is a sibling to a
d
is a sibling to b
// general siblings
expand('a.b:c|d:e')
//=> { a: { b: 'c' }, d: 'e' }
// adjacent siblings
expand('a.b:c+d:e')
//=> { a: { b: 'c', d: 'e' } }
Expand colons into key-value pairs:
expand('a:b')
//=> {a: 'b'}
expand('a.b:c')
//=> {a: {b: 'c'}}
expand('a.b.c:d')
//=> {a: {b: {c: 'd'}}}
Expand comma separated values into arrays:
expand('a,b')
//=> ['a', 'b']
expand('a,b,c')
//=> ['a', 'b', 'c']
expand('a:b,c,d|e:f,g,h')
//=> {a: ['b', 'c', 'd'], e: ['f', 'g', 'h']}
Expand siblings with comma separated values into arrays:
expand('a:b,c,d|e:f,g,h')
//=> {a: ['b', 'c', 'd'], e: ['f', 'g', 'h']}
Expand children with comma separated values into arrays:
expand('a.b.c:d,e,f|g.h:i,j,k')
//=> {a: { b: {c: ['d', 'e', 'f']}}, g: {h: ['i', 'j', 'k']}}
Expand sibling objects into key-value pairs:
expand('a:b|c:d')
//=> {a: 'b', c: 'd'}
expand('a:b|c:d|e:f')
//=> {a: 'b', c: 'd', e: 'f'}
expand('a:b|c:d|e:f|g:h')
//=> {a: 'b', c: 'd', e: 'f', g: 'h'}
Expand child objects into key-value pairs:
expand('a.b:c')
//=> {a: {b: 'c'}}
expand('a.b.c:d')
//=> {a: {b: {c: 'd'}}}
expand('a.b.c.d:e')
//=> {a: {b: {c: {d: 'e'}}}}
Expand sibling and child objects into key-value pairs:
expand('a:b|c:d')
//=> {a: 'b', c: 'd'}
expand('a.b.c|d.e:f')
//=> {a: {b: {c: ''}}, d: {e: 'f'}}
expand('a.b:c|d.e:f')
//=> {a: {b: 'c'}, d: {e: 'f'}}
expand('a.b.c:d|e.f.g:h')
//=> {a: {b: {c: 'd'}}, e: {f: {g: 'h'}}}
expand-args: Expand parsed command line arguments using expand-object. | homepage
Install dev dependencies:
$ npm i -d && npm test
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Jon Schlinkert
Copyright © 2015 Jon Schlinkert Released under the MIT license.
This file was generated by verb on December 23, 2015.
FAQs
Expand a string into a JavaScript object using a simple notation. Use the CLI or as a node.js lib.
We found that expand-object 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.