diff --git a/src/index.ts b/src/index.ts index 3875354..ba8ada8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,12 +6,12 @@ export default { name: 'printKeys', type: 'postProcessor', process(_, key, options) { - // Filter out internal i18next options when printing keys. The resulting - // array is passed to JSON.stringify which instructs it which keys should - // be printed. - const optionKeys = Object.keys(options).filter( - (key) => !ignore.includes(key) - ) + // Filter out internal and undefined options when printing keys. The + // resulting array is passed to JSON.stringify which instructs it which + // keys should be printed. + const optionKeys = Object.keys(options) + .filter((key) => options[key] !== undefined) + .filter((key) => !ignore.includes(key)) return optionKeys.length ? key + ' ' + JSON.stringify(options, optionKeys) diff --git a/test/printKeys.spec.ts b/test/printKeys.spec.ts index dbf3244..cb8a023 100644 --- a/test/printKeys.spec.ts +++ b/test/printKeys.spec.ts @@ -34,3 +34,11 @@ it('should not print the internal options', () => { expect(i18next.t('key', { lngs: ['en', 'es'] })).toBe('key') expect(i18next.t('key', { interpolation: {} })).toBe('key') }) + +it('should not print undefined options', () => { + expect(i18next.t('basic', { count: undefined })).toBe('basic') + expect(i18next.t('basic', { context: undefined })).toBe('basic') + expect(i18next.t('basic', { count: 1, context: undefined })).toBe( + 'basic {"count":1}' + ) +})