fix(core): update

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

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;
export { fastDeepEqual };
export * from './smartobject.classes.smartobject';
export * from './tools';
export * from './smartobject.classes.smartobject.js';
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
*/
export class SmartObject {
// instance
public originalObject: object;
constructor(originalObjectArg: object) {
@ -22,4 +21,4 @@ export class SmartObject {
public toFlatObject() {
return tools.toFlatObject(this.originalObject);
}
}
}

View File

@ -1,6 +1,6 @@
// thirdparty scope
// 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';
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 {
presentInBothProperties: string[];
@ -27,41 +27,44 @@ export const compareObjects = (
const allProperties = Object.keys(referenceObjectArg).concat(Object.keys(comparisonObjectArg));
for (const currentProperty of allProperties) {
// lets find presentInBothProperties
if (referenceObjectArg[ currentProperty ] && comparisonObjectArg[ currentProperty ]) {
if (referenceObjectArg[currentProperty] && comparisonObjectArg[currentProperty]) {
returnComparisonObject.presentInBothProperties.push(currentProperty);
}
// lets find missingProperties
if (referenceObjectArg[ currentProperty ] && !comparisonObjectArg[ currentProperty ]) {
if (referenceObjectArg[currentProperty] && !comparisonObjectArg[currentProperty]) {
returnComparisonObject.missingProperties.push(currentProperty);
}
// lets find additionalProperties
if (!referenceObjectArg[ currentProperty ] && comparisonObjectArg[ currentProperty ]) {
if (!referenceObjectArg[currentProperty] && comparisonObjectArg[currentProperty]) {
returnComparisonObject.additionalProperties.push(currentProperty);
}
// lets find nulledProperties
if (comparisonObjectArg[ currentProperty ] === null) {
if (comparisonObjectArg[currentProperty] === null) {
returnComparisonObject.nulledProperties.push(currentProperty);
}
// lets find undefinedProperties
if (comparisonObjectArg[ currentProperty ] === undefined) {
if (comparisonObjectArg[currentProperty] === undefined) {
returnComparisonObject.undefinedProperties.push(currentProperty);
}
// lets find divergingProperties
if (
JSON.stringify(referenceObjectArg[ currentProperty ]) !==
JSON.stringify(comparisonObjectArg[ currentProperty ])
JSON.stringify(referenceObjectArg[currentProperty]) !==
JSON.stringify(comparisonObjectArg[currentProperty])
) {
returnComparisonObject.divergingProperties.push(currentProperty);
}
// lets find equalProperties
if (
plugins.fastDeepEqual(referenceObjectArg[ currentProperty ], comparisonObjectArg[ currentProperty ])
plugins.fastDeepEqual(
referenceObjectArg[currentProperty],
comparisonObjectArg[currentProperty]
)
) {
returnComparisonObject.equalProperties.push(currentProperty);
}
@ -71,9 +74,12 @@ export const compareObjects = (
const onlyUnique = (value: any, index: number, self: Array<any>) => {
return self.indexOf(value) === index;
};
const uniqueArray = returnComparisonObject[ currentProperty as keyof (typeof returnComparisonObject) ].filter(onlyUnique);
returnComparisonObject[ currentProperty as keyof (typeof returnComparisonObject) ] = uniqueArray;
const uniqueArray =
returnComparisonObject[currentProperty as keyof typeof returnComparisonObject].filter(
onlyUnique
);
returnComparisonObject[currentProperty as keyof typeof returnComparisonObject] = uniqueArray;
}
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.
@ -6,9 +6,9 @@ import * as plugins from '../smartobject.plugins';
* @param childParam
* @returns {boolean}
*/
export let exists = (parentObject: object, childParam: string): boolean => {
export let exists = (parentObject: object, childParam: string): boolean => {
if (parentObject.hasOwnProperty(childParam)) {
return true;
}
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
@ -6,12 +6,16 @@ import * as plugins from '../smartobject.plugins';
* @param wildcardArg the rege expression to match the property keys against
* @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 propertyNamesMatched = propertyNames.filter(propertyNameArg => {
let propertyNamesMatched = propertyNames.filter((propertyNameArg) => {
return plugins.minimatch(propertyNameArg, wildcardArg);
});
for (let propertyNameArg of propertyNamesMatched) {
await callbackArg(parentObjectArg[propertyNameArg]);
}
};
};

View File

@ -1,5 +1,5 @@
export * from './compareobjects';
export * from './exists';
export * from './foreachminimatch';
export * from './smart_add_get';
export * from './toFlatObject';
export * from './compareobjects.js';
export * from './exists.js';
export * from './foreachminimatch.js';
export * from './smart_add_get.js';
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
@ -7,7 +7,7 @@ import * as plugins from '../smartobject.plugins';
* @param logBool
* @returns {boolean}
*/
export const smartAdd = (
export const smartAdd = (
parentObject: object,
childParam: string,
valueArg: any = {},
@ -17,7 +17,7 @@ import * as plugins from '../smartobject.plugins';
): typeof parentObject & any => {
optionsArg = {
interpretDotsAsLevel: true,
...optionsArg
...optionsArg,
};
let paramLevels: string[];
@ -70,7 +70,7 @@ export const smartGet = <T>(
): T => {
optionsArg = {
interpretDotsAsLevel: true,
...optionsArg
...optionsArg,
};
let paramLevels: string[];
@ -89,4 +89,4 @@ export const smartGet = <T>(
}
}
return referencePointer as T;
};
};

View File

@ -1,21 +1,29 @@
export const toFlatObject = (objectArg: object) => {
const returnObject: {[key: string]: any} = {};
const extractLayer = (subObject: {[key: string]: any}, pathArg: string, loopProtection: 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' && !(subObject[ key ] instanceof Array)) {
if (typeof subObject[key] === 'object' && !(subObject[key] instanceof Array)) {
const newLoopbackArray = loopProtection.slice();
newLoopbackArray.push(subObject);
extractLayer(subObject[ key ], localPathArg ? localPathArg += `.${key}` : key, newLoopbackArray);
extractLayer(
subObject[key],
localPathArg ? (localPathArg += `.${key}`) : key,
newLoopbackArray
);
} else {
returnObject[localPathArg ? localPathArg += `.${key}` : key] = subObject[key];
returnObject[localPathArg ? (localPathArg += `.${key}`) : key] = subObject[key];
}
}
}
};
extractLayer(objectArg, '', []);
return returnObject;
}
};