@hedhog/utils
Version:
<p align="center"> <img src="https://avatars.githubusercontent.com/u/177489127?s=200&v=4" alt="Hedhog Avatar" /> </p>
39 lines • 1.24 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatDataWithLocale = void 0;
const formatDataWithLocale = (data) => {
const newData = {
locale: {},
};
const locales = new Set();
const fieldKeys = new Set();
for (const key of Object.keys(data)) {
if (key !== "locale") {
const keys = key.split("-");
if (keys.length === 1) {
newData[keys[0]] = data[keys[0]];
}
else {
const locale = keys[0];
const field = keys[1];
if (!newData.locale[locale]) {
newData.locale[locale] = {};
}
newData.locale[locale][field] =
data[key] !== undefined ? data[key] : "";
locales.add(locale);
fieldKeys.add(field);
}
}
}
locales.forEach((locale) => {
fieldKeys.forEach((key) => {
if (!newData.locale[locale][key]) {
newData.locale[locale][key] = "";
}
});
});
return newData;
};
exports.formatDataWithLocale = formatDataWithLocale;
//# sourceMappingURL=formatDataWithLocale.js.map
;