@appolo/utils
Advanced tools
Comparing version 8.0.50 to 8.0.51
@@ -97,2 +97,20 @@ "use strict"; | ||
} | ||
static cloneJSON(json) { | ||
if (typeof json !== 'object' || json === null) { | ||
return json; | ||
} | ||
if (Array.isArray(json)) { | ||
return json.map(value => (typeof value !== 'object' || value === null) | ||
? value | ||
: Objects.cloneJSON(value)); | ||
} | ||
const output = {}; | ||
for (const key in json) { | ||
const value = json[key]; | ||
output[key] = (typeof value !== 'object' || value === null) | ||
? value | ||
: Objects.cloneJSON(value); | ||
} | ||
return output; | ||
} | ||
static clone(obj) { | ||
@@ -99,0 +117,0 @@ if (!obj) { |
@@ -34,3 +34,5 @@ import {Arrays} from "./arrays"; | ||
public static replaceFormatJson(obj: { [index: string]: any }, data: { [index: string]: any }): { [index: string]: any } { | ||
public static replaceFormatJson(obj: { [index: string]: any }, data: { [index: string]: any }): { | ||
[index: string]: any | ||
} { | ||
return JSON.parse(Strings.replaceFormatJson(JSON.stringify(obj), data)); | ||
@@ -56,3 +58,5 @@ } | ||
public static invertBy<T extends { [index: string]: any }, K extends { [index: string]: any }>(obj: T, criteria: (value: T[keyof T], key: keyof T, i?: number) => string | number): K { | ||
public static invertBy<T extends { [index: string]: any }, K extends { | ||
[index: string]: any | ||
}>(obj: T, criteria: (value: T[keyof T], key: keyof T, i?: number) => string | number): K { | ||
@@ -126,3 +130,25 @@ let output = Object.keys(obj || {}).reduce((output, key, index: number) => { | ||
public static cloneJSON<T>(json: T): T { | ||
if (typeof json !== 'object' || json === null) { | ||
return json; | ||
} | ||
if (Array.isArray(json)) { | ||
return json.map(value => | ||
(typeof value !== 'object' || value === null) | ||
? value | ||
: Objects.cloneJSON(value) | ||
) as any; | ||
} | ||
const output: any = {}; | ||
for (const key in json) { | ||
const value = json[key]; | ||
output[key] = (typeof value !== 'object' || value === null) | ||
? value | ||
: Objects.cloneJSON(value) | ||
} | ||
return output; | ||
} | ||
public static clone<T>(obj: T): T { | ||
@@ -129,0 +155,0 @@ |
@@ -20,3 +20,3 @@ { | ||
"main": "./index.js", | ||
"version": "8.0.50", | ||
"version": "8.0.51", | ||
"license": "MIT", | ||
@@ -33,12 +33,12 @@ "repository": { | ||
"devDependencies": { | ||
"@types/benchmark": "^2.1.2", | ||
"@types/chai": "^4.3.5", | ||
"@types/mocha": "^10.0.1", | ||
"@types/node": "^20.1.0", | ||
"@types/benchmark": "^2.1.3", | ||
"@types/chai": "^4.3.8", | ||
"@types/mocha": "^10.0.2", | ||
"@types/node": "^20.8.5", | ||
"benchmark": "^2.1.4", | ||
"chai": "^4.3.7", | ||
"chai": "^4.3.10", | ||
"mocha": "^10.2.0", | ||
"tslib": "^2.5.0", | ||
"tslib": "^2.6.2", | ||
"typescript": "^4.9.5" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
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
267232
4906