Skip to content

Commit

Permalink
feat(min_safe_integer): return default when number is less than Numbe…
Browse files Browse the repository at this point in the history
…r.MIN_SAFE_INTEGER
  • Loading branch information
jojoee committed Oct 18, 2021
1 parent d4c8af8 commit c582562
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ function bahttext (num) {
if (typeof num === 'boolean') return defaultResult
// must be number only
if (isNaN(Number(num))) return defaultResult
// not less than Number.MIN_SAFE_INTEGER
if (num < Number.MIN_SAFE_INTEGER) return defaultResult
// no more than Number.MAX_SAFE_INTEGER
if (num >= Number.MAX_SAFE_INTEGER) return defaultResult
if (num > Number.MAX_SAFE_INTEGER) return defaultResult

// set
const positiveNum = Math.abs(num)
Expand Down
13 changes: 10 additions & 3 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@ describe('misc', () => {
expect(bahttext('it-must-be-number-only')).toBe(zeroText)
})

test('less than Number.MIN_SAFE_INTEGER', () => {
const items = [1, 20, 9451, 5656549]
for (let i = 0; i < items.length; i++) {
expect(bahttext(Number.MIN_SAFE_INTEGER - items[i])).toBe(defaultResult)
}
})

test('more than Number.MAX_SAFE_INTEGER', () => {
const additions = [1, 20, 9451, 5656549]
for (let i = 0; i < additions.length; i++) {
expect(bahttext(Number.MAX_SAFE_INTEGER + additions[i])).toBe(defaultResult)
const items = [1, 20, 9451, 5656549]
for (let i = 0; i < items.length; i++) {
expect(bahttext(Number.MAX_SAFE_INTEGER + items[i])).toBe(defaultResult)
}
})
})
Expand Down

0 comments on commit c582562

Please sign in to comment.