2022-05-14 11:15:42 +02:00
|
|
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
2022-04-24 12:17:29 +02:00
|
|
|
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 {
|
2022-04-24 12:17:29 +02:00
|
|
|
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
|
2022-05-14 11:15:42 +02:00
|
|
|
const result: any = {};
|
2022-04-24 12:17:29 +02:00
|
|
|
for (const key in val)
|
|
|
|
result[key] = toRaw(val[key]);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return toRaw(val);
|
|
|
|
}
|