+23
-3
@@ -21,3 +21,3 @@ /** | ||
| obj.forEach((i) => { | ||
| res.push(this.cloneDeep(i)); | ||
| res.push(cloneDeep(i)); | ||
| }); | ||
@@ -28,3 +28,3 @@ return res; | ||
| Object.keys(obj).forEach((k) => { | ||
| res[k] = this.cloneDeep(obj[k]); | ||
| res[k] = cloneDeep(obj[k]); | ||
| }); | ||
@@ -101,2 +101,21 @@ } else { | ||
| /** | ||
| * Очистка объекта с данными от служебных свойств | ||
| * @param {Object} obj обрабатываемый объект | ||
| * @param {Array<string>} prefixes префиксы свойств, которые нужно удалить из obj | ||
| */ | ||
| function clearObj(obj, prefixes= ['__','_']) { | ||
| if (obj instanceof Object) { | ||
| for (const prop in obj) { | ||
| if (prefixes.some(prefix => prop.startsWith(prefix))) { | ||
| delete obj[prop]; | ||
| } else { | ||
| const o = obj[prop]; | ||
| if (o instanceof Object) clearObj(o); | ||
| } | ||
| } | ||
| } | ||
| return obj; | ||
| } | ||
| export { | ||
@@ -107,3 +126,4 @@ isEmpty, | ||
| getPath, | ||
| compose | ||
| compose, | ||
| clearObj | ||
| }; |
+8
-0
@@ -269,2 +269,9 @@ import fs from 'fs/promises'; | ||
| function getExtensionsMetaByName(name, extension) { | ||
| if(extension) { | ||
| return sortedExtensions.find((m) => m.name === extension).meta[name]; | ||
| } | ||
| return sortedExtensions.map(x => x?.meta[name]).filter(x => x); | ||
| } | ||
| export { | ||
@@ -274,2 +281,3 @@ load, | ||
| getSortedExtensions, | ||
| getExtensionsMetaByName, | ||
| getExtensions, | ||
@@ -276,0 +284,0 @@ nfMenuInfo as menuInfo, |
@@ -27,2 +27,77 @@ import assert from 'assert'; | ||
| }); | ||
| describe('cloneDeep()', () => { | ||
| it('primitives', () => { | ||
| // Arrange | ||
| const source = {a: 1, b: 'foo', c: true}; | ||
| // Act | ||
| const res = testing.cloneDeep(source); | ||
| // Assert | ||
| assert.strictEqual(source === res, false); | ||
| assert.deepStrictEqual(res, source); | ||
| }); | ||
| it('date', () => { | ||
| // Arrange | ||
| const source = {a: new Date()}; | ||
| // Act | ||
| const res = testing.cloneDeep(source); | ||
| // Assert | ||
| assert.strictEqual(source === res, false); | ||
| assert.deepStrictEqual(res, source); | ||
| assert.strictEqual(res.a instanceof Date, true); | ||
| }); | ||
| it('array', () => { | ||
| // Arrange | ||
| const source = {a: [['a',1],['b','t'],['c',true]]}; | ||
| // Act | ||
| const res = testing.cloneDeep(source); | ||
| // Assert | ||
| assert.strictEqual(source === res, false); | ||
| assert.deepStrictEqual(res, source); | ||
| assert.strictEqual(Array.isArray(res.a), true); | ||
| }); | ||
| it('map', () => { | ||
| // Arrange | ||
| const source = {a: new Map([['a',1],['b','t'],['c',true]])}; | ||
| // Act | ||
| const res = testing.cloneDeep(source); | ||
| // Assert | ||
| assert.strictEqual(source === res, false); | ||
| assert.deepStrictEqual(res, source); | ||
| assert.strictEqual(res.a instanceof Map, true); | ||
| }); | ||
| }); | ||
| describe('clearObj()', () => { | ||
| it('default', () => { | ||
| // Arrange | ||
| const source = {a_: 1, b__: 'foo', __c: true}; | ||
| // Act | ||
| testing.clearObj(source); | ||
| // Assert | ||
| assert.strictEqual(source.__c, undefined); | ||
| assert.strictEqual(source.b__, 'foo'); | ||
| assert.strictEqual(source.a_, 1); | ||
| }); | ||
| it('multiple', () => { | ||
| // Arrange | ||
| const source = {a_: 1, b__: 'foo', __c: true, _d: new Date()}; | ||
| // Act | ||
| testing.clearObj(source, ['__','_']); | ||
| // Assert | ||
| assert.strictEqual(source.__c, undefined); | ||
| assert.strictEqual(source._d, undefined); | ||
| assert.strictEqual(source.b__, 'foo'); | ||
| assert.strictEqual(source.a_, 1); | ||
| }); | ||
| it('recursive', () => { | ||
| // Arrange | ||
| const source = {a_: 1, b__: {__ba: 'foo', bb__: 'bar'}, __c: true}; | ||
| // Act | ||
| testing.clearObj(source); | ||
| // Assert | ||
| assert.strictEqual(source.__c, undefined); | ||
| assert.strictEqual(source.b__.__ba, undefined); | ||
| assert.strictEqual(source.b__.bb__, 'bar'); | ||
| assert.strictEqual(source.a_, 1); | ||
| }); | ||
| }); | ||
| }); |
+1
-1
| { | ||
| "name": "@nfjs/core", | ||
| "version": "1.0.0", | ||
| "version": "1.0.1", | ||
| "description": "Core", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
37721
10.86%949
11.91%1
Infinity%