index.js 917 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. 'use strict'
  2. var test = require('tape')
  3. var isNumberLike = require('..')
  4. var testCases = [
  5. // ['number', expectedResult]
  6. [0, true],
  7. ['0', true],
  8. [1.1, true],
  9. ['1.1', true],
  10. [-1.1, true],
  11. ['-1.1', true],
  12. ['1.1.1', false],
  13. [1.1e2, true],
  14. ['1.1e2', true],
  15. ['1e2e3', false],
  16. ['-', false],
  17. [null, false],
  18. ['22221.2.e.34442', false],
  19. [ '111a111', false ],
  20. [[], false],
  21. [[''], false],
  22. [Number.EPSILON, true],
  23. [Number.MAX_SAFE_INTEGER, true],
  24. [Number.MAX_VALUE, true],
  25. [Number.MIN_SAFE_INTEGER, true],
  26. [Number.MIN_VALUE, true],
  27. [Number.NaN, false],
  28. [Number.NEGATIVE_INFINITY, false],
  29. [Number.POSITIVE_INFINITY, false],
  30. [function (arg1, arg2) {}, false]
  31. ]
  32. test('isNumberLike', function (t) {
  33. t.plan(testCases.length)
  34. testCases.forEach(function (item) {
  35. t.equals(isNumberLike(item[0]), item[1], 'isNumberLike(' + JSON.stringify(item[0]) + ') === ' + item[1])
  36. })
  37. })