fast-json-stringify 1.15.0 → 1.15.4

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.
@@ -4,43 +4,43 @@ const t = require('tap')
4
4
  const build = require('..')
5
5
 
6
6
  const schema = {
7
- 'type': 'object',
8
- 'properties': {
7
+ type: 'object',
8
+ properties: {
9
9
  },
10
- 'if': {
11
- 'properties': {
12
- 'kind': { 'type': 'string', 'enum': ['foobar'] }
10
+ if: {
11
+ properties: {
12
+ kind: { type: 'string', enum: ['foobar'] }
13
13
  }
14
14
  },
15
- 'then': {
16
- 'properties': {
17
- 'kind': { 'type': 'string', 'enum': ['foobar'] },
18
- 'foo': { 'type': 'string' },
19
- 'bar': { 'type': 'number' },
20
- 'list': {
21
- 'type': 'array',
22
- 'items': {
23
- 'type': 'object',
24
- 'properties': {
25
- 'name': { 'type': 'string' },
26
- 'value': { 'type': 'string' }
15
+ then: {
16
+ properties: {
17
+ kind: { type: 'string', enum: ['foobar'] },
18
+ foo: { type: 'string' },
19
+ bar: { type: 'number' },
20
+ list: {
21
+ type: 'array',
22
+ items: {
23
+ type: 'object',
24
+ properties: {
25
+ name: { type: 'string' },
26
+ value: { type: 'string' }
27
27
  }
28
28
  }
29
29
  }
30
30
  }
31
31
  },
32
- 'else': {
33
- 'properties': {
34
- 'kind': { 'type': 'string', 'enum': ['greeting'] },
35
- 'hi': { 'type': 'string' },
36
- 'hello': { 'type': 'number' },
37
- 'list': {
38
- 'type': 'array',
39
- 'items': {
40
- 'type': 'object',
41
- 'properties': {
42
- 'name': { 'type': 'string' },
43
- 'value': { 'type': 'string' }
32
+ else: {
33
+ properties: {
34
+ kind: { type: 'string', enum: ['greeting'] },
35
+ hi: { type: 'string' },
36
+ hello: { type: 'number' },
37
+ list: {
38
+ type: 'array',
39
+ items: {
40
+ type: 'object',
41
+ properties: {
42
+ name: { type: 'string' },
43
+ value: { type: 'string' }
44
44
  }
45
45
  }
46
46
  }
@@ -49,104 +49,104 @@ const schema = {
49
49
  }
50
50
 
51
51
  const nestedIfSchema = {
52
- 'type': 'object',
53
- 'properties': { },
54
- 'if': {
55
- 'properties': {
56
- 'kind': { 'type': 'string', 'enum': ['foobar', 'greeting'] }
52
+ type: 'object',
53
+ properties: { },
54
+ if: {
55
+ properties: {
56
+ kind: { type: 'string', enum: ['foobar', 'greeting'] }
57
57
  }
58
58
  },
59
- 'then': {
60
- 'if': {
61
- 'properties': {
62
- 'kind': { 'type': 'string', 'enum': ['foobar'] }
59
+ then: {
60
+ if: {
61
+ properties: {
62
+ kind: { type: 'string', enum: ['foobar'] }
63
63
  }
64
64
  },
65
- 'then': {
66
- 'properties': {
67
- 'kind': { 'type': 'string', 'enum': ['foobar'] },
68
- 'foo': { 'type': 'string' },
69
- 'bar': { 'type': 'number' },
70
- 'list': {
71
- 'type': 'array',
72
- 'items': {
73
- 'type': 'object',
74
- 'properties': {
75
- 'name': { 'type': 'string' },
76
- 'value': { 'type': 'string' }
65
+ then: {
66
+ properties: {
67
+ kind: { type: 'string', enum: ['foobar'] },
68
+ foo: { type: 'string' },
69
+ bar: { type: 'number' },
70
+ list: {
71
+ type: 'array',
72
+ items: {
73
+ type: 'object',
74
+ properties: {
75
+ name: { type: 'string' },
76
+ value: { type: 'string' }
77
77
  }
78
78
  }
79
79
  }
80
80
  }
81
81
  },
82
- 'else': {
83
- 'properties': {
84
- 'kind': { 'type': 'string', 'enum': ['greeting'] },
85
- 'hi': { 'type': 'string' },
86
- 'hello': { 'type': 'number' }
82
+ else: {
83
+ properties: {
84
+ kind: { type: 'string', enum: ['greeting'] },
85
+ hi: { type: 'string' },
86
+ hello: { type: 'number' }
87
87
  }
88
88
  }
89
89
  },
90
- 'else': {
91
- 'properties': {
92
- 'kind': { 'type': 'string', 'enum': ['alphabet'] },
93
- 'a': { 'type': 'string' },
94
- 'b': { 'type': 'number' }
90
+ else: {
91
+ properties: {
92
+ kind: { type: 'string', enum: ['alphabet'] },
93
+ a: { type: 'string' },
94
+ b: { type: 'number' }
95
95
  }
96
96
  }
97
97
  }
98
98
 
99
99
  const nestedElseSchema = {
100
- 'type': 'object',
101
- 'properties': { },
102
- 'if': {
103
- 'properties': {
104
- 'kind': { 'type': 'string', 'enum': ['foobar'] }
100
+ type: 'object',
101
+ properties: { },
102
+ if: {
103
+ properties: {
104
+ kind: { type: 'string', enum: ['foobar'] }
105
105
  }
106
106
  },
107
- 'then': {
108
- 'properties': {
109
- 'kind': { 'type': 'string', 'enum': ['foobar'] },
110
- 'foo': { 'type': 'string' },
111
- 'bar': { 'type': 'number' },
112
- 'list': {
113
- 'type': 'array',
114
- 'items': {
115
- 'type': 'object',
116
- 'properties': {
117
- 'name': { 'type': 'string' },
118
- 'value': { 'type': 'string' }
107
+ then: {
108
+ properties: {
109
+ kind: { type: 'string', enum: ['foobar'] },
110
+ foo: { type: 'string' },
111
+ bar: { type: 'number' },
112
+ list: {
113
+ type: 'array',
114
+ items: {
115
+ type: 'object',
116
+ properties: {
117
+ name: { type: 'string' },
118
+ value: { type: 'string' }
119
119
  }
120
120
  }
121
121
  }
122
122
  }
123
123
  },
124
- 'else': {
125
- 'if': {
126
- 'properties': {
127
- 'kind': { 'type': 'string', 'enum': ['greeting'] }
124
+ else: {
125
+ if: {
126
+ properties: {
127
+ kind: { type: 'string', enum: ['greeting'] }
128
128
  }
129
129
  },
130
- 'then': {
131
- 'properties': {
132
- 'kind': { 'type': 'string', 'enum': ['greeting'] },
133
- 'hi': { 'type': 'string' },
134
- 'hello': { 'type': 'number' }
130
+ then: {
131
+ properties: {
132
+ kind: { type: 'string', enum: ['greeting'] },
133
+ hi: { type: 'string' },
134
+ hello: { type: 'number' }
135
135
  }
136
136
  },
137
- 'else': {
138
- 'properties': {
139
- 'kind': { 'type': 'string', 'enum': ['alphabet'] },
140
- 'a': { 'type': 'string' },
141
- 'b': { 'type': 'number' }
137
+ else: {
138
+ properties: {
139
+ kind: { type: 'string', enum: ['alphabet'] },
140
+ a: { type: 'string' },
141
+ b: { type: 'number' }
142
142
  }
143
143
  }
144
144
  }
145
145
  }
146
146
 
147
147
  const nestedDeepElseSchema = {
148
- 'type': 'object',
149
- 'additionalProperties': schema
148
+ type: 'object',
149
+ additionalProperties: schema
150
150
  }
151
151
 
152
152
  const fooBarInput = {
@@ -23,11 +23,11 @@ function buildTest (schema, toStringify) {
23
23
  }
24
24
 
25
25
  buildTest({
26
- 'title': 'infer type object by keyword',
26
+ title: 'infer type object by keyword',
27
27
  // 'type': 'object',
28
- 'properties': {
29
- 'name': {
30
- 'type': 'string'
28
+ properties: {
29
+ name: {
30
+ type: 'string'
31
31
  }
32
32
  }
33
33
  }, {
@@ -35,15 +35,15 @@ buildTest({
35
35
  })
36
36
 
37
37
  buildTest({
38
- 'title': 'infer type of nested object by keyword',
38
+ title: 'infer type of nested object by keyword',
39
39
  // 'type': 'object',
40
- 'properties': {
41
- 'more': {
42
- 'description': 'more properties',
40
+ properties: {
41
+ more: {
42
+ description: 'more properties',
43
43
  // 'type': 'object',
44
- 'properties': {
45
- 'something': {
46
- 'type': 'string'
44
+ properties: {
45
+ something: {
46
+ type: 'string'
47
47
  }
48
48
  }
49
49
  }
@@ -55,13 +55,13 @@ buildTest({
55
55
  })
56
56
 
57
57
  buildTest({
58
- 'title': 'infer type array by keyword',
59
- 'type': 'object',
60
- 'properties': {
61
- 'ids': {
58
+ title: 'infer type array by keyword',
59
+ type: 'object',
60
+ properties: {
61
+ ids: {
62
62
  // 'type': 'array',
63
- 'items': {
64
- 'type': 'string'
63
+ items: {
64
+ type: 'string'
65
65
  }
66
66
  }
67
67
  }
@@ -70,12 +70,12 @@ buildTest({
70
70
  })
71
71
 
72
72
  buildTest({
73
- 'title': 'infer type string by keyword',
74
- 'type': 'object',
75
- 'properties': {
76
- 'name': {
73
+ title: 'infer type string by keyword',
74
+ type: 'object',
75
+ properties: {
76
+ name: {
77
77
  // 'type': 'string',
78
- 'maxLength': 3
78
+ maxLength: 3
79
79
  }
80
80
  }
81
81
  }, {
@@ -83,12 +83,12 @@ buildTest({
83
83
  })
84
84
 
85
85
  buildTest({
86
- 'title': 'infer type number by keyword',
87
- 'type': 'object',
88
- 'properties': {
89
- 'age': {
86
+ title: 'infer type number by keyword',
87
+ type: 'object',
88
+ properties: {
89
+ age: {
90
90
  // 'type': 'number',
91
- 'maximum': 18
91
+ maximum: 18
92
92
  }
93
93
  }
94
94
  }, {
@@ -13,7 +13,7 @@ function runTests (t, testsuite, skippedTests) {
13
13
  t.test(test.description, (t) => {
14
14
  t.plan(1)
15
15
  try {
16
- let output = stringify(test.data)
16
+ const output = stringify(test.data)
17
17
  t.equal(output, JSON.stringify(test.data), 'compare payloads')
18
18
  } catch (err) {
19
19
  if (test.valid === false) {
@@ -6,7 +6,7 @@ const build = require('..')
6
6
 
7
7
  const nullable = true
8
8
 
9
- let complexObject = {
9
+ const complexObject = {
10
10
  type: 'object',
11
11
  properties: {
12
12
  nullableString: { type: 'string', nullable: nullable },
@@ -45,7 +45,7 @@ let complexObject = {
45
45
  }
46
46
  }
47
47
 
48
- let complexData = {
48
+ const complexData = {
49
49
  nullableString: null,
50
50
  nullableNumber: null,
51
51
  nullableInteger: null,
@@ -62,10 +62,10 @@ let complexData = {
62
62
  nullableNull: null,
63
63
  nullableArray: null
64
64
  },
65
- arrayWithNullableItems: [ 1, 2, null ]
65
+ arrayWithNullableItems: [1, 2, null]
66
66
  }
67
67
 
68
- let complexExpectedResult = {
68
+ const complexExpectedResult = {
69
69
  nullableString: null,
70
70
  nullableNumber: null,
71
71
  nullableInteger: null,
@@ -82,32 +82,32 @@ let complexExpectedResult = {
82
82
  nullableNull: null,
83
83
  nullableArray: null
84
84
  },
85
- arrayWithNullableItems: [ 1, 2, null ]
85
+ arrayWithNullableItems: [1, 2, null]
86
86
  }
87
87
 
88
- let testSet = {
89
- nullableString: [ { type: 'string', nullable: nullable }, null, null ],
90
- nullableNumber: [ { type: 'number', nullable: nullable }, null, null ],
91
- nullableInteger: [ { type: 'integer', nullable: nullable }, null, null ],
92
- nullableBoolean: [ { type: 'boolean', nullable: nullable }, null, null ],
93
- nullableNull: [ { type: 'null', nullable: nullable }, null, null ],
94
- nullableArray: [ {
88
+ const testSet = {
89
+ nullableString: [{ type: 'string', nullable: nullable }, null, null],
90
+ nullableNumber: [{ type: 'number', nullable: nullable }, null, null],
91
+ nullableInteger: [{ type: 'integer', nullable: nullable }, null, null],
92
+ nullableBoolean: [{ type: 'boolean', nullable: nullable }, null, null],
93
+ nullableNull: [{ type: 'null', nullable: nullable }, null, null],
94
+ nullableArray: [{
95
95
  type: 'array',
96
96
  nullable: true,
97
97
  items: {}
98
- }, null, null ],
99
- nullableObject: [ { type: 'object', nullable: true }, null, null ],
100
- complexObject: [ complexObject, complexData, complexExpectedResult ]
98
+ }, null, null],
99
+ nullableObject: [{ type: 'object', nullable: true }, null, null],
100
+ complexObject: [complexObject, complexData, complexExpectedResult]
101
101
  }
102
102
 
103
103
  Object.keys(testSet).forEach(key => {
104
104
  test(`handle nullable:true in ${key} correctly`, (t) => {
105
105
  t.plan(1)
106
106
 
107
- let stringifier = build(testSet[key][0])
108
- let data = testSet[key][1]
109
- let expected = testSet[key][2]
110
- let result = stringifier(data)
107
+ const stringifier = build(testSet[key][0])
108
+ const data = testSet[key][1]
109
+ const expected = testSet[key][2]
110
+ const result = stringifier(data)
111
111
  t.deepEqual(JSON.parse(result), expected)
112
112
  })
113
113
  })
@@ -14,13 +14,13 @@ test('patternProperties', (t) => {
14
14
  }
15
15
  },
16
16
  patternProperties: {
17
- 'foo': {
17
+ foo: {
18
18
  type: 'string'
19
19
  }
20
20
  }
21
21
  })
22
22
 
23
- let obj = { str: 'test', foo: 42, ofoo: true, foof: 'string', objfoo: { a: true }, notMe: false }
23
+ const obj = { str: 'test', foo: 42, ofoo: true, foof: 'string', objfoo: { a: true }, notMe: false }
24
24
  t.equal(stringify(obj), '{"foo":"42","ofoo":"true","foof":"string","objfoo":"[object Object]","str":"test"}')
25
25
  })
26
26