4 Commits

Author SHA1 Message Date
a0dc540a7c 1.0.10 2022-03-08 01:49:39 +01:00
b4f780216f fix(core): update 2022-03-08 01:49:38 +01:00
1ae72169b2 1.0.9 2022-03-08 01:42:40 +01:00
e240c71c83 fix(core): update 2022-03-08 01:42:39 +01:00
4 changed files with 8 additions and 4 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "@pushrocks/smartobject", "name": "@pushrocks/smartobject",
"version": "1.0.8", "version": "1.0.10",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@pushrocks/smartobject", "name": "@pushrocks/smartobject",
"version": "1.0.8", "version": "1.0.10",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"fast-deep-equal": "^3.1.3", "fast-deep-equal": "^3.1.3",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartobject", "name": "@pushrocks/smartobject",
"version": "1.0.8", "version": "1.0.10",
"private": false, "private": false,
"description": "work with objects", "description": "work with objects",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",

View File

@@ -10,6 +10,7 @@ tap.test('should create a smartobject', async () => {
yeah: 'so deep', yeah: 'so deep',
evendeeper: { evendeeper: {
sodeep: 2, sodeep: 2,
deepArray: ['one array', 'two array']
} }
} }
} }

View File

@@ -1,10 +1,13 @@
export const toFlatObject = (objectArg: object) => { export const toFlatObject = (objectArg: object) => {
const returnObject: {[key: string]: any} = {}; const returnObject: {[key: string]: any} = {};
const extractLayer = (subObject: {[key: string]: any}, pathArg: string, loopProtection: object[]) => { const extractLayer = (subObject: {[key: string]: any}, pathArg: string, loopProtection: object[]) => {
if (loopProtection.indexOf(subObject) > -1) {
return;
}
if (subObject) if (subObject)
for (const key of Object.keys(subObject)) { for (const key of Object.keys(subObject)) {
let localPathArg = pathArg; let localPathArg = pathArg;
if (typeof subObject[ key ] === 'object') { if (typeof subObject[ key ] === 'object' && !(subObject[ key ] instanceof Array)) {
const newLoopbackArray = loopProtection.slice(); const newLoopbackArray = loopProtection.slice();
newLoopbackArray.push(subObject); newLoopbackArray.push(subObject);
extractLayer(subObject[ key ], localPathArg ? localPathArg += `.${key}` : key, newLoopbackArray); extractLayer(subObject[ key ], localPathArg ? localPathArg += `.${key}` : key, newLoopbackArray);