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.
- package/.github/workflows/ci.yml +1 -1
- package/index.js +1 -2
- package/package.json +1 -1
- package/test/date.test.js +1 -1
- package/test/integer.test.js +32 -1
package/.github/workflows/ci.yml
CHANGED
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)
|
|
258
|
+
return $asNumber(parseInteger(i))
|
|
260
259
|
}
|
|
261
260
|
}
|
|
262
261
|
|
package/package.json
CHANGED
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
|
|
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 = {
|
package/test/integer.test.js
CHANGED
|
@@ -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
|
|
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
|
+
})
|