Skip to content

Commit

Permalink
Merge pull request #70 from ovhemert/number-input-check
Browse files Browse the repository at this point in the history
add check for numbers
  • Loading branch information
mcollina committed Jun 18, 2019
2 parents a063187 + bd70016 commit 74a1894
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -65,7 +65,7 @@ module.exports = function prettyFactory (options) {
}

// Short-circuit for spec allowed primitive values.
if ([null, true, false].includes(log)) {
if ([null, true, false].includes(log) || Number.isFinite(log)) {
return `${log}\n`
}

Expand Down
20 changes: 20 additions & 0 deletions test/basic.test.js
Expand Up @@ -349,6 +349,26 @@ test('basic prettifier tests', (t) => {
t.end()
})

t.test('handles numbers', (t) => {
const pretty = prettyFactory()
let formatted = pretty(2)
t.is(formatted, '2\n')

formatted = pretty(-2)
t.is(formatted, '-2\n')

formatted = pretty(0.2)
t.is(formatted, '0.2\n')

formatted = pretty(Infinity)
t.is(formatted, 'Infinity\n')

formatted = pretty(NaN)
t.is(formatted, 'NaN\n')

t.end()
})

t.test('handles `undefined` input', (t) => {
t.plan(1)
const pretty = prettyFactory()
Expand Down

0 comments on commit 74a1894

Please sign in to comment.