fix(core): update

This commit is contained in:
Philipp Kunz 2023-07-12 19:40:41 +02:00
parent 61fcd5b992
commit a58c2881b9
21 changed files with 2181 additions and 28432 deletions

View File

@ -0,0 +1,66 @@
name: Default (not tags)
on:
push:
tags-ignore:
- '**'
env:
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
jobs:
security:
runs-on: ubuntu-latest
continue-on-error: true
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Install pnpm and npmci
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
- name: Run npm prepare
run: npmci npm prepare
- name: Audit production dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --prod
continue-on-error: true
- name: Audit development dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --dev
continue-on-error: true
test:
if: ${{ always() }}
needs: security
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Test stable
run: |
npmci node install stable
npmci npm install
npmci npm test
- name: Test build
run: |
npmci node install stable
npmci npm install
npmci npm build

View File

@ -0,0 +1,124 @@
name: Default (tags)
on:
push:
tags:
- '*'
env:
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
jobs:
security:
runs-on: ubuntu-latest
continue-on-error: true
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Audit production dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --prod
continue-on-error: true
- name: Audit development dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --dev
continue-on-error: true
test:
if: ${{ always() }}
needs: security
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Test stable
run: |
npmci node install stable
npmci npm install
npmci npm test
- name: Test build
run: |
npmci node install stable
npmci npm install
npmci npm build
release:
needs: test
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Release
run: |
npmci node install stable
npmci npm publish
metadata:
needs: test
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
continue-on-error: true
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @shipzone/npmci
npmci npm prepare
- name: Code quality
run: |
npmci command npm install -g typescript
npmci npm install
- name: Trigger
run: npmci trigger
- name: Build docs and upload artifacts
run: |
npmci node install stable
npmci npm install
pnpm install -g @gitzone/tsdoc
npmci command tsdoc
continue-on-error: true

24
.vscode/launch.json vendored
View File

@ -2,28 +2,10 @@
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"name": "current file", "command": "npm test",
"type": "node", "name": "Run npm test",
"request": "launch", "request": "launch",
"args": [ "type": "node-terminal"
"${relativeFile}"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": "test.ts",
"type": "node",
"request": "launch",
"args": [
"test/test.ts"
],
"runtimeArgs": ["-r", "@gitzone/tsrun"],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart"
} }
] ]
} }

View File

@ -5,7 +5,7 @@
"githost": "gitlab.com", "githost": "gitlab.com",
"gitscope": "push.rocks", "gitscope": "push.rocks",
"gitrepo": "smartobject", "gitrepo": "smartobject",
"shortDescription": "work with objects", "description": "work with objects",
"npmPackagename": "@push.rocks/smartobject", "npmPackagename": "@push.rocks/smartobject",
"license": "MIT", "license": "MIT",
"projectDomain": "push.rocks" "projectDomain": "push.rocks"

27343
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -10,19 +10,19 @@
"scripts": { "scripts": {
"test": "(tstest test/)", "test": "(tstest test/)",
"build": "(tsbuild --web)", "build": "(tsbuild --web)",
"format": "(gitzone format)" "format": "(gitzone format)",
"buildDocs": "tsdoc"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.29", "@gitzone/tsbuild": "^2.1.66",
"@gitzone/tstest": "^1.0.64", "@gitzone/tsrun": "^1.2.42",
"@pushrocks/tapbundle": "^4.0.8", "@gitzone/tstest": "^1.0.74",
"@types/node": "^17.0.21", "@push.rocks/tapbundle": "^5.0.8",
"tslint": "^6.1.3", "@types/node": "^17.0.45"
"tslint-config-prettier": "^1.15.0"
}, },
"dependencies": { "dependencies": {
"fast-deep-equal": "^3.1.3", "fast-deep-equal": "^3.1.3",
"minimatch": "^5.0.1" "minimatch": "^5.1.6"
}, },
"browserslist": [ "browserslist": [
"last 1 chrome versions" "last 1 chrome versions"
@ -38,5 +38,6 @@
"cli.js", "cli.js",
"npmextra.json", "npmextra.json",
"readme.md" "readme.md"
] ],
"type": "module"
} }

