Skip to content

Commit

Permalink
fix: allow support for falsy values like 0 in tagged literal (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesKyburz authored and bcoe committed Aug 10, 2017
1 parent c66f8ba commit c926123
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
})
Expand Down
8 changes: 8 additions & 0 deletions test/y18n-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit c926123

Please sign in to comment.