fast-json-stringify 5.6.0 → 5.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/serializer.js CHANGED
@@ -27,7 +27,7 @@ module.exports = class Serializer {
27
27
  if (i === Infinity || i === -Infinity) {
28
28
  throw new Error(`The value "${i}" cannot be converted to an integer.`)
29
29
  }
30
- if ((i | 0) === i) {
30
+ if (Number.isInteger(i)) {
31
31
  return '' + i
32
32
  }
33
33
  if (Number.isNaN(i)) {
@@ -50,17 +50,14 @@ module.exports = class Serializer {
50
50
  }
51
51
 
52
52
  asNumber (i) {
53
- if (typeof i !== 'number') {
54
- i = Number(i)
55
- }
56
- // NaN !== NaN
57
- if (i !== i) { // eslint-disable-line no-self-compare
53
+ const num = Number(i)
54
+ if (Number.isNaN(num)) {
58
55
  throw new Error(`The value "${i}" cannot be converted to a number.`)
56
+ } else if (!Number.isFinite(num)) {
57
+ return null
58
+ } else {
59
+ return '' + num
59
60
  }
60
- if (i === Infinity || i === -Infinity) {
61
- return 'null'
62
- }
63
- return '' + i
64
61
  }
65
62
 
66
63
  asBoolean (bool) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fast-json-stringify",
3
- "version": "5.6.0",
3
+ "version": "5.6.2",
4
4
  "description": "Stringify your JSON at max speed",
5
5
  "main": "index.js",
6
6
  "types": "types/index.d.ts",
@@ -0,0 +1,24 @@
1
+ 'use strict'
2
+
3
+ const t = require('tap')
4
+ const fjs = require('..')
5
+ const schema = {
6
+ type: 'object',
7
+ properties: {
8
+ fullName: { type: 'string' },
9
+ phone: { type: 'number' }
10
+ }
11
+ }
12
+
13
+ const input = {
14
+ fullName: 'Jone',
15
+ phone: 'phone'
16
+ }
17
+
18
+ const render = fjs(schema)
19
+
20
+ try {
21
+ render(input)
22
+ } catch (err) {
23
+ t.equal(err.message, 'The value "phone" cannot be converted to a number.')
24
+ }
@@ -45,6 +45,7 @@ test('render a float as an integer', (t) => {
45
45
  { input: 42, output: '42' },
46
46
  { input: 1.99999, output: '1' },
47
47
  { input: -45.05, output: '-45' },
48
+ { input: 3333333333333333, output: '3333333333333333' },
48
49
  { input: Math.PI, output: '3', rounding: 'trunc' },
49
50
  { input: 5.0, output: '5', rounding: 'trunc' },
50
51
  { input: null, output: '0', rounding: 'trunc' },