fast-json-stringify 2.7.5 → 2.7.6

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.
@@ -38,6 +38,6 @@ jobs:
38
38
  needs: test
39
39
  runs-on: ubuntu-latest
40
40
  steps:
41
- - uses: fastify/github-action-merge-dependabot@v2.0.0
41
+ - uses: fastify/github-action-merge-dependabot@v2.1.0
42
42
  with:
43
43
  github-token: ${{ secrets.GITHUB_TOKEN }}
package/index.js CHANGED
@@ -254,9 +254,8 @@ function $asInteger (i) {
254
254
  } else if (Number.isInteger(i)) {
255
255
  return $asNumber(i)
256
256
  } else {
257
- // if the output is NaN the type is coerced to int 0
258
257
  /* eslint no-undef: "off" */
259
- return $asNumber(parseInteger(i) || 0)
258
+ return $asNumber(parseInteger(i))
260
259
  }
261
260
  }
262
261
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fast-json-stringify",
3
- "version": "2.7.5",
3
+ "version": "2.7.6",
4
4
  "description": "Stringify your JSON at max speed",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
package/test/date.test.js CHANGED
@@ -76,7 +76,7 @@ test('verify padding for rendered date in a string when format is date', (t) =>
76
76
  t.ok(validate(JSON.parse(output)), 'valid schema')
77
77
  })
78
78
 
79
- test('render a date in a string when format is time as HH:mm:ss', (t) => {
79
+ test('render a date in a string when format is time as kk:mm:ss', (t) => {
80
80
  t.plan(3)
81
81
 
82
82
  const schema = {
@@ -6,6 +6,7 @@ const semver = require('semver')
6
6
  const validator = require('is-my-json-valid')
7
7
  const proxyquire = require('proxyquire')
8
8
  const build = proxyquire('..', { long: null })
9
+ const ROUNDING_TYPES = ['ceil', 'floor', 'round']
9
10
 
10
11
  test('render an integer as JSON', (t) => {
11
12
  t.plan(2)
@@ -40,6 +41,10 @@ test('render a float as an integer', (t) => {
40
41
  const cases = [
41
42
  { input: Math.PI, output: '3' },
42
43
  { input: 5.0, output: '5' },
44
+ { input: null, output: '0' },
45
+ { input: 0, output: '0' },
46
+ { input: 0.0, output: '0' },
47
+ { input: 42, output: '42' },
43
48
  { input: 1.99999, output: '1' },
44
49
  { input: -45.05, output: '-45' },
45
50
  { input: 0.95, output: '1', rounding: 'ceil' },
@@ -138,7 +143,7 @@ if (semver.gt(process.versions.node, '10.3.0')) {
138
143
  t.end()
139
144
  }
140
145
 
141
- test('should round interger object parameter ', t => {
146
+ test('should round integer object parameter', t => {
142
147
  t.plan(2)
143
148
 
144
149
  const schema = { type: 'object', properties: { magic: { type: 'integer' } } }
@@ -149,3 +154,29 @@ test('should round interger object parameter ', t => {
149
154
  t.equal(output, '{"magic":5}')
150
155
  t.ok(validate(JSON.parse(output)), 'valid schema')
151
156
  })
157
+
158
+ test('should not stringify a property if it does not exist', t => {
159
+ t.plan(2)
160
+
161
+ const schema = { title: 'Example Schema', type: 'object', properties: { age: { type: 'integer' } } }
162
+ const validate = validator(schema)
163
+ const stringify = build(schema)
164
+ const output = stringify({})
165
+
166
+ t.equal(output, '{}')
167
+ t.ok(validate(JSON.parse(output)), 'valid schema')
168
+ })
169
+
170
+ ROUNDING_TYPES.forEach((rounding) => {
171
+ test(`should not stringify a property if it does not exist (rounding: ${rounding})`, t => {
172
+ t.plan(2)
173
+
174
+ const schema = { type: 'object', properties: { magic: { type: 'integer' } } }
175
+ const validate = validator(schema)
176
+ const stringify = build(schema, { rounding })
177
+ const output = stringify({})
178
+
179
+ t.equal(output, '{}')
180
+ t.ok(validate(JSON.parse(output)), 'valid schema')
181
+ })
182
+ })