@jsverse/transloco-keys-manager
Version:
Extract translatable keys from projects that uses Transloco
37 lines • 1.1 kB
JavaScript
import { getConfig } from '../config.js';
import { isObject } from './validators.utils.js';
export function stringify(val) {
const { sort } = getConfig();
let value = val;
if (sort) {
value = sortKeys(val);
}
return JSON.stringify(value, null, 2);
}
function sortKeys(val) {
return Object.keys(val)
.sort()
.reduce((acc, key) => {
acc[key] = isObject(val[key]) ? sortKeys(val[key]) : val[key];
return acc;
}, {});
}
export function mergeDeep(target, ...sources) {
if (!sources.length)
return target;
const source = sources.shift();
if (isObject(target) && isObject(source)) {
for (const key in source) {
if (isObject(source[key])) {
if (!target[key])
Object.assign(target, { [key]: {} });
mergeDeep(target[key], source[key]);
}
else {
Object.assign(target, { [key]: source[key] });
}
}
}
return mergeDeep(target, ...sources);
}
//# sourceMappingURL=object.utils.js.map