Skip to content

Commit c926123

Browse files
JamesKyburzbcoe
authored andcommitted
fix: allow support for falsy values like 0 in tagged literal (#45)
1 parent c66f8ba commit c926123

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Y18N.prototype._taggedLiteral = function (parts) {
4949
parts.forEach(function (part, i) {
5050
var arg = args[i + 1]
5151
str += part
52-
if (arg) {
52+
if (typeof arg !== 'undefined') {
5353
str += '%s'
5454
}
5555
})

test/y18n-test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ describe('y18n', function () {
3838

3939
__`Hi, ${'Ben'} ${'Coe'}!`.should.equal('Yarr! Shiver me timbers, why \'tis Ben Coe!')
4040
})
41+
it('can be used as a tag for template literals with falsy arguments', function () {
42+
var __ = y18n({
43+
locale: 'pirate',
44+
directory: path.join(__dirname, 'locales')
45+
}).__
46+
47+
__`Hi, ${'Ben'} ${''}!`.should.equal('Yarr! Shiver me timbers, why \'tis Ben !')
48+
})
4149
it('uses replacements from the default locale if none is configured', function () {
4250
var __ = y18n({
4351
directory: path.join(__dirname, 'locales')

0 commit comments

Comments
 (0)