2016-03-13 05:19:24 +08:00
|
|
|
export class Utils {
|
|
|
|
|
|
|
|
static clone<T>(object:T):T {
|
|
|
|
return JSON.parse(JSON.stringify(object));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-09 23:04:56 +08:00
|
|
|
static concatUrls(...args:Array<string>) {
|
2016-03-26 23:25:48 +08:00
|
|
|
let url = "";
|
2016-05-09 23:04:56 +08:00
|
|
|
for (let i = 0; i < args.length; i++) {
|
|
|
|
if (args[i] === "" || typeof args[i] === "undefined") continue;
|
|
|
|
|
|
|
|
let part = args[i].replace("\\", "/");
|
|
|
|
if (part === "/" || part === "./") continue;
|
2016-03-26 23:25:48 +08:00
|
|
|
|
|
|
|
url += part + "/";
|
|
|
|
}
|
|
|
|
|
|
|
|
return url.substring(0, url.length - 1);
|
|
|
|
}
|
|
|
|
|
2016-05-09 23:04:56 +08:00
|
|
|
public static updateKeys(targetObject, sourceObject) {
|
2016-05-10 03:43:52 +08:00
|
|
|
Object.keys(sourceObject).forEach((key)=> {
|
2016-05-09 23:04:56 +08:00
|
|
|
if (typeof targetObject[key] === "undefined") {
|
2016-04-22 19:23:44 +08:00
|
|
|
return;
|
|
|
|
}
|
2016-05-09 23:04:56 +08:00
|
|
|
if (typeof targetObject[key] === "object") {
|
|
|
|
Utils.updateKeys(targetObject[key], sourceObject[key]);
|
|
|
|
} else {
|
2016-04-22 19:23:44 +08:00
|
|
|
targetObject[key] = sourceObject[key];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-05-09 23:04:56 +08:00
|
|
|
public static setKeys(targetObject, sourceObject) {
|
2016-04-22 19:23:44 +08:00
|
|
|
Object.keys(sourceObject).forEach((key)=> {
|
2016-05-09 23:04:56 +08:00
|
|
|
if (typeof targetObject[key] === "object") {
|
|
|
|
Utils.updateKeys(targetObject[key], sourceObject[key]);
|
|
|
|
} else {
|
2016-04-22 19:23:44 +08:00
|
|
|
targetObject[key] = sourceObject[key];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-05-09 23:04:56 +08:00
|
|
|
|
|
|
|
public static enumToArray(EnumType):Array<{key:number;value:string;}> {
|
2016-05-02 03:30:43 +08:00
|
|
|
let arr:Array<{key:number;value:string;}> = [];
|
2016-05-09 23:04:56 +08:00
|
|
|
for (let enumMember in EnumType) {
|
|
|
|
if (!EnumType.hasOwnProperty(enumMember)) {
|
2016-05-02 03:30:43 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
let key = parseInt(enumMember, 10);
|
|
|
|
if (key >= 0) {
|
|
|
|
arr.push({key: key, value: EnumType[enumMember]});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return arr;
|
|
|
|
}
|
2016-04-22 19:23:44 +08:00
|
|
|
|
2016-03-13 05:19:24 +08:00
|
|
|
}
|