fix(core): update
This commit is contained in:
		@@ -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;
 | 
			
		||||
};
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
};
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -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]);
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -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';
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
};
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
}
 | 
			
		||||
};
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user