Skip to content

Commit a489611

Browse files
committed
bumped v4.14.0
Signed-off-by: Matteo Collina <[email protected]>
1 parent 5a288bc commit a489611

File tree

3 files changed

+51
-70
lines changed

3 files changed

+51
-70
lines changed

fastify.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const VERSION = '4.13.0'
3+
const VERSION = '4.14.0'
44

55
const Avvio = require('avvio')
66
const http = require('http')

lib/error-serializer.js

Lines changed: 49 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
/* istanbul ignore file */
33

44
'use strict'
5-
65

76

87
// eslint-disable-next-line
98
const STR_ESCAPE = /[\u0000-\u001f\u0022\u005c\ud800-\udfff]|[\ud800-\udbff](?![\udc00-\udfff])|(?:[^\ud800-\udbff]|^)[\udc00-\udfff]/
109

1110
class Serializer {
12-
constructor (options = {}) {
13-
switch (options.rounding) {
11+
constructor (options) {
12+
switch (options && options.rounding) {
1413
case 'floor':
1514
this.parseInteger = Math.floor
1615
break
@@ -20,24 +19,36 @@ class Serializer {
2019
case 'round':
2120
this.parseInteger = Math.round
2221
break
22+
case 'trunc':
2323
default:
2424
this.parseInteger = Math.trunc
2525
break
2626
}
2727
}
2828

2929
asInteger (i) {
30-
if (typeof i === 'bigint') {
30+
if (typeof i === 'number') {
31+
if (i === Infinity || i === -Infinity) {
32+
throw new Error(`The value "${i}" cannot be converted to an integer.`)
33+
}
34+
if (Number.isInteger(i)) {
35+
return '' + i
36+
}
37+
if (Number.isNaN(i)) {
38+
throw new Error(`The value "${i}" cannot be converted to an integer.`)
39+
}
40+
return this.parseInteger(i)
41+
} else if (i === null) {
42+
return '0'
43+
} else if (typeof i === 'bigint') {
3144
return i.toString()
32-
} else if (Number.isInteger(i)) {
33-
return '' + i
3445
} else {
3546
/* eslint no-undef: "off" */
3647
const integer = this.parseInteger(i)
37-
if (Number.isNaN(integer) || !Number.isFinite(integer)) {
38-
throw new Error(`The value "${i}" cannot be converted to an integer.`)
39-
} else {
48+
if (Number.isFinite(integer)) {
4049
return '' + integer
50+
} else {
51+
throw new Error(`The value "${i}" cannot be converted to an integer.`)
4152
}
4253
}
4354
}
@@ -91,23 +102,24 @@ class Serializer {
91102
}
92103

93104
asString (str) {
94-
const quotes = '"'
95-
if (str instanceof Date) {
96-
return quotes + str.toISOString() + quotes
97-
} else if (str === null) {
98-
return quotes + quotes
99-
} else if (str instanceof RegExp) {
100-
str = str.source
101-
} else if (typeof str !== 'string') {
102-
str = str.toString()
105+
if (typeof str !== 'string') {
106+
if (str === null) {
107+
return '""'
108+
}
109+
if (str instanceof Date) {
110+
return '"' + str.toISOString() + '"'
111+
}
112+
if (str instanceof RegExp) {
113+
str = str.source
114+
} else {
115+
str = str.toString()
116+
}
103117
}
104118

105119
// Fast escape chars check
106120
if (!STR_ESCAPE.test(str)) {
107-
return quotes + str + quotes
108-
}
109-
110-
if (str.length < 42) {
121+
return '"' + str + '"'
122+
} else if (str.length < 42) {
111123
return this.asStringSmall(str)
112124
} else {
113125
return JSON.stringify(str)
@@ -151,81 +163,50 @@ class Serializer {
151163
}
152164

153165

154-
155-
const serializer = new Serializer({"mode":"standalone"})
166+
const serializer = new Serializer()
156167

157168

158169

159-
function main (input) {
160-
let json = ''
161-
json += anonymous0(input)
162-
return json
163-
}
164170

165171
function anonymous0 (input) {
166172
// #
167173

168-
var obj = (input && typeof input.toJSON === 'function')
174+
const obj = (input && typeof input.toJSON === 'function')
169175
? input.toJSON()
170176
: input
171177

172-
var json = '{'
173-
var addComma = false
178+
let json = '{'
179+
let addComma = false
174180

175181
if (obj["statusCode"] !== undefined) {
176-
177-
if (addComma) {
178-
json += ','
179-
} else {
180-
addComma = true
181-
}
182-
183-
json += "\"statusCode\"" + ':'
182+
!addComma && (addComma = true) || (json += ',')
183+
json += "\"statusCode\":"
184184
json += serializer.asNumber(obj["statusCode"])
185185
}
186186

187187
if (obj["code"] !== undefined) {
188-
189-
if (addComma) {
190-
json += ','
191-
} else {
192-
addComma = true
193-
}
194-
195-
json += "\"code\"" + ':'
188+
!addComma && (addComma = true) || (json += ',')
189+
json += "\"code\":"
196190
json += serializer.asString(obj["code"])
197191
}
198192

199193
if (obj["error"] !== undefined) {
200-
201-
if (addComma) {
202-
json += ','
203-
} else {
204-
addComma = true
205-
}
206-
207-
json += "\"error\"" + ':'
194+
!addComma && (addComma = true) || (json += ',')
195+
json += "\"error\":"
208196
json += serializer.asString(obj["error"])
209197
}
210198

211199
if (obj["message"] !== undefined) {
212-
213-
if (addComma) {
214-
json += ','
215-
} else {
216-
addComma = true
217-
}
218-
219-
json += "\"message\"" + ':'
200+
!addComma && (addComma = true) || (json += ',')
201+
json += "\"message\":"
220202
json += serializer.asString(obj["message"])
221203
}
222204

223-
json += '}'
224-
return json
205+
return json + '}'
225206
}
226207

208+
const main = anonymous0
209+
227210

228-
229211

230212
module.exports = main
231-

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fastify",
3-
"version": "4.13.0",
3+
"version": "4.14.0",
44
"description": "Fast and low overhead web framework, for Node.js",
55
"main": "fastify.js",
66
"type": "commonjs",

0 commit comments

Comments
 (0)