Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a0dc540a7c | |||
| b4f780216f | |||
| 1ae72169b2 | |||
| e240c71c83 |
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@pushrocks/smartobject",
|
||||
"version": "1.0.8",
|
||||
"version": "1.0.10",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@pushrocks/smartobject",
|
||||
"version": "1.0.8",
|
||||
"version": "1.0.10",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"fast-deep-equal": "^3.1.3",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartobject",
|
||||
"version": "1.0.8",
|
||||
"version": "1.0.10",
|
||||
"private": false,
|
||||
"description": "work with objects",
|
||||
"main": "dist_ts/index.js",
|
||||
|
||||
@@ -10,6 +10,7 @@ tap.test('should create a smartobject', async () => {
|
||||
yeah: 'so deep',
|
||||
evendeeper: {
|
||||
sodeep: 2,
|
||||
deepArray: ['one array', 'two array']
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
export const toFlatObject = (objectArg: object) => {
|
||||
const returnObject: {[key: string]: any} = {};
|
||||
const extractLayer = (subObject: {[key: string]: any}, pathArg: string, loopProtection: object[]) => {
|
||||
if (loopProtection.indexOf(subObject) > -1) {
|
||||
return;
|
||||
}
|
||||
if (subObject)
|
||||
for (const key of Object.keys(subObject)) {
|
||||
let localPathArg = pathArg;
|
||||
if (typeof subObject[ key ] === 'object') {
|
||||
if (typeof subObject[ key ] === 'object' && !(subObject[ key ] instanceof Array)) {
|
||||
const newLoopbackArray = loopProtection.slice();
|
||||
newLoopbackArray.push(subObject);
|
||||
extractLayer(subObject[ key ], localPathArg ? localPathArg += `.${key}` : key, newLoopbackArray);
|
||||
|
||||
Reference in New Issue
Block a user