fast-json-stringify 2.2.8 → 2.2.9

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/bench.js CHANGED
@@ -58,11 +58,6 @@ const obj = {
58
58
 
59
59
  const multiArray = []
60
60
 
61
- const JSTR = require('json-strify')
62
- const JSTRStringify = JSTR(schemaCJS)
63
- const JSTRArray = JSTR(arraySchemaCJS)
64
- const JSTRInstance = JSTR()
65
-
66
61
  const CJS = require('compile-json-stringify')
67
62
  const CJSStringify = CJS(schemaCJS)
68
63
  const CJSStringifyArray = CJS(arraySchemaCJS)
@@ -90,9 +85,6 @@ for (i = 0; i < 1000; i++) {
90
85
  suite.add('FJS creation', function () {
91
86
  FJS(schema)
92
87
  })
93
- suite.add('JSTR creation', function () {
94
- JSTR(schemaCJS)
95
- })
96
88
  suite.add('CJS creation', function () {
97
89
  CJS(schemaCJS)
98
90
  })
@@ -105,10 +97,6 @@ suite.add('fast-json-stringify array', function () {
105
97
  stringifyArray(multiArray)
106
98
  })
107
99
 
108
- suite.add('json-strify array', function () {
109
- JSTRArray(multiArray)
110
- })
111
-
112
100
  suite.add('compile-json-stringify array', function () {
113
101
  CJSStringifyArray(multiArray)
114
102
  })
@@ -121,10 +109,6 @@ suite.add('fast-json-stringify long string', function () {
121
109
  stringifyString(str)
122
110
  })
123
111
 
124
- suite.add('json-strify long string', function () {
125
- JSTRInstance(str)
126
- })
127
-
128
112
  suite.add('compile-json-stringify long string', function () {
129
113
  CJSStringifyString(str)
130
114
  })
@@ -137,10 +121,6 @@ suite.add('fast-json-stringify short string', function () {
137
121
  stringifyString('hello world')
138
122
  })
139
123
 
140
- suite.add('json-strify short string', function () {
141
- JSTRInstance('hello world')
142
- })
143
-
144
124
  suite.add('compile-json-stringify short string', function () {
145
125
  CJSStringifyString('hello world')
146
126
  })
@@ -153,10 +133,6 @@ suite.add('fast-json-stringify obj', function () {
153
133
  stringify(obj)
154
134
  })
155
135
 
156
- suite.add('json-strify obj', function () {
157
- JSTRStringify(obj)
158
- })
159
-
160
136
  suite.add('compile-json-stringify obj', function () {
161
137
  CJSStringify(obj)
162
138
  })
package/index.js CHANGED
@@ -937,7 +937,7 @@ function buildObject (location, code, name) {
937
937
  return code
938
938
  }
939
939
 
940
- function buildArray (location, code, name) {
940
+ function buildArray (location, code, name, key = null) {
941
941
  var schema = location.schema
942
942
  code += `
943
943
  function ${name} (obj) {
@@ -988,6 +988,14 @@ function buildArray (location, code, name) {
988
988
  result = nested(laterCode, name, '[i]', mergeLocation(location, { schema: schema.items }), undefined, true)
989
989
  }
990
990
 
991
+ if (key) {
992
+ code += `
993
+ if(!Array.isArray(obj)) {
994
+ throw new TypeError(\`Property '${key}' should be of type array, received '$\{obj}' instead.\`)
995
+ }
996
+ `
997
+ }
998
+
991
999
  code += `
992
1000
  var l = obj.length
993
1001
  var w = l - 1
@@ -1131,7 +1139,7 @@ function nested (laterCode, name, key, location, subKey, isArray) {
1131
1139
  break
1132
1140
  case 'array':
1133
1141
  funcName = asFuncName('$arr' + name + key + subKey) // eslint-disable-line
1134
- laterCode = buildArray(location, laterCode, funcName)
1142
+ laterCode = buildArray(location, laterCode, funcName, key)
1135
1143
  code += `
1136
1144
  json += ${funcName}(obj${accessor})
1137
1145
  `
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fast-json-stringify",
3
- "version": "2.2.8",
3
+ "version": "2.2.9",
4
4
  "description": "Stringify your JSON at max speed",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -33,7 +33,6 @@
33
33
  "benchmark": "^2.1.4",
34
34
  "compile-json-stringify": "^0.1.2",
35
35
  "is-my-json-valid": "^2.20.0",
36
- "json-strify": "^0.1.7",
37
36
  "long": "^4.0.0",
38
37
  "moment": "^2.24.0",
39
38
  "pre-commit": "^1.2.2",
@@ -417,3 +417,21 @@ test('object that is simultaneously a string and a json switched', (t) => {
417
417
  const valueObj = stringify({ simultaneously: { foo: likeObjectId } })
418
418
  t.is(valueObj, '{"simultaneously":{"foo":"hello"}}')
419
419
  })
420
+
421
+ test('should throw an error when type is array and object is null', (t) => {
422
+ t.plan(1)
423
+ const schema = {
424
+ type: 'object',
425
+ properties: {
426
+ arr: {
427
+ type: 'array',
428
+ items: {
429
+ type: 'number'
430
+ }
431
+ }
432
+ }
433
+ }
434
+
435
+ const stringify = build(schema)
436
+ t.throws(() => stringify({ arr: null }), new TypeError('Property \'arr\' should be of type array, received \'null\' instead.'))
437
+ })