fast-json-stringify 2.7.6 → 2.7.7

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.1.0
41
+ - uses: fastify/github-action-merge-dependabot@v2.1.1
42
42
  with:
43
43
  github-token: ${{ secrets.GITHUB_TOKEN }}
package/README.md CHANGED
@@ -342,7 +342,7 @@ const stringify = fastJson({
342
342
  savedId: { type: 'string' }
343
343
  },
344
344
  // without "required" validation any object will match
345
- required: ['saveId']
345
+ required: ['savedId']
346
346
  },
347
347
  {
348
348
  type: 'object',
package/index.js CHANGED
@@ -72,21 +72,7 @@ function build (schema, options) {
72
72
  `
73
73
 
74
74
  code += `
75
- ${$pad2Zeros.toString()}
76
- ${$asAny.toString()}
77
- ${$asString.toString()}
78
- ${$asStringNullable.toString()}
79
- ${$asStringSmall.toString()}
80
- ${$asDatetime.toString()}
81
- ${$asDate.toString()}
82
- ${$asTime.toString()}
83
- ${$asNumber.toString()}
84
- ${$asNumberNullable.toString()}
85
- ${$asInteger.toString()}
86
- ${$asIntegerNullable.toString()}
87
- ${$asNull.toString()}
88
- ${$asBoolean.toString()}
89
- ${$asBooleanNullable.toString()}
75
+ ${asFunctions}
90
76
 
91
77
  var isLong = ${isLong ? isLong.toString() : false}
92
78
 
@@ -116,19 +102,19 @@ function build (schema, options) {
116
102
  code = buildObject(location, code, main)
117
103
  break
118
104
  case 'string':
119
- main = schema.nullable ? $asStringNullable.name : getStringSerializer(schema.format)
105
+ main = schema.nullable ? '$asStringNullable' : getStringSerializer(schema.format)
120
106
  break
121
107
  case 'integer':
122
- main = schema.nullable ? $asIntegerNullable.name : $asInteger.name
108
+ main = schema.nullable ? '$asIntegerNullable' : '$asInteger'
123
109
  break
124
110
  case 'number':
125
- main = schema.nullable ? $asNumberNullable.name : $asNumber.name
111
+ main = schema.nullable ? '$asNumberNullable' : '$asNumber'
126
112
  break
127
113
  case 'boolean':
128
- main = schema.nullable ? $asBooleanNullable.name : $asBoolean.name
114
+ main = schema.nullable ? '$asBooleanNullable' : '$asBoolean'
129
115
  break
130
116
  case 'null':
131
- main = $asNull.name
117
+ main = '$asNull'
132
118
  break
133
119
  case 'array':
134
120
  main = '$main'
@@ -233,6 +219,7 @@ function getTestSerializer (format) {
233
219
  return stringSerializerMap[format]
234
220
  }
235
221
 
222
+ const asFunctions = `
236
223
  function $pad2Zeros (num) {
237
224
  const s = '00' + num
238
225
  return s[s.length - 2] + s[s.length - 1]
@@ -372,7 +359,7 @@ function $asStringSmall (str) {
372
359
  surrogateFound = true
373
360
  }
374
361
  if (point === 34 || point === 92) {
375
- result += str.slice(last, i) + '\\'
362
+ result += str.slice(last, i) + '\\\\'
376
363
  last = i
377
364
  found = true
378
365
  }
@@ -385,6 +372,7 @@ function $asStringSmall (str) {
385
372
  }
386
373
  return ((point < 32) || (surrogateFound === true)) ? JSON.stringify(str) : '"' + result + '"'
387
374
  }
375
+ `
388
376
 
389
377
  function addPatternProperties (location) {
390
378
  const schema = location.schema
@@ -928,7 +916,7 @@ function buildObject (location, code, name) {
928
916
  if (schema.nullable) {
929
917
  code += `
930
918
  if(input === null) {
931
- return '${$asNull()}';
919
+ return 'null';
932
920
  }
933
921
  `
934
922
  }
@@ -967,7 +955,7 @@ function buildArray (location, code, name, key = null) {
967
955
  if (schema.nullable) {
968
956
  code += `
969
957
  if(obj === null) {
970
- return '${$asNull()}';
958
+ return 'null';
971
959
  }
972
960
  `
973
961
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fast-json-stringify",
3
- "version": "2.7.6",
3
+ "version": "2.7.7",
4
4
  "description": "Stringify your JSON at max speed",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -41,7 +41,8 @@
41
41
  "semver": "^7.1.0",
42
42
  "standard": "^16.0.1",
43
43
  "tap": "^15.0.0",
44
- "typescript": "^4.0.2"
44
+ "typescript": "^4.0.2",
45
+ "webpack": "^5.40.0"
45
46
  },
46
47
  "dependencies": {
47
48
  "ajv": "^6.11.0",
@@ -0,0 +1,50 @@
1
+ 'use strict'
2
+
3
+ const test = require('tap').test
4
+ const webpack = require('webpack')
5
+ const path = require('path')
6
+
7
+ test('the library should work with webpack', async (t) => {
8
+ t.plan(1)
9
+ const targetdir = path.resolve(__dirname, '..', '.cache')
10
+ const targetname = path.join(targetdir, 'webpacktest.js')
11
+ const wopts = {
12
+ entry: path.resolve(__dirname, '..', 'index.js'),
13
+ mode: 'production',
14
+ target: 'node',
15
+ output: {
16
+ path: targetdir,
17
+ filename: 'webpacktest.js',
18
+ library: {
19
+ name: 'fastJsonStringify',
20
+ type: 'umd'
21
+ }
22
+ }
23
+ }
24
+ await new Promise((resolve, reject) => {
25
+ webpack(wopts, (err, stats) => {
26
+ if (err) { reject(err) } else { resolve(stats) };
27
+ })
28
+ })
29
+ const build = require(targetname)
30
+ const stringify = build({
31
+ title: 'webpack should not rename code to be executed',
32
+ type: 'object',
33
+ properties: {
34
+ foo: {
35
+ type: 'string'
36
+ },
37
+ bar: {
38
+ type: 'boolean'
39
+ }
40
+ },
41
+ patternProperties: {
42
+ foo: {
43
+ type: 'number'
44
+ }
45
+ }
46
+ })
47
+
48
+ const obj = { foo: '42', bar: true }
49
+ t.equal(stringify(obj), '{"foo":"42","bar":true}')
50
+ })