From 2d49674e58d1707420bf7fc0930d0669d10bef83 Mon Sep 17 00:00:00 2001 From: Veit Kunz Date: Tue, 4 Apr 2023 08:43:42 +0200 Subject: [PATCH] Stricter null checking to not filter out empty strings --- dist/modules/includes/lookup.js | 2 +- dist/modules/stores/dictionary.js | 2 +- src/includes/lookup.ts | 2 +- src/stores/dictionary.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/modules/includes/lookup.js b/dist/modules/includes/lookup.js index 2e2a736..ccc6571 100644 --- a/dist/modules/includes/lookup.js +++ b/dist/modules/includes/lookup.js @@ -20,7 +20,7 @@ export const lookup = (path, refLocale) => { for (let i = 0; i < locales.length; i++) { const locale = locales[i]; const message = getMessageFromDictionary(locale, path); - if (message) { + if (message !== null) { // Used the requested locale as the cache key // Ex: { en: { title: "Title" }} // lookup('title', 'en-GB') should cache with 'en-GB' instead of 'en' diff --git a/dist/modules/stores/dictionary.js b/dist/modules/stores/dictionary.js index 7122a19..5fe6635 100644 --- a/dist/modules/stores/dictionary.js +++ b/dist/modules/stores/dictionary.js @@ -22,7 +22,7 @@ export function getMessageFromDictionary(locale, id) { let tmpDict = localeDictionary; for (let i = 0; i < ids.length; i++) { if (typeof tmpDict[ids[i]] !== 'object') { - return tmpDict[ids[i]] || null; + return tmpDict[ids[i]] ?? null; } tmpDict = tmpDict[ids[i]]; } diff --git a/src/includes/lookup.ts b/src/includes/lookup.ts index 5e9096e..ae2133e 100644 --- a/src/includes/lookup.ts +++ b/src/includes/lookup.ts @@ -28,7 +28,7 @@ export const lookup = (path: string, refLocale: string) => { const locale = locales[i]; const message = getMessageFromDictionary(locale, path); - if (message) { + if (message !== null) { // Used the requested locale as the cache key // Ex: { en: { title: "Title" }} // lookup('title', 'en-GB') should cache with 'en-GB' instead of 'en' diff --git a/src/stores/dictionary.ts b/src/stores/dictionary.ts index 2f47783..f4145f8 100644 --- a/src/stores/dictionary.ts +++ b/src/stores/dictionary.ts @@ -30,7 +30,7 @@ export function getMessageFromDictionary(locale: string, id: string) { let tmpDict: any = localeDictionary for (let i = 0; i < ids.length; i++) { if (typeof tmpDict[ids[i]] !== 'object') { - return (tmpDict[ids[i]] as LocaleDictionaryValue) || null + return (tmpDict[ids[i]] as LocaleDictionaryValue) ?? null } tmpDict = tmpDict[ids[i]]; }