fast-json-stringify 2.5.4 → 2.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/ci.yml +30 -14
- package/README.md +8 -6
- package/example.js +1 -3
- package/index.js +2 -24
- package/package.json +1 -1
package/.github/workflows/ci.yml
CHANGED
|
@@ -1,27 +1,43 @@
|
|
|
1
|
-
name: CI
|
|
2
|
-
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
paths-ignore:
|
|
6
|
+
- 'docs/**'
|
|
7
|
+
- '*.md'
|
|
8
|
+
pull_request:
|
|
9
|
+
paths-ignore:
|
|
10
|
+
- 'docs/**'
|
|
11
|
+
- '*.md'
|
|
12
|
+
|
|
3
13
|
jobs:
|
|
4
14
|
test:
|
|
5
|
-
runs-on:
|
|
15
|
+
runs-on: ${{ matrix.os }}
|
|
6
16
|
strategy:
|
|
7
17
|
matrix:
|
|
8
18
|
node-version: [10.x, 12.x, 13.x, 14.x]
|
|
19
|
+
os: [macos-latest, ubuntu-latest, windows-latest]
|
|
20
|
+
|
|
9
21
|
steps:
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
- uses: actions/checkout@v2
|
|
23
|
+
|
|
24
|
+
- name: Use Node.js
|
|
25
|
+
uses: actions/setup-node@v2.1.5
|
|
26
|
+
with:
|
|
27
|
+
node-version: ${{ matrix.node-version }}
|
|
28
|
+
|
|
29
|
+
- name: Install Dependencies
|
|
30
|
+
run: |
|
|
31
|
+
npm install --ignore-scripts
|
|
32
|
+
|
|
33
|
+
- name: Run Tests
|
|
34
|
+
run: |
|
|
35
|
+
npm run test
|
|
19
36
|
|
|
20
37
|
automerge:
|
|
21
38
|
needs: test
|
|
22
39
|
runs-on: ubuntu-latest
|
|
23
40
|
steps:
|
|
24
41
|
- uses: fastify/github-action-merge-dependabot@v2.0.0
|
|
25
|
-
if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request' }}
|
|
26
42
|
with:
|
|
27
|
-
github-token: ${{secrets.
|
|
43
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
package/README.md
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
# fast-json-stringify
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-

|
|
4
|
+
[](https://www.npmjs.com/package/fast-json-stringify)
|
|
5
|
+
[](https://snyk.io/test/github/fastify/fast-json-stringify)
|
|
6
|
+
[](https://standardjs.com/)
|
|
5
7
|
[](https://www.npmjs.com/package/fast-json-stringify)
|
|
6
8
|
|
|
7
9
|
|
|
@@ -106,7 +108,7 @@ const stringify = fastJson(mySchema, {
|
|
|
106
108
|
<a name="fastJsonStringify"></a>
|
|
107
109
|
### fastJsonStringify(schema)
|
|
108
110
|
|
|
109
|
-
Build a `stringify()` function based on [jsonschema](
|
|
111
|
+
Build a `stringify()` function based on [jsonschema](https://json-schema.org/).
|
|
110
112
|
|
|
111
113
|
Supported types:
|
|
112
114
|
|
|
@@ -399,7 +401,7 @@ console.log(stringify({
|
|
|
399
401
|
})) // {"kind":"foobar","foo":"FOO","bar":42}
|
|
400
402
|
```
|
|
401
403
|
|
|
402
|
-
**NB
|
|
404
|
+
**NB** Do not declare the properties twice or you will print them twice!
|
|
403
405
|
|
|
404
406
|
<a name="ref"></a>
|
|
405
407
|
#### Reuse - $ref
|
|
@@ -514,7 +516,7 @@ const stringify = fastJson(schema, { schema: externalSchema })
|
|
|
514
516
|
|
|
515
517
|
<a name="long"></a>
|
|
516
518
|
#### Long integers
|
|
517
|
-
By default the library will handle
|
|
519
|
+
By default the library will automatically handle [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) from Node.js v10.3 and above.
|
|
518
520
|
If you can't use BigInts in your environment, long integers (64-bit) are also supported using the [long](https://github.com/dcodeIO/long.js) module.
|
|
519
521
|
Example:
|
|
520
522
|
```javascript
|
|
@@ -641,7 +643,7 @@ console.log(stringify({ firstName: 'Foo', surname: 'bar' })) // '{"firstName":"F
|
|
|
641
643
|
<a name="acknowledgements"></a>
|
|
642
644
|
## Acknowledgements
|
|
643
645
|
|
|
644
|
-
This project was kindly sponsored by [nearForm](
|
|
646
|
+
This project was kindly sponsored by [nearForm](https://nearform.com).
|
|
645
647
|
|
|
646
648
|
<a name="license"></a>
|
|
647
649
|
## License
|
package/example.js
CHANGED
package/index.js
CHANGED
|
@@ -146,13 +146,8 @@ function build (schema, options) {
|
|
|
146
146
|
return ${main}
|
|
147
147
|
`
|
|
148
148
|
|
|
149
|
-
const dependencies = []
|
|
150
|
-
const dependenciesName = []
|
|
151
|
-
if (dependsOnAjv(schema)) {
|
|
152
|
-
dependencies.push(new Ajv(options.ajv))
|
|
153
|
-
dependenciesName.push('ajv')
|
|
154
|
-
}
|
|
155
|
-
|
|
149
|
+
const dependencies = [new Ajv(options.ajv)]
|
|
150
|
+
const dependenciesName = ['ajv']
|
|
156
151
|
dependenciesName.push(code)
|
|
157
152
|
|
|
158
153
|
if (options.debugMode) {
|
|
@@ -223,23 +218,6 @@ function inferTypeByKeyword (schema) {
|
|
|
223
218
|
return schema.type
|
|
224
219
|
}
|
|
225
220
|
|
|
226
|
-
function dependsOnAjv (schema) {
|
|
227
|
-
const str = JSON.stringify(schema)
|
|
228
|
-
switch (true) {
|
|
229
|
-
case /"if":{.*"then":{/.test(str):
|
|
230
|
-
case /"(anyOf|oneOf)":\[/.test(str):
|
|
231
|
-
case /"const"/.test(str):
|
|
232
|
-
case /"\$ref"/.test(str):
|
|
233
|
-
{
|
|
234
|
-
return true
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
default: {
|
|
238
|
-
return false
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
221
|
const stringSerializerMap = {
|
|
244
222
|
'date-time': '$asDatetime',
|
|
245
223
|
date: '$asDate',
|