mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
15 lines
492 B
JavaScript
15 lines
492 B
JavaScript
//#region src/object/flatten.ts
|
|
function flatten(object, options = {}) {
|
|
const { prefix = "" } = options;
|
|
const result = {};
|
|
for (const [key, value] of Object.entries(object)) {
|
|
const fullKey = prefix ? `${prefix}.${key}` : key;
|
|
if (value !== null && typeof value === "object" && !Array.isArray(value)) Object.assign(result, flatten(value, { prefix: fullKey }));
|
|
else result[fullKey] = value;
|
|
}
|
|
return result;
|
|
}
|
|
//#endregion
|
|
export { flatten };
|
|
|
|
//# sourceMappingURL=flatten.js.map
|