@appolo/utils
Advanced tools
Comparing version 8.0.12 to 8.0.13
@@ -32,13 +32,26 @@ "use strict"; | ||
} | ||
static createClassFromObject(klass, obj) { | ||
let instance = new klass(); | ||
static classToPlain(klass) { | ||
let dto = typeof klass["toJSON"] == "function" ? klass["toJSON"]() : JSON.parse(JSON.stringify(klass)); | ||
return dto; | ||
} | ||
static plainToClassInstance(instance, obj) { | ||
if (typeof instance["formJSON"] == "function") { | ||
instance["formJSON"](obj); | ||
return instance; | ||
} | ||
let keys = Object.keys(obj); | ||
for (let i = 0; i < keys.length; i++) { | ||
let key = keys[i]; | ||
instance[key] = obj[key]; | ||
if (typeof instance[key] != "function") { | ||
instance[key] = obj[key]; | ||
} | ||
} | ||
return instance; | ||
} | ||
static plainToClass(klass, obj) { | ||
let instance = new klass(obj); | ||
return Classes.plainToClassInstance(instance, obj); | ||
} | ||
} | ||
exports.Classes = Classes; | ||
//# sourceMappingURL=classes.js.map |
import {Arrays} from "./arrays"; | ||
import {Functions} from "../index"; | ||
import {Functions, Util} from "../index"; | ||
@@ -40,9 +40,24 @@ export class Classes { | ||
public static createClassFromObject<T>(klass: { new(): T }, obj: { [P in keyof T]: T[P] }): T { | ||
let instance = new klass(); | ||
public static classToPlain<T>(klass: T ): { [P in keyof T]: T[P] } { | ||
let dto = typeof klass["toJSON"] == "function" ? klass["toJSON"]() : JSON.parse(JSON.stringify(klass)) | ||
return dto | ||
} | ||
public static plainToClassInstance<T>(instance: T, obj: { [P in keyof T]: T[P] }): T { | ||
if (typeof instance["formJSON"] == "function") { | ||
instance["formJSON"](obj); | ||
return instance; | ||
} | ||
let keys = Object.keys(obj); | ||
for (let i = 0; i < keys.length; i++) { | ||
let key = keys[i] | ||
instance[key] = obj[key]; | ||
let key = keys[i]; | ||
if (typeof instance[key] != "function") { | ||
instance[key] = obj[key]; | ||
} | ||
} | ||
@@ -52,2 +67,9 @@ | ||
} | ||
public static plainToClass<T>(klass: { new(...args: any[]): T }, obj: { [P in keyof T]: T[P] }): T { | ||
let instance = new klass(obj); | ||
return Classes.plainToClassInstance(instance, obj) | ||
} | ||
} |
@@ -20,3 +20,3 @@ { | ||
"main": "./index.js", | ||
"version": "8.0.12", | ||
"version": "8.0.13", | ||
"license": "MIT", | ||
@@ -23,0 +23,0 @@ "repository": { |
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
182455
3273