2851
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -1,27 +1,26 @@
# @pushrocks/smartobject # @push.rocks/smartobject
work with objects work with objects
## Availabililty and Links ## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartobject) * [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/smartobject)
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartobject) * [gitlab.com (source)](https://gitlab.com/push.rocks/smartobject)
* [github.com (source mirror)](https://github.com/pushrocks/smartobject) * [github.com (source mirror)](https://github.com/push.rocks/smartobject)
* [docs (typedoc)](https://pushrocks.gitlab.io/smartobject/) * [docs (typedoc)](https://push.rocks.gitlab.io/smartobject/)
## Status for master ## Status for master
Status Category | Status Badge Status Category | Status Badge
-- | -- -- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartobject/badges/master/pipeline.svg)](https://lossless.cloud) GitLab Pipelines | [![pipeline status](https://gitlab.com/push.rocks/smartobject/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartobject/badges/master/coverage.svg)](https://lossless.cloud) GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/push.rocks/smartobject/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartobject)](https://lossless.cloud) npm | [![npm downloads per month](https://badgen.net/npm/dy/@push.rocks/smartobject)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartobject)](https://lossless.cloud) Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/push.rocks/smartobject)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud) TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud) Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartobject)](https://lossless.cloud) PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@push.rocks/smartobject)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartobject)](https://lossless.cloud) PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@push.rocks/smartobject)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartobject)](https://lossless.cloud) BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@push.rocks/smartobject)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
## Usage ## Usage
@ -33,7 +32,6 @@ We are always happy for code contributions. If you are not the code contributing
For further information read the linked docs at the top of this readme. For further information read the linked docs at the top of this readme.
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh) ## Legal
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy) | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)

View File

@ -1,5 +1,5 @@
import { expect, tap } from '@pushrocks/tapbundle'; import { expect, tap } from '@push.rocks/tapbundle';
import * as smartobject from '../ts/index'; import * as smartobject from '../ts/index.js';
tap.test('first test', async () => { tap.test('first test', async () => {
const result = smartobject.compareObjects( const result = smartobject.compareObjects(
@ -28,7 +28,7 @@ tap.test('childObject should now be in parentObject', async () => {
tap.test('should be able to deepAdd an childParam', async () => { tap.test('should be able to deepAdd an childParam', async () => {
const parentObject = { const parentObject = {
hello: 'there' hello: 'there',
}; };
const parentObject2 = smartobject.smartAdd(parentObject, 'wow.za', 'yes'); const parentObject2 = smartobject.smartAdd(parentObject, 'wow.za', 'yes');
console.log(parentObject2); console.log(parentObject2);
@ -39,9 +39,9 @@ tap.test('should be able to deep get an item', async () => {
const testObject = { const testObject = {
hey: { hey: {
there: { there: {
so: 'cool' so: 'cool',
} },
} },
}; };
const item = smartobject.smartGet(testObject, 'hey.there.so'); const item = smartobject.smartGet(testObject, 'hey.there.so');
@ -52,11 +52,11 @@ tap.test('should call properties for minimatched properties', async () => {
let testObject = { let testObject = {
matchedOne: 'Hey!', matchedOne: 'Hey!',
matchedTwo: 'this works!', matchedTwo: 'this works!',
notmatched: 'NOT!' notmatched: 'NOT!',
}; };
const matchedStrings: string[] = []; const matchedStrings: string[] = [];
await smartobject.forEachMinimatch(testObject, 'matched*', matchedProperty => { await smartobject.forEachMinimatch(testObject, 'matched*', (matchedProperty) => {
matchedStrings.push(matchedProperty); matchedStrings.push(matchedProperty);
console.log(matchedProperty); console.log(matchedProperty);
}); });

View File

@ -1,5 +1,5 @@
import { expect, expectAsync, tap} from '@pushrocks/tapbundle'; import { expect, expectAsync, tap } from '@push.rocks/tapbundle';
import * as smartobject from '../ts'; import * as smartobject from '../ts/index.js';
let testSmartobject: smartobject.SmartObject; let testSmartobject: smartobject.SmartObject;
@ -10,15 +10,15 @@ tap.test('should create a smartobject', async () => {
yeah: 'so deep', yeah: 'so deep',
evendeeper: { evendeeper: {
sodeep: 2, sodeep: 2,
deepArray: ['one array', 'two array'] deepArray: ['one array', 'two array'],
} },
} },
} };
testSmartobject = new smartobject.SmartObject(originalObject); testSmartobject = new smartobject.SmartObject(originalObject);
testSmartobject.addValueAtFlatPathString('deep.nice', 'yeah that has been added'); testSmartobject.addValueAtFlatPathString('deep.nice', 'yeah that has been added');
console.log(testSmartobject.originalObject); console.log(testSmartobject.originalObject);
console.log(testSmartobject.toFlatObject()) console.log(testSmartobject.toFlatObject());
expect(testSmartobject.getValueAtFlatPathString('deep.yeah')).toEqual('so deep'); expect(testSmartobject.getValueAtFlatPathString('deep.yeah')).toEqual('so deep');
}); });
tap.start(); tap.start();

8
ts/00_commitinfo_data.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
*/
export const commitinfo = {
name: '@push.rocks/smartobject',
version: '1.0.11',
description: 'work with objects'
}

View File

@ -1,6 +1,6 @@
import * as plugins from './smartobject.plugins'; import * as plugins from './smartobject.plugins.js';
const fastDeepEqual = plugins.fastDeepEqual; const fastDeepEqual = plugins.fastDeepEqual;
export { fastDeepEqual }; export { fastDeepEqual };
export * from './smartobject.classes.smartobject'; export * from './smartobject.classes.smartobject.js';
export * from './tools'; export * from './tools/index.js';

View File

@ -1,10 +1,9 @@
import * as tools from './tools'; import * as tools from './tools/index.js';
/** /**
* a smartobject that simplifies accessing objects * a smartobject that simplifies accessing objects
*/ */
export class SmartObject { export class SmartObject {
// instance // instance
public originalObject: object; public originalObject: object;
constructor(originalObjectArg: object) { constructor(originalObjectArg: object) {
@ -22,4 +21,4 @@ export class SmartObject {
public toFlatObject() { public toFlatObject() {
return tools.toFlatObject(this.originalObject); return tools.toFlatObject(this.originalObject);
} }
} }

View File

@ -1,6 +1,6 @@
// thirdparty scope // thirdparty scope
// tslint:disable-next-line: no-submodule-imports // tslint:disable-next-line: no-submodule-imports
import fastDeepEqual from 'fast-deep-equal/es6'; import fastDeepEqual from 'fast-deep-equal/es6/index.js';
import minimatch from 'minimatch'; import minimatch from 'minimatch';
export { fastDeepEqual, minimatch }; export { fastDeepEqual, minimatch };

View File

@ -1,4 +1,4 @@
import * as plugins from '../smartobject.plugins'; import * as plugins from '../smartobject.plugins.js';
export interface IObjectCompareResult { export interface IObjectCompareResult {
presentInBothProperties: string[]; presentInBothProperties: string[];
@ -27,41 +27,44 @@ export const compareObjects = (
const allProperties = Object.keys(referenceObjectArg).concat(Object.keys(comparisonObjectArg)); const allProperties = Object.keys(referenceObjectArg).concat(Object.keys(comparisonObjectArg));
for (const currentProperty of allProperties) { for (const currentProperty of allProperties) {
// lets find presentInBothProperties // lets find presentInBothProperties
if (referenceObjectArg[ currentProperty ] && comparisonObjectArg[ currentProperty ]) { if (referenceObjectArg[currentProperty] && comparisonObjectArg[currentProperty]) {
returnComparisonObject.presentInBothProperties.push(currentProperty); returnComparisonObject.presentInBothProperties.push(currentProperty);
} }
// lets find missingProperties // lets find missingProperties
if (referenceObjectArg[ currentProperty ] && !comparisonObjectArg[ currentProperty ]) { if (referenceObjectArg[currentProperty] && !comparisonObjectArg[currentProperty]) {
returnComparisonObject.missingProperties.push(currentProperty); returnComparisonObject.missingProperties.push(currentProperty);
} }
// lets find additionalProperties // lets find additionalProperties
if (!referenceObjectArg[ currentProperty ] && comparisonObjectArg[ currentProperty ]) { if (!referenceObjectArg[currentProperty] && comparisonObjectArg[currentProperty]) {
returnComparisonObject.additionalProperties.push(currentProperty); returnComparisonObject.additionalProperties.push(currentProperty);
} }
// lets find nulledProperties // lets find nulledProperties
if (comparisonObjectArg[ currentProperty ] === null) { if (comparisonObjectArg[currentProperty] === null) {
returnComparisonObject.nulledProperties.push(currentProperty); returnComparisonObject.nulledProperties.push(currentProperty);
} }
// lets find undefinedProperties // lets find undefinedProperties
if (comparisonObjectArg[ currentProperty ] === undefined) { if (comparisonObjectArg[currentProperty] === undefined) {
returnComparisonObject.undefinedProperties.push(currentProperty); returnComparisonObject.undefinedProperties.push(currentProperty);
} }
// lets find divergingProperties // lets find divergingProperties
if ( if (
JSON.stringify(referenceObjectArg[ currentProperty ]) !== JSON.stringify(referenceObjectArg[currentProperty]) !==
JSON.stringify(comparisonObjectArg[ currentProperty ]) JSON.stringify(comparisonObjectArg[currentProperty])
) { ) {
returnComparisonObject.divergingProperties.push(currentProperty); returnComparisonObject.divergingProperties.push(currentProperty);
} }
// lets find equalProperties // lets find equalProperties
if ( if (
plugins.fastDeepEqual(referenceObjectArg[ currentProperty ], comparisonObjectArg[ currentProperty ]) plugins.fastDeepEqual(
referenceObjectArg[currentProperty],
comparisonObjectArg[currentProperty]
)
) { ) {
returnComparisonObject.equalProperties.push(currentProperty); returnComparisonObject.equalProperties.push(currentProperty);
} }
@ -71,9 +74,12 @@ export const compareObjects = (
const onlyUnique = (value: any, index: number, self: Array<any>) => { const onlyUnique = (value: any, index: number, self: Array<any>) => {
return self.indexOf(value) === index; return self.indexOf(value) === index;
}; };
const uniqueArray = returnComparisonObject[ currentProperty as keyof (typeof returnComparisonObject) ].filter(onlyUnique); const uniqueArray =
returnComparisonObject[ currentProperty as keyof (typeof returnComparisonObject) ] = uniqueArray; returnComparisonObject[currentProperty as keyof typeof returnComparisonObject].filter(
onlyUnique
);
returnComparisonObject[currentProperty as keyof typeof returnComparisonObject] = uniqueArray;
} }
return returnComparisonObject; return returnComparisonObject;
}; };

View File

@ -1,4 +1,4 @@
import * as plugins from '../smartobject.plugins'; import * as plugins from '../smartobject.plugins.js';
/** /**
* checks if an object has a parameter with a given key name, returns true if yes. * checks if an object has a parameter with a given key name, returns true if yes.
@ -6,9 +6,9 @@ import * as plugins from '../smartobject.plugins';
* @param childParam * @param childParam
* @returns {boolean} * @returns {boolean}
*/ */
export let exists = (parentObject: object, childParam: string): boolean => { export let exists = (parentObject: object, childParam: string): boolean => {
if (parentObject.hasOwnProperty(childParam)) { if (parentObject.hasOwnProperty(childParam)) {
return true; return true;
} }
return false; return false;
}; };

View File

@ -1,4 +1,4 @@
import * as plugins from '../smartobject.plugins'; import * as plugins from '../smartobject.plugins.js';
/** /**
* runs a function for all properties of an object whose key matches a regex expression * runs a function for all properties of an object whose key matches a regex expression
@ -6,12 +6,16 @@ import * as plugins from '../smartobject.plugins';
* @param wildcardArg the rege expression to match the property keys against * @param wildcardArg the rege expression to match the property keys against
* @param callbackArg the function to run with those properties * @param callbackArg the function to run with those properties
*/ */
export let forEachMinimatch = async (parentObjectArg: any, wildcardArg: string, callbackArg: (matchedArg: string) => void) => { export let forEachMinimatch = async (
parentObjectArg: any,
wildcardArg: string,
callbackArg: (matchedArg: string) => void
) => {
let propertyNames = Object.getOwnPropertyNames(parentObjectArg); let propertyNames = Object.getOwnPropertyNames(parentObjectArg);
let propertyNamesMatched = propertyNames.filter(propertyNameArg => { let propertyNamesMatched = propertyNames.filter((propertyNameArg) => {
return plugins.minimatch(propertyNameArg, wildcardArg); return plugins.minimatch(propertyNameArg, wildcardArg);
}); });
for (let propertyNameArg of propertyNamesMatched) { for (let propertyNameArg of propertyNamesMatched) {
await callbackArg(parentObjectArg[propertyNameArg]); await callbackArg(parentObjectArg[propertyNameArg]);
} }
}; };

View File

@ -1,5 +1,5 @@
export * from './compareobjects'; export * from './compareobjects.js';
export * from './exists'; export * from './exists.js';
export * from './foreachminimatch'; export * from './foreachminimatch.js';
export * from './smart_add_get'; export * from './smart_add_get.js';
export * from './toFlatObject'; export * from './toFlatObject.js';

View File

@ -1,4 +1,4 @@
import * as plugins from '../smartobject.plugins'; import * as plugins from '../smartobject.plugins.js';
/** /**
* adds an object to the parent object if it doesn't exists * adds an object to the parent object if it doesn't exists
@ -7,7 +7,7 @@ import * as plugins from '../smartobject.plugins';
* @param logBool * @param logBool
* @returns {boolean} * @returns {boolean}
*/ */
export const smartAdd = ( export const smartAdd = (
parentObject: object, parentObject: object,
childParam: string, childParam: string,
valueArg: any = {}, valueArg: any = {},
@ -17,7 +17,7 @@ import * as plugins from '../smartobject.plugins';
): typeof parentObject & any => { ): typeof parentObject & any => {
optionsArg = { optionsArg = {
interpretDotsAsLevel: true, interpretDotsAsLevel: true,
...optionsArg ...optionsArg,
}; };
let paramLevels: string[]; let paramLevels: string[];
@ -70,7 +70,7 @@ export const smartGet = <T>(
): T => { ): T => {
optionsArg = { optionsArg = {
interpretDotsAsLevel: true, interpretDotsAsLevel: true,
...optionsArg ...optionsArg,
}; };
let paramLevels: string[]; let paramLevels: string[];
@ -89,4 +89,4 @@ export const smartGet = <T>(
} }
} }
return referencePointer as T; return referencePointer as T;
}; };

View File

@ -1,21 +1,29 @@
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) { if (loopProtection.indexOf(subObject) > -1) {
return; 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' && !(subObject[ key ] instanceof Array)) { 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
);
} else { } else {
returnObject[localPathArg ? localPathArg += `.${key}` : key] = subObject[key]; returnObject[localPathArg ? (localPathArg += `.${key}`) : key] = subObject[key];
} }
} }
} };
extractLayer(objectArg, '', []); extractLayer(objectArg, '', []);
return returnObject; return returnObject;
} };

11
tsconfig.json Normal file
View File

@ -0,0 +1,11 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "nodenext",
"esModuleInterop": true,
"verbatimModuleSyntax": true,
}
}