2024-10-19 15:12:22 +08:00
|
|
|
import { HashMap } from "@kit.ArkTS";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 常用方法,部分方法,在ets里面不能用
|
|
|
|
|
*/
|
|
|
|
|
export class ToolsHelperForTS {
|
|
|
|
|
// Map转为Record
|
|
|
|
|
static mapToRecord(myMap: HashMap<string, string>): Record<string, string> {
|
|
|
|
|
return Object.fromEntries(myMap.entries()) as Record<string, string>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Record转为Map
|
|
|
|
|
static recordToMap(myRecord: Record<string, string>): HashMap<string, string> {
|
|
|
|
|
let myMap: HashMap<string, string> = new HashMap();
|
|
|
|
|
for (const key in myRecord) {
|
|
|
|
|
myMap.set(key, myRecord[key]);
|
|
|
|
|
}
|
|
|
|
|
return myMap;
|
|
|
|
|
}
|
2024-10-22 16:10:15 +08:00
|
|
|
|
|
|
|
|
public static classToRecord(obj: Object): Record<string, string> {
|
|
|
|
|
const record: Record<string, string> = {} as Record<string, string>;
|
|
|
|
|
for (const key in obj) {
|
|
|
|
|
if (obj.hasOwnProperty(key)) {
|
|
|
|
|
record[key] = obj[key];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return record;
|
|
|
|
|
}
|
2024-10-19 15:12:22 +08:00
|
|
|
}
|