@thefoot/dot-object-expander
v1.0.2
Published
A recursive object parser that expands keys with dot notation.
Downloads
205
Readme
Dot Object Expander
A small module that expands object keys with dot notation into full objects.
It is a simple recursive wrapper around the dot-object library dot.object
method. It also checks for circular references before attempting to parse.
This was built primarily to parse API nested object queries into proper format for MongoDB, as some versions of MongoDB drivers do not support dot notation in key names.
Installation
npm i @thefoot/dot-object-expander --save
Usage
NodeJS
const dotObjectExpander = require ( '@thefoot/dot-object-expander' );
console.log( dotObjectExpander ( {
string : 'bar',
int : 123,
float : 1.234,
boolean : true,
'obj.foo' : {
'bar.baz': 123
},
'org.user.type': {
admin: {
'has.permissions.admin': true
},
ary : [ 1, 2, 3 ]
}
} ) );
// Result:
{
"string": "bar",
"int": 123,
"float": 1.234,
"boolean": true,
"obj": {
"foo": {
"bar": {
"baz": 123
}
}
},
"org": {
"user": {
"type": {
"admin": {
"has": {
"permissions": {
"admin": true
}
}
},
"ary": [
1,
2,
3
]
}
}
}
}
ES Module
ES Module-aware environments such as Webpack and Rollup bundlers should automatically use the dist/parser.esm.js
export.
import dotObjectExpander from '@thefoot/dot-object-expander';
dotObjectExpander({
'org.user.type': {
admin: {
'has.permissions.admin': true
},
ary : [ 1, 2, 3 ]
}
});
Browser
Unminified with comments
<script src="https://unpkg.com/dot-object-expander/dist/parser.js"></script>
<script>
var parsed = dotObjectExpander({
'org.user.type': {
admin: {
'has.permissions.admin': true
},
ary : [ 1, 2, 3 ]
}
});
// ...
</script>
Minified with source map
<script src="https://unpkg.com/dot-object-expander/dist/parser.min.js"></script>
<script>
var parsed = dotObjectExpander({
'org.user.type': {
admin: {
'has.permissions.admin': true
},
ary : [ 1, 2, 3 ]
}
});
// ...
</script>
Contributing
Contributions welcome, please read CONTRIBUTING and CODING-STANDARDS.
Credits
Rob Halff for his dot-object library.
Author
Contributors
- .