@slickgrid-universal/utils
Advanced tools
Comparing version 5.0.0-beta.2 to 5.0.0-beta.3
@@ -20,5 +20,5 @@ "use strict"; | ||
top = elementOffsetTop - pageScrollTop; | ||
bottom = windowHeight - (elementOffsetTop - pageScrollTop); | ||
left = elementOffsetLeft - pageScrollLeft; | ||
right = windowWidth - (elementOffsetLeft - pageScrollLeft); | ||
bottom = windowHeight - (elementOffsetTop - pageScrollTop + element.clientHeight); | ||
right = windowWidth - (elementOffsetLeft - pageScrollLeft + element.clientWidth); | ||
} | ||
@@ -25,0 +25,0 @@ return { top, bottom, left, right }; |
@@ -7,2 +7,3 @@ "use strict"; | ||
* e.g. it used `var` everywhere, it used `arguments` to get function arguments, ... | ||
* See `jQuery.extend()` for multiple usage demos: https://api.jquery.com/jquery.extend/ | ||
* | ||
@@ -9,0 +10,0 @@ * The previous lib can be found here at this Github link: |
"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.isDefinedNumber = exports.isDefined = exports.isEmptyObject = exports.getFunctionDetails = exports.emptyObject = exports.deepMerge = exports.deepCopy = exports.arrayRemoveItemByIndex = exports.addWhiteSpaces = exports.addToArrayWhenNotExists = void 0; | ||
const nodeExtend_1 = require("./nodeExtend"); | ||
/** | ||
@@ -46,42 +47,16 @@ * 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 | ||
/** | ||
* Create an immutable clone of an array or object | ||
* (c) 2019 Chris Ferdinandi, MIT License, https://gomakethings.com | ||
* @param {Array|Object} objectOrArray - the array or object to copy | ||
* @return {Array|Object} - the clone of the array or object | ||
* @use `extend()` when possible. | ||
* Create an immutable clone of an array or object (native type will be returned "as is"). | ||
* This function will deep copy whatever is provided as the first argument, but nonetheless it is now an alias to `extend()` (node-extend) function. | ||
* We'll keep the method to avoid breaking users of `deepCopy()`, however we suggest to directly use `extend(true, {}, obj)` whenever possible | ||
*/ | ||
function deepCopy(objectOrArray) { | ||
/** | ||
* Create an immutable copy of an object | ||
* @return {Object} | ||
*/ | ||
const cloneObj = () => { | ||
// Create new object | ||
const clone = {}; | ||
// Loop through each item in the original | ||
// Recursively copy it's value and add to the clone | ||
Object.keys(objectOrArray).forEach(key => { | ||
if (Object.prototype.hasOwnProperty.call(objectOrArray, key)) { | ||
clone[key] = deepCopy(objectOrArray[key]); | ||
} | ||
}); | ||
return clone; | ||
}; | ||
/** | ||
* Create an immutable copy of an array | ||
* @return {Array} | ||
*/ | ||
const cloneArr = () => objectOrArray.map((item) => deepCopy(item)); | ||
// -- init --// | ||
// Get object type | ||
const type = Object.prototype.toString.call(objectOrArray).slice(8, -1).toLowerCase(); | ||
// If an object | ||
if (type === 'object') { | ||
return cloneObj(); | ||
// we previously had a full implementation but we can now use node-extend to do the job | ||
// except that we need couple of small priors checks (native will be returned as is) | ||
if (!Array.isArray(objectOrArray) && !isObject(objectOrArray)) { | ||
return objectOrArray; | ||
} | ||
// If an array | ||
if (type === 'array') { | ||
return cloneArr(); | ||
} | ||
// Otherwise, return it as-is | ||
return objectOrArray; | ||
// Array or Object need 2nd arg to be either [] or {} for a deep copy to assign to when using node-extend (same as jQuery.extend()) | ||
const assignment = Array.isArray(objectOrArray) ? [] : {}; | ||
return (0, nodeExtend_1.extend)(true, assignment, objectOrArray); | ||
} | ||
@@ -88,0 +63,0 @@ exports.deepCopy = deepCopy; |
@@ -17,5 +17,5 @@ /** calculate available space for each side of the DOM element */ | ||
top = elementOffsetTop - pageScrollTop; | ||
bottom = windowHeight - (elementOffsetTop - pageScrollTop); | ||
left = elementOffsetLeft - pageScrollLeft; | ||
right = windowWidth - (elementOffsetLeft - pageScrollLeft); | ||
bottom = windowHeight - (elementOffsetTop - pageScrollTop + element.clientHeight); | ||
right = windowWidth - (elementOffsetLeft - pageScrollLeft + element.clientWidth); | ||
} | ||
@@ -22,0 +22,0 @@ return { top, bottom, left, right }; |
@@ -6,2 +6,3 @@ /** | ||
* e.g. it used `var` everywhere, it used `arguments` to get function arguments, ... | ||
* See `jQuery.extend()` for multiple usage demos: https://api.jquery.com/jquery.extend/ | ||
* | ||
@@ -8,0 +9,0 @@ * The previous lib can be found here at this Github link: |
@@ -0,1 +1,2 @@ | ||
import { extend } from './nodeExtend'; | ||
/** | ||
@@ -40,42 +41,16 @@ * 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 | ||
/** | ||
* Create an immutable clone of an array or object | ||
* (c) 2019 Chris Ferdinandi, MIT License, https://gomakethings.com | ||
* @param {Array|Object} objectOrArray - the array or object to copy | ||
* @return {Array|Object} - the clone of the array or object | ||
* @use `extend()` when possible. | ||
* Create an immutable clone of an array or object (native type will be returned "as is"). | ||
* This function will deep copy whatever is provided as the first argument, but nonetheless it is now an alias to `extend()` (node-extend) function. | ||
* We'll keep the method to avoid breaking users of `deepCopy()`, however we suggest to directly use `extend(true, {}, obj)` whenever possible | ||
*/ | ||
export function deepCopy(objectOrArray) { | ||
/** | ||
* Create an immutable copy of an object | ||
* @return {Object} | ||
*/ | ||
const cloneObj = () => { | ||
// Create new object | ||
const clone = {}; | ||
// Loop through each item in the original | ||
// Recursively copy it's value and add to the clone | ||
Object.keys(objectOrArray).forEach(key => { | ||
if (Object.prototype.hasOwnProperty.call(objectOrArray, key)) { | ||
clone[key] = deepCopy(objectOrArray[key]); | ||
} | ||
}); | ||
return clone; | ||
}; | ||
/** | ||
* Create an immutable copy of an array | ||
* @return {Array} | ||
*/ | ||
const cloneArr = () => objectOrArray.map((item) => deepCopy(item)); | ||
// -- init --// | ||
// Get object type | ||
const type = Object.prototype.toString.call(objectOrArray).slice(8, -1).toLowerCase(); | ||
// If an object | ||
if (type === 'object') { | ||
return cloneObj(); | ||
// we previously had a full implementation but we can now use node-extend to do the job | ||
// except that we need couple of small priors checks (native will be returned as is) | ||
if (!Array.isArray(objectOrArray) && !isObject(objectOrArray)) { | ||
return objectOrArray; | ||
} | ||
// If an array | ||
if (type === 'array') { | ||
return cloneArr(); | ||
} | ||
// Otherwise, return it as-is | ||
return objectOrArray; | ||
// Array or Object need 2nd arg to be either [] or {} for a deep copy to assign to when using node-extend (same as jQuery.extend()) | ||
const assignment = Array.isArray(objectOrArray) ? [] : {}; | ||
return extend(true, assignment, objectOrArray); | ||
} | ||
@@ -82,0 +57,0 @@ /** |
@@ -6,2 +6,3 @@ /** | ||
* e.g. it used `var` everywhere, it used `arguments` to get function arguments, ... | ||
* See `jQuery.extend()` for multiple usage demos: https://api.jquery.com/jquery.extend/ | ||
* | ||
@@ -8,0 +9,0 @@ * The previous lib can be found here at this Github link: |
@@ -22,6 +22,6 @@ import type { AnyFunction } from './models/types'; | ||
/** | ||
* Create an immutable clone of an array or object | ||
* (c) 2019 Chris Ferdinandi, MIT License, https://gomakethings.com | ||
* @param {Array|Object} objectOrArray - the array or object to copy | ||
* @return {Array|Object} - the clone of the array or object | ||
* @use `extend()` when possible. | ||
* Create an immutable clone of an array or object (native type will be returned "as is"). | ||
* This function will deep copy whatever is provided as the first argument, but nonetheless it is now an alias to `extend()` (node-extend) function. | ||
* We'll keep the method to avoid breaking users of `deepCopy()`, however we suggest to directly use `extend(true, {}, obj)` whenever possible | ||
*/ | ||
@@ -28,0 +28,0 @@ export declare function deepCopy(objectOrArray: any | any[]): any | any[]; |
{ | ||
"name": "@slickgrid-universal/utils", | ||
"version": "5.0.0-beta.2", | ||
"version": "5.0.0-beta.3", | ||
"description": "Common set of small utilities", | ||
@@ -40,3 +40,3 @@ "main": "./dist/cjs/index.js", | ||
], | ||
"gitHead": "821e9e33886faa626166edc9857912e788a933ad" | ||
"gitHead": "26cd69e67f2ed8cba9cc0d8c426ac5d201b20dea" | ||
} |
@@ -6,2 +6,3 @@ [](https://opensource.org/licenses/MIT) | ||
[](https://www.npmjs.com/package/@slickgrid-universal/utils) | ||
[](https://bundlephobia.com/result?p=@slickgrid-universal/utils) | ||
@@ -8,0 +9,0 @@ [](https://github.com/ghiscoding/slickgrid-universal/actions) |
@@ -21,5 +21,5 @@ import type { HtmlElementPosition, InferDOMType } from './models/index'; | ||
top = elementOffsetTop - pageScrollTop; | ||
bottom = windowHeight - (elementOffsetTop - pageScrollTop); | ||
left = elementOffsetLeft - pageScrollLeft; | ||
right = windowWidth - (elementOffsetLeft - pageScrollLeft); | ||
bottom = windowHeight - (elementOffsetTop - pageScrollTop + element.clientHeight); | ||
right = windowWidth - (elementOffsetLeft - pageScrollLeft + element.clientWidth); | ||
} | ||
@@ -26,0 +26,0 @@ |
@@ -0,0 +0,0 @@ export * from './domUtils'; |
export * from './interfaces'; | ||
export * from './types'; |
@@ -0,0 +0,0 @@ export interface HtmlElementPosition { |
@@ -0,0 +0,0 @@ |
@@ -6,2 +6,3 @@ /** | ||
* e.g. it used `var` everywhere, it used `arguments` to get function arguments, ... | ||
* See `jQuery.extend()` for multiple usage demos: https://api.jquery.com/jquery.extend/ | ||
* | ||
@@ -8,0 +9,0 @@ * The previous lib can be found here at this Github link: |
@@ -0,0 +0,0 @@ /** |
import type { AnyFunction } from './models/types'; | ||
import { extend } from './nodeExtend'; | ||
@@ -46,46 +47,16 @@ /** | ||
/** | ||
* Create an immutable clone of an array or object | ||
* (c) 2019 Chris Ferdinandi, MIT License, https://gomakethings.com | ||
* @param {Array|Object} objectOrArray - the array or object to copy | ||
* @return {Array|Object} - the clone of the array or object | ||
* @use `extend()` when possible. | ||
* Create an immutable clone of an array or object (native type will be returned "as is"). | ||
* This function will deep copy whatever is provided as the first argument, but nonetheless it is now an alias to `extend()` (node-extend) function. | ||
* We'll keep the method to avoid breaking users of `deepCopy()`, however we suggest to directly use `extend(true, {}, obj)` whenever possible | ||
*/ | ||
export function deepCopy(objectOrArray: any | any[]): any | any[] { | ||
/** | ||
* Create an immutable copy of an object | ||
* @return {Object} | ||
*/ | ||
const cloneObj = () => { | ||
// Create new object | ||
const clone = {}; | ||
// Loop through each item in the original | ||
// Recursively copy it's value and add to the clone | ||
Object.keys(objectOrArray).forEach(key => { | ||
if (Object.prototype.hasOwnProperty.call(objectOrArray, key)) { | ||
(clone as any)[key] = deepCopy(objectOrArray[key]); | ||
} | ||
}); | ||
return clone; | ||
}; | ||
/** | ||
* Create an immutable copy of an array | ||
* @return {Array} | ||
*/ | ||
const cloneArr = () => objectOrArray.map((item: any) => deepCopy(item)); | ||
// -- init --// | ||
// Get object type | ||
const type = Object.prototype.toString.call(objectOrArray).slice(8, -1).toLowerCase(); | ||
// If an object | ||
if (type === 'object') { | ||
return cloneObj(); | ||
// we previously had a full implementation but we can now use node-extend to do the job | ||
// except that we need couple of small priors checks (native will be returned as is) | ||
if (!Array.isArray(objectOrArray) && !isObject(objectOrArray)) { | ||
return objectOrArray; | ||
} | ||
// If an array | ||
if (type === 'array') { | ||
return cloneArr(); | ||
} | ||
// Otherwise, return it as-is | ||
return objectOrArray; | ||
// Array or Object need 2nd arg to be either [] or {} for a deep copy to assign to when using node-extend (same as jQuery.extend()) | ||
const assignment = Array.isArray(objectOrArray) ? [] : {}; | ||
return extend(true, assignment, objectOrArray); | ||
} | ||
@@ -92,0 +63,0 @@ |
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
Sorry, the diff of this file is not supported yet
20
220145
3071