@slickgrid-universal/utils
Advanced tools
Comparing version 4.1.0 to 4.2.0
@@ -66,4 +66,4 @@ "use strict"; | ||
function destroyAllElementProps(obj) { | ||
if (obj) { | ||
for (const key of Object.keys(obj)) { | ||
if (typeof obj === 'object') { | ||
Object.keys(obj).forEach(key => { | ||
if (Array.isArray(obj[key])) { | ||
@@ -75,3 +75,3 @@ destroyAllElementProps(obj[key]); | ||
} | ||
} | ||
}); | ||
} | ||
@@ -78,0 +78,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.uniqueObjectArray = exports.uniqueArray = exports.toSnakeCase = exports.toSentenceCase = exports.toKebabCase = exports.toCamelCase = exports.titleCase = exports.setDeepValue = exports.removeAccentFromText = exports.parseBoolean = exports.isObjectEmpty = exports.isNumber = exports.hasData = exports.isPrimitiveOrHTML = exports.isPrimitiveValue = exports.isObject = exports.isDefined = exports.isEmptyObject = exports.emptyObject = exports.objectAssignAndExtend = exports.deepMerge = exports.deepCopy = exports.arrayRemoveItemByIndex = exports.addWhiteSpaces = exports.addToArrayWhenNotExists = void 0; | ||
exports.uniqueObjectArray = exports.uniqueArray = exports.toSnakeCase = exports.toSentenceCase = exports.toKebabCase = exports.toCamelCase = exports.titleCase = exports.setDeepValue = exports.removeAccentFromText = exports.parseBoolean = exports.isObjectEmpty = exports.isNumber = exports.hasData = exports.isPrimitiveOrHTML = exports.isPrimitiveValue = exports.isObject = exports.isDefined = exports.isEmptyObject = exports.emptyObject = exports.deepMerge = exports.deepCopy = exports.arrayRemoveItemByIndex = exports.addWhiteSpaces = exports.addToArrayWhenNotExists = void 0; | ||
/** | ||
@@ -61,7 +61,7 @@ * Add an item to an array only when the item does not exists, when the item is an object we will be using their "id" to compare | ||
// Recursively copy it's value and add to the clone | ||
for (const key in objectOrArray) { | ||
Object.keys(objectOrArray).forEach(key => { | ||
if (Object.prototype.hasOwnProperty.call(objectOrArray, key)) { | ||
clone[key] = deepCopy(objectOrArray[key]); | ||
} | ||
} | ||
}); | ||
return clone; | ||
@@ -104,3 +104,3 @@ }; | ||
if (isObject(target) && isObject(source)) { | ||
for (const prop in source) { | ||
Object.keys(source).forEach(prop => { | ||
if (source.hasOwnProperty(prop)) { | ||
@@ -133,3 +133,3 @@ if (prop in target) { | ||
} | ||
} | ||
}); | ||
} | ||
@@ -140,33 +140,2 @@ return deepMerge(target, ...sources); | ||
/** | ||
* This method is similar to `Object.assign` with the exception that it will also extend the object properties when filled. | ||
* There's also a distinction with extend vs merge, we are only extending when the property is not filled (if it is filled then it remains untouched and will not be merged) | ||
* It also applies the change directly on the target object which mutates the original object. | ||
* For example using these 2 objects: obj1 = { a: 1, b: { c: 2, d: 3 }} and obj2 = { b: { d: 2, e: 3}}: | ||
* - Object.assign(obj1, obj2) => { a: 1, b: { e: 4 }} | ||
* - objectAssignAndExtend(obj1, obj2) => { a: 1, b: { c: 2, d: 3, e: 4 } | ||
* @param {Object} target - the target object — what to apply the sources properties and mutate into | ||
* @param {Object} sources - the source object(s) — objects containing the properties you want to apply. | ||
* @returns {Object} The target object. | ||
*/ | ||
function objectAssignAndExtend(target, ...sources) { | ||
if (!sources.length || sources[0] === undefined) { | ||
return target; | ||
} | ||
const source = sources.shift(); | ||
// when target is not an object but source is an object, then we'll assign as object | ||
target = (!isObject(target) && isObject(source)) ? {} : target; | ||
if (isObject(target) && isObject(source)) { | ||
for (const key of Object.keys(source)) { | ||
if (typeof source[key] === 'object' && source[key] !== null) { | ||
objectAssignAndExtend(target[key], source[key]); | ||
} | ||
if ((target[key] === null || target[key] === undefined) && source[key] !== null && source[key] !== undefined) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return objectAssignAndExtend(target, ...sources); | ||
} | ||
exports.objectAssignAndExtend = objectAssignAndExtend; | ||
/** | ||
* Empty an object properties by looping through them all and deleting them | ||
@@ -176,6 +145,8 @@ * @param obj - input object | ||
function emptyObject(obj) { | ||
for (const key in obj) { | ||
if (obj.hasOwnProperty(key)) { | ||
delete obj[key]; | ||
} | ||
if (isObject(obj)) { | ||
Object.keys(obj).forEach(key => { | ||
if (obj.hasOwnProperty(key)) { | ||
delete obj[key]; | ||
} | ||
}); | ||
} | ||
@@ -182,0 +153,0 @@ obj = null; |
@@ -61,4 +61,4 @@ /** calculate available space for each side of the DOM element */ | ||
export function destroyAllElementProps(obj) { | ||
if (obj) { | ||
for (const key of Object.keys(obj)) { | ||
if (typeof obj === 'object') { | ||
Object.keys(obj).forEach(key => { | ||
if (Array.isArray(obj[key])) { | ||
@@ -70,3 +70,3 @@ destroyAllElementProps(obj[key]); | ||
} | ||
} | ||
}); | ||
} | ||
@@ -73,0 +73,0 @@ } |
@@ -55,7 +55,7 @@ /** | ||
// Recursively copy it's value and add to the clone | ||
for (const key in objectOrArray) { | ||
Object.keys(objectOrArray).forEach(key => { | ||
if (Object.prototype.hasOwnProperty.call(objectOrArray, key)) { | ||
clone[key] = deepCopy(objectOrArray[key]); | ||
} | ||
} | ||
}); | ||
return clone; | ||
@@ -97,3 +97,3 @@ }; | ||
if (isObject(target) && isObject(source)) { | ||
for (const prop in source) { | ||
Object.keys(source).forEach(prop => { | ||
if (source.hasOwnProperty(prop)) { | ||
@@ -126,3 +126,3 @@ if (prop in target) { | ||
} | ||
} | ||
}); | ||
} | ||
@@ -132,32 +132,2 @@ return deepMerge(target, ...sources); | ||
/** | ||
* This method is similar to `Object.assign` with the exception that it will also extend the object properties when filled. | ||
* There's also a distinction with extend vs merge, we are only extending when the property is not filled (if it is filled then it remains untouched and will not be merged) | ||
* It also applies the change directly on the target object which mutates the original object. | ||
* For example using these 2 objects: obj1 = { a: 1, b: { c: 2, d: 3 }} and obj2 = { b: { d: 2, e: 3}}: | ||
* - Object.assign(obj1, obj2) => { a: 1, b: { e: 4 }} | ||
* - objectAssignAndExtend(obj1, obj2) => { a: 1, b: { c: 2, d: 3, e: 4 } | ||
* @param {Object} target - the target object — what to apply the sources properties and mutate into | ||
* @param {Object} sources - the source object(s) — objects containing the properties you want to apply. | ||
* @returns {Object} The target object. | ||
*/ | ||
export function objectAssignAndExtend(target, ...sources) { | ||
if (!sources.length || sources[0] === undefined) { | ||
return target; | ||
} | ||
const source = sources.shift(); | ||
// when target is not an object but source is an object, then we'll assign as object | ||
target = (!isObject(target) && isObject(source)) ? {} : target; | ||
if (isObject(target) && isObject(source)) { | ||
for (const key of Object.keys(source)) { | ||
if (typeof source[key] === 'object' && source[key] !== null) { | ||
objectAssignAndExtend(target[key], source[key]); | ||
} | ||
if ((target[key] === null || target[key] === undefined) && source[key] !== null && source[key] !== undefined) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return objectAssignAndExtend(target, ...sources); | ||
} | ||
/** | ||
* Empty an object properties by looping through them all and deleting them | ||
@@ -167,6 +137,8 @@ * @param obj - input object | ||
export function emptyObject(obj) { | ||
for (const key in obj) { | ||
if (obj.hasOwnProperty(key)) { | ||
delete obj[key]; | ||
} | ||
if (isObject(obj)) { | ||
Object.keys(obj).forEach(key => { | ||
if (obj.hasOwnProperty(key)) { | ||
delete obj[key]; | ||
} | ||
}); | ||
} | ||
@@ -173,0 +145,0 @@ obj = null; |
@@ -36,14 +36,2 @@ /** | ||
/** | ||
* This method is similar to `Object.assign` with the exception that it will also extend the object properties when filled. | ||
* There's also a distinction with extend vs merge, we are only extending when the property is not filled (if it is filled then it remains untouched and will not be merged) | ||
* It also applies the change directly on the target object which mutates the original object. | ||
* For example using these 2 objects: obj1 = { a: 1, b: { c: 2, d: 3 }} and obj2 = { b: { d: 2, e: 3}}: | ||
* - Object.assign(obj1, obj2) => { a: 1, b: { e: 4 }} | ||
* - objectAssignAndExtend(obj1, obj2) => { a: 1, b: { c: 2, d: 3, e: 4 } | ||
* @param {Object} target - the target object — what to apply the sources properties and mutate into | ||
* @param {Object} sources - the source object(s) — objects containing the properties you want to apply. | ||
* @returns {Object} The target object. | ||
*/ | ||
export declare function objectAssignAndExtend(target: any, ...sources: any): any; | ||
/** | ||
* Empty an object properties by looping through them all and deleting them | ||
@@ -50,0 +38,0 @@ * @param obj - input object |
{ | ||
"name": "@slickgrid-universal/utils", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"description": "Common set of small utilities", | ||
@@ -47,3 +47,3 @@ "main": "./dist/cjs/index.js", | ||
], | ||
"gitHead": "1cfc2658f5d70e66c096e5ea77d1827dd44e0292" | ||
"gitHead": "d97d211a6c2d7d2f3ad65a3d5f19b27584e5ae8c" | ||
} |
@@ -72,4 +72,4 @@ import type { HtmlElementPosition, InferDOMType } from './types/index'; | ||
export function destroyAllElementProps(obj: any) { | ||
if (obj) { | ||
for (const key of Object.keys(obj)) { | ||
if (typeof obj === 'object') { | ||
Object.keys(obj).forEach(key => { | ||
if (Array.isArray(obj[key])) { | ||
@@ -81,3 +81,3 @@ destroyAllElementProps(obj[key]); | ||
} | ||
} | ||
}); | ||
} | ||
@@ -84,0 +84,0 @@ } |
@@ -61,3 +61,3 @@ /* eslint-disable guard-for-in */ | ||
// Return undefined instead of __proto__ if '__proto__' is not an own property | ||
const getProperty = function getProperty(obj: any, name: any) { | ||
const getProperty = function getProperty(obj: any, name: string) { | ||
if (name === '__proto__') { | ||
@@ -64,0 +64,0 @@ if (!hasOwn.call(obj, name)) { |
@@ -60,7 +60,7 @@ /** | ||
// Recursively copy it's value and add to the clone | ||
for (const key in objectOrArray) { | ||
Object.keys(objectOrArray).forEach(key => { | ||
if (Object.prototype.hasOwnProperty.call(objectOrArray, key)) { | ||
(clone as any)[key] = deepCopy(objectOrArray[key]); | ||
} | ||
} | ||
}); | ||
return clone; | ||
@@ -108,3 +108,3 @@ }; | ||
if (isObject(target) && isObject(source)) { | ||
for (const prop in source) { | ||
Object.keys(source).forEach(prop => { | ||
if (source.hasOwnProperty(prop)) { | ||
@@ -133,3 +133,3 @@ if (prop in target) { | ||
} | ||
} | ||
}); | ||
} | ||
@@ -140,35 +140,2 @@ return deepMerge(target, ...sources); | ||
/** | ||
* This method is similar to `Object.assign` with the exception that it will also extend the object properties when filled. | ||
* There's also a distinction with extend vs merge, we are only extending when the property is not filled (if it is filled then it remains untouched and will not be merged) | ||
* It also applies the change directly on the target object which mutates the original object. | ||
* For example using these 2 objects: obj1 = { a: 1, b: { c: 2, d: 3 }} and obj2 = { b: { d: 2, e: 3}}: | ||
* - Object.assign(obj1, obj2) => { a: 1, b: { e: 4 }} | ||
* - objectAssignAndExtend(obj1, obj2) => { a: 1, b: { c: 2, d: 3, e: 4 } | ||
* @param {Object} target - the target object — what to apply the sources properties and mutate into | ||
* @param {Object} sources - the source object(s) — objects containing the properties you want to apply. | ||
* @returns {Object} The target object. | ||
*/ | ||
export function objectAssignAndExtend(target: any, ...sources: any): any { | ||
if (!sources.length || sources[0] === undefined) { | ||
return target; | ||
} | ||
const source = sources.shift(); | ||
// when target is not an object but source is an object, then we'll assign as object | ||
target = (!isObject(target) && isObject(source)) ? {} : target; | ||
if (isObject(target) && isObject(source)) { | ||
for (const key of Object.keys(source)) { | ||
if (typeof source[key] === 'object' && source[key] !== null) { | ||
objectAssignAndExtend(target[key], source[key]); | ||
} | ||
if ((target[key] === null || target[key] === undefined) && source[key] !== null && source[key] !== undefined) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
return objectAssignAndExtend(target, ...sources); | ||
} | ||
/** | ||
* Empty an object properties by looping through them all and deleting them | ||
@@ -178,6 +145,8 @@ * @param obj - input object | ||
export function emptyObject(obj: any) { | ||
for (const key in obj) { | ||
if (obj.hasOwnProperty(key)) { | ||
delete obj[key]; | ||
} | ||
if (isObject(obj)) { | ||
Object.keys(obj).forEach(key => { | ||
if (obj.hasOwnProperty(key)) { | ||
delete obj[key]; | ||
} | ||
}); | ||
} | ||
@@ -184,0 +153,0 @@ obj = null; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
204158
2920