From c859cc38ecc4623a6d265bc1e4ac0257d7b43f94 Mon Sep 17 00:00:00 2001 From: James Kyburz Date: Wed, 28 Jun 2017 09:19:53 +0200 Subject: [PATCH 1/2] failing test with falsy arguments for template literals --- test/y18n-test.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/y18n-test.js b/test/y18n-test.js index 089746ff..2ef27377 100644 --- a/test/y18n-test.js +++ b/test/y18n-test.js @@ -38,6 +38,14 @@ describe('y18n', function () { __`Hi, ${'Ben'} ${'Coe'}!`.should.equal('Yarr! Shiver me timbers, why \'tis Ben Coe!') }) + it('can be used as a tag for template literals with falsy arguments', function () { + var __ = y18n({ + locale: 'pirate', + directory: path.join(__dirname, 'locales') + }).__ + + __`Hi, ${'Ben'} ${''}!`.should.equal('Yarr! Shiver me timbers, why \'tis Ben !') + }) it('uses replacements from the default locale if none is configured', function () { var __ = y18n({ directory: path.join(__dirname, 'locales') From 85b36194cdb14702620999e9304e4a7c9eddb300 Mon Sep 17 00:00:00 2001 From: James Kyburz Date: Wed, 17 May 2017 09:03:24 +0200 Subject: [PATCH 2/2] allow support for falsy values like 0 in tagged literal --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 922f8c49..d7206816 100644 --- a/index.js +++ b/index.js @@ -49,7 +49,7 @@ Y18N.prototype._taggedLiteral = function (parts) { parts.forEach(function (part, i) { var arg = args[i + 1] str += part - if (arg) { + if (typeof arg !== 'undefined') { str += '%s' } })