style: clean up code with prettier and eslint
This commit is contained in:
1 parent
60278b9e71
commit
fb8e77bb68
378 files changed
+22407
-20689
No files matched your search
@@ -3,31 +3,31 @@
|
||||
// for ease of search/filter/render; the on-disk format is the nested object
|
||||
// produced by `unflattenObject`.
|
||||
|
||||
export function flattenObject(obj: Record<string, unknown>, prefix = ''): Record<string, string> {
|
||||
const result: Record<string, string> = {}
|
||||
export function flattenObject(obj: Record<string, unknown>, prefix = ""): Record<string, string> {
|
||||
const result: Record<string, string> = {};
|
||||
for (const [key, value] of Object.entries(obj)) {
|
||||
const fullKey = prefix ? `${prefix}.${key}` : key
|
||||
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
||||
Object.assign(result, flattenObject(value as Record<string, unknown>, fullKey))
|
||||
const fullKey = prefix ? `${prefix}.${key}` : key;
|
||||
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
||||
Object.assign(result, flattenObject(value as Record<string, unknown>, fullKey));
|
||||
} else {
|
||||
result[fullKey] = String(value ?? '')
|
||||
result[fullKey] = String(value ?? "");
|
||||
}
|
||||
}
|
||||
return result
|
||||
return result;
|
||||
}
|
||||
|
||||
export function unflattenObject(flat: Record<string, string>): Record<string, unknown> {
|
||||
const result: Record<string, unknown> = {}
|
||||
const result: Record<string, unknown> = {};
|
||||
for (const [key, value] of Object.entries(flat)) {
|
||||
const parts = key.split('.')
|
||||
let current: Record<string, unknown> = result
|
||||
const parts = key.split(".");
|
||||
let current: Record<string, unknown> = result;
|
||||
for (let i = 0; i < parts.length - 1; i++) {
|
||||
if (!current[parts[i]] || typeof current[parts[i]] !== 'object') {
|
||||
current[parts[i]] = {}
|
||||
if (!current[parts[i]] || typeof current[parts[i]] !== "object") {
|
||||
current[parts[i]] = {};
|
||||
}
|
||||
current = current[parts[i]] as Record<string, unknown>
|
||||
current = current[parts[i]] as Record<string, unknown>;
|
||||
}
|
||||
current[parts[parts.length - 1]] = value
|
||||
current[parts[parts.length - 1]] = value;
|
||||
}
|
||||
return result
|
||||
return result;
|
||||
}
|
||||
Reference in new issue
Block a user