Skip to content

Commit

Permalink
Handle null case
Browse files Browse the repository at this point in the history
  • Loading branch information
LorisSigrist committed Oct 3, 2023
1 parent 48b9356 commit 5aee3a1
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/file-handling/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,22 @@ export function generateDictionaryFromTree(tree, locale) {
const keyVal = new Map();

/**
* @param {unknown} obj
* @param {unknown} thing
* @param {string[]} path
*/
function flatten(obj, path = []) {
if (typeof obj === "string" || typeof obj === "number") {
keyVal.set(path.join("."), String(obj));
function flatten(thing, path = []) {
if (thing === null) {
keyVal.set(path.join("."), "");
return;
}

if (typeof obj === "object" && obj !== null) {
for (const [key, value] of Object.entries(obj)) {
if (typeof thing === "string" || typeof thing === "number") {
keyVal.set(path.join("."), String(thing));
return;
}

if (typeof thing === "object") {
for (const [key, value] of Object.entries(thing)) {
flatten(value, [...path, key]);
}
return;
Expand Down

0 comments on commit 5aee3a1

Please sign in to comment.