MCPcopy Create free account
hub / github.com/callumalpass/tasknotes / flatten

Function flatten

scripts/i18n-manager.mjs:15–26  ·  view source on GitHub ↗

Flattens a nested translation object into a single-level key-value map.

(tree, prefix = '')

Source from the content-addressed store, hash-verified

13
14/** Flattens a nested translation object into a single-level key-value map. */
15function flatten(tree, prefix = '') {
16 const entries = {};
17 for (const [key, value] of Object.entries(tree)) {
18 const fullKey = prefix ? `${prefix}.${key}` : key;
19 if (typeof value === 'string') {
20 entries[fullKey] = value;
21 } else if (value && typeof value === 'object' && !Array.isArray(value)) {
22 Object.assign(entries, flatten(value, fullKey));
23 }
24 }
25 return entries;
26}
27
28/** Hashes a string using SHA1. */
29function hash(str) {

Callers 1

getLocaleMapFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected