fast-json-stringify 5.4.1 → 5.6.0
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/benchmark.yml +1 -1
- package/.taprc +5 -0
- package/README.md +6 -2
- package/benchmark/bench.js +21 -0
- package/index.js +132 -123
- package/lib/serializer.js +43 -27
- package/lib/standalone.js +4 -5
- package/package.json +17 -27
- package/test/allof.test.js +52 -3
- package/test/any.test.js +77 -0
- package/test/anyof.test.js +6 -6
- package/test/array.test.js +133 -14
- package/test/date.test.js +117 -24
- package/test/if-then-else.test.js +4 -3
- package/test/integer.test.js +8 -0
- package/test/multi-type-serializer.test.js +19 -0
- package/test/patternProperties.test.js +18 -0
- package/test/ref.test.js +73 -0
- package/test/string.test.js +50 -0
- package/test/typesArray.test.js +47 -1
- package/{index.d.ts → types/index.d.ts} +27 -1
- package/{test/types/test.ts → types/index.test-d.ts} +85 -2
- package/test/types/schema-inference.test-d.ts +0 -48
- package/test/types/tsconfig.json +0 -13
package/.taprc
CHANGED
package/README.md
CHANGED
|
@@ -548,7 +548,7 @@ By default the library will handle automatically [BigInt](https://developer.mozi
|
|
|
548
548
|
<a name="integer"></a>
|
|
549
549
|
#### Integers
|
|
550
550
|
The `type: integer` property will be truncated if a floating point is provided.
|
|
551
|
-
You can customize this behaviour with the `rounding` option that will accept [`round`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round), [`ceil`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil)
|
|
551
|
+
You can customize this behaviour with the `rounding` option that will accept [`round`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round), [`ceil`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil), [`floor`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor) or [`trunc`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/trunc). Default is `trunc`:
|
|
552
552
|
|
|
553
553
|
```js
|
|
554
554
|
const stringify = fastJson(schema, { rounding: 'ceil' })
|
|
@@ -650,12 +650,16 @@ AJV Serialize large array x 58.76 ops/sec ±4.59% (60 runs sampled)
|
|
|
650
650
|
Treat the schema definition as application code, it
|
|
651
651
|
is not safe to use user-provided schemas.
|
|
652
652
|
|
|
653
|
-
|
|
653
|
+
To achieve low cost and high performance redaction `fast-json-stringify`
|
|
654
654
|
creates and compiles a function (using the `Function` constructor) on initialization.
|
|
655
655
|
While the `schema` is currently validated for any developer errors,
|
|
656
656
|
there is no guarantee that supplying user-generated schema could not
|
|
657
657
|
expose your application to remote attacks.
|
|
658
658
|
|
|
659
|
+
Users are responsible for sending trusted data. `fast-json-stringify` guarantees that you will get
|
|
660
|
+
a valid output only if your input matches the schema or can be coerced to the schema. If your input
|
|
661
|
+
doesn't match the schema, you will get undefined behavior.
|
|
662
|
+
|
|
659
663
|
<a name="debug"></a>
|
|
660
664
|
### Debug Mode
|
|
661
665
|
|
package/benchmark/bench.js
CHANGED
|
@@ -214,6 +214,27 @@ const benchmarks = [
|
|
|
214
214
|
b5: true
|
|
215
215
|
}
|
|
216
216
|
},
|
|
217
|
+
{
|
|
218
|
+
name: 'simple object',
|
|
219
|
+
schema: {
|
|
220
|
+
title: 'Example Schema',
|
|
221
|
+
type: 'object',
|
|
222
|
+
properties: {
|
|
223
|
+
firstName: {
|
|
224
|
+
type: 'string'
|
|
225
|
+
},
|
|
226
|
+
lastName: {
|
|
227
|
+
type: ['string', 'null']
|
|
228
|
+
},
|
|
229
|
+
age: {
|
|
230
|
+
description: 'Age in years',
|
|
231
|
+
type: 'integer',
|
|
232
|
+
minimum: 0
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
input: { firstName: 'Max', lastName: 'Power', age: 22 }
|
|
237
|
+
},
|
|
217
238
|
{
|
|
218
239
|
name: 'object with const string property',
|
|
219
240
|
schema: {
|