antares/src/renderer/libs/unproxify.ts

23 lines
606 B
TypeScript
Raw Normal View History

/* eslint-disable @typescript-eslint/no-explicit-any */
import { toRaw } from 'vue';
/**
* @param {*} val
* @param {Boolean} json converts the value in JSON object (default true)
*/
2023-08-17 13:48:55 +02:00
export function unproxify<T = any> (val: T, json = true): T {
if (json)// JSON conversion
return JSON.parse(JSON.stringify(val));
else if (Array.isArray(val))// If array
return toRaw(val);
else if (typeof val === 'object') { // If object
const result: any = {};
for (const key in val)
result[key] = toRaw(val[key]);
return result;
}
else
return toRaw(val);
}