@squared-functions/module
Advanced tools
Comparing version 1.1.4 to 1.1.5
107
index.js
@@ -1,2 +0,2 @@ | ||
/* @squared-functions/module 1.1.4 | ||
/* @squared-functions/module 1.1.5 | ||
https://github.com/anpham6/squared-functions */ | ||
@@ -107,8 +107,109 @@ | ||
} | ||
static isString(value) { | ||
return typeof value === 'string' && value.length > 0; | ||
} | ||
static isObject(value) { | ||
return typeof value === 'object' && value !== null; | ||
} | ||
static isString(value) { | ||
return typeof value === 'string' && value.length > 0; | ||
static isPlainObject(value) { | ||
return Module.isObject(value) && (value.constructor === Object || Object.getPrototypeOf(Object(value)) === null); | ||
} | ||
static cloneObject(data, options) { | ||
let target, deep, typedArray; | ||
if (options) { | ||
({ target, deep, typedArray } = options); | ||
} | ||
const nested = deep ? target ? { deep, typedArray } : options : undefined; | ||
const checkValue = (value) => { | ||
if (this.isObject(value)) { | ||
if (value instanceof Map) { | ||
return new Map(value); | ||
} | ||
if (value instanceof Set) { | ||
return new Set(value); | ||
} | ||
if (value instanceof Date) { | ||
return new Date(value); | ||
} | ||
if (value instanceof RegExp) { | ||
return new RegExp(value); | ||
} | ||
if (typedArray) { | ||
if (value instanceof Buffer) { | ||
return Buffer.from(value); | ||
} | ||
if (value instanceof Int8Array) { | ||
return Int8Array.from(value); | ||
} | ||
if (value instanceof Uint8Array) { | ||
return Uint8Array.from(value); | ||
} | ||
if (value instanceof Uint8ClampedArray) { | ||
return Uint8ClampedArray.from(value); | ||
} | ||
if (value instanceof Int16Array) { | ||
return Int16Array.from(value); | ||
} | ||
if (value instanceof Uint16Array) { | ||
return Uint16Array.from(value); | ||
} | ||
if (value instanceof Int32Array) { | ||
return Int32Array.from(value); | ||
} | ||
if (value instanceof Uint32Array) { | ||
return Uint32Array.from(value); | ||
} | ||
if (value instanceof Float32Array) { | ||
return Float32Array.from(value); | ||
} | ||
if (value instanceof Float64Array) { | ||
return Float64Array.from(value); | ||
} | ||
if (value instanceof BigInt64Array) { | ||
return BigInt64Array.from(value); | ||
} | ||
if (value instanceof BigUint64Array) { | ||
return BigUint64Array.from(value); | ||
} | ||
} | ||
} | ||
return value; | ||
}; | ||
if (Array.isArray(data)) { | ||
const length = data.length; | ||
if (!target || !Array.isArray(target)) { | ||
target = new Array(length); | ||
} | ||
else { | ||
target.length = 0; | ||
} | ||
for (let i = 0; i < length; ++i) { | ||
const value = data[i]; | ||
if (deep) { | ||
target[i] = Array.isArray(value) || this.isPlainObject(value) ? this.cloneObject(value, nested) : checkValue(value); | ||
} | ||
else { | ||
target[i] = Array.isArray(value) ? value.slice(0) : value; | ||
} | ||
} | ||
} | ||
else if (this.isPlainObject(data)) { | ||
if (!target || !this.isObject(target)) { | ||
target = {}; | ||
} | ||
for (const attr in data) { | ||
const value = data[attr]; | ||
if (deep) { | ||
target[attr] = Array.isArray(value) || this.isPlainObject(value) ? this.cloneObject(value, nested) : checkValue(value); | ||
} | ||
else { | ||
target[attr] = Array.isArray(value) ? value.slice(0) : value; | ||
} | ||
} | ||
} | ||
else { | ||
return deep ? checkValue(data) : data; | ||
} | ||
return target; | ||
} | ||
static generateUUID(format = '8-4-4-4-12', dictionary) { | ||
@@ -115,0 +216,0 @@ const match = format.match(/(\d+|[^\d]+)/g); |
{ | ||
"name": "@squared-functions/module", | ||
"version": "1.1.4", | ||
"version": "1.1.5", | ||
"description": "Module extension class for squared-functions", | ||
@@ -18,3 +18,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"@squared-functions/types": "^1.1.4", | ||
"@squared-functions/types": "1.1.5", | ||
"uuid": "^8.3.2", | ||
@@ -21,0 +21,0 @@ "chalk": "^4.1.1" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
26240
627
+ Added@squared-functions/types@1.1.5(transitive)
- Removed@squared-functions/types@1.3.4(transitive)