diff --git a/index.d.ts b/index.d.ts index 28b78ae..762aae0 100644 --- a/index.d.ts +++ b/index.d.ts @@ -26,7 +26,7 @@ pupa('I like {{0}} and {{1}}', ['
🦄
', '🐮']); */ declare function pupa( template: string, - data: unknown[] | {[key: string]: unknown} + data: unknown[] | {[key: string]: any} ): string; export = pupa; diff --git a/index.js b/index.js index 4555579..c8dc040 100644 --- a/index.js +++ b/index.js @@ -20,7 +20,7 @@ module.exports = (template, data) => { result = result ? result[property] : ''; } - return htmlEscape(result.toString()) || ''; + return htmlEscape(String(result)); }); } @@ -33,6 +33,6 @@ module.exports = (template, data) => { result = result ? result[property] : ''; } - return result || ''; + return String(result); }); }; diff --git a/test.js b/test.js index 3babccd..a8a1a13 100644 --- a/test.js +++ b/test.js @@ -5,6 +5,7 @@ test('main', t => { // Normal placeholder t.is(pupa('{foo}', {foo: '!'}), '!'); t.is(pupa('{foo}', {foo: 10}), '10'); + t.is(pupa('{foo}', {foo: 0}), '0'); t.is(pupa('{foo}{foo}', {foo: '!'}), '!!'); t.is(pupa('{foo}{bar}{foo}', {foo: '!', bar: '#'}), '!#!'); t.is(pupa('yo {foo} lol {bar} sup', {foo: '🦄', bar: '🌈'}), 'yo 🦄 lol 🌈 sup'); @@ -23,6 +24,7 @@ test('main', t => { // Encoding HTML Entities to avoid code injection t.is(pupa('{{foo}}', {foo: '!'}), '!'); t.is(pupa('{{foo}}', {foo: 10}), '10'); + t.is(pupa('{{foo}}', {foo: 0}), '0'); t.is(pupa('{{foo}}{{foo}}', {foo: '!'}), '!!'); t.is(pupa('{foo}{{bar}}{foo}', {foo: '!', bar: '#'}), '!#!'); t.is(pupa('yo {{foo}} lol {{bar}} sup', {foo: '🦄', bar: '🌈'}), 'yo 🦄 lol 🌈 sup');