20 行
570 B
TypeScript
20 行
570 B
TypeScript
|
|
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;
|
||
|
|
}
|
||
|
|
}
|