HarmonyOSBaseLibs/src/main/ets/utils/ToolsHelperForTS.ts

38 行
1.0 KiB
TypeScript

import { HashMap } from '@kit.ArkTS';
2024-10-19 15:12:22 +08:00
/**
* ,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> {
2024-10-22 16:10:15 +08:00
const record: Record<string, string> = {} as Record<string, string>;
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
record[key] = obj[key];
}
}
return record;
}
static gets(headers?: Record<string, string>) {
return {
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
// "Accept": "application/json",
...headers
}
}
2024-10-19 15:12:22 +08:00
}