Skip to content

Commit

Permalink
Bumped v4.16.0
Browse files Browse the repository at this point in the history
Signed-off-by: Matteo Collina <hello@matteocollina.com>
  • Loading branch information
mcollina committed Apr 25, 2023
1 parent cefdb3a commit c2f3ff6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 164 deletions.
2 changes: 1 addition & 1 deletion fastify.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const VERSION = '4.15.0'
const VERSION = '4.16.0'

const Avvio = require('avvio')
const http = require('http')
Expand Down
171 changes: 9 additions & 162 deletions lib/error-serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,171 +2,19 @@
/* istanbul ignore file */

'use strict'


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

class Serializer {
constructor (options) {
switch (options && options.rounding) {
case 'floor':
this.parseInteger = Math.floor
break
case 'ceil':
this.parseInteger = Math.ceil
break
case 'round':
this.parseInteger = Math.round
break
case 'trunc':
default:
this.parseInteger = Math.trunc
break
}
}

asInteger (i) {
if (typeof i === 'number') {
if (i === Infinity || i === -Infinity) {
throw new Error(`The value "${i}" cannot be converted to an integer.`)
}
if (Number.isInteger(i)) {
return '' + i
}
if (Number.isNaN(i)) {
throw new Error(`The value "${i}" cannot be converted to an integer.`)
}
return this.parseInteger(i)
} else if (i === null) {
return '0'
} else if (typeof i === 'bigint') {
return i.toString()
} else {
/* eslint no-undef: "off" */
const integer = this.parseInteger(i)
if (Number.isFinite(integer)) {
return '' + integer
} else {
throw new Error(`The value "${i}" cannot be converted to an integer.`)
}
}
}

asNumber (i) {
const num = Number(i)
if (Number.isNaN(num)) {
throw new Error(`The value "${i}" cannot be converted to a number.`)
} else if (!Number.isFinite(num)) {
return null
} else {
return '' + num
}
}

asBoolean (bool) {
return bool && 'true' || 'false' // eslint-disable-line
}

asDateTime (date) {
if (date === null) return '""'
if (date instanceof Date) {
return '"' + date.toISOString() + '"'
}
if (typeof date === 'string') {
return '"' + date + '"'
}
throw new Error(`The value "${date}" cannot be converted to a date-time.`)
}

asDate (date) {
if (date === null) return '""'
if (date instanceof Date) {
return '"' + new Date(date.getTime() - (date.getTimezoneOffset() * 60000)).toISOString().slice(0, 10) + '"'
}
if (typeof date === 'string') {
return '"' + date + '"'
}
throw new Error(`The value "${date}" cannot be converted to a date.`)
}
const { dependencies } = require('fast-json-stringify/lib/standalone')

asTime (date) {
if (date === null) return '""'
if (date instanceof Date) {
return '"' + new Date(date.getTime() - (date.getTimezoneOffset() * 60000)).toISOString().slice(11, 19) + '"'
}
if (typeof date === 'string') {
return '"' + date + '"'
}
throw new Error(`The value "${date}" cannot be converted to a time.`)
}
const { Serializer, Validator } = dependencies

asString (str) {
if (typeof str !== 'string') {
if (str === null) {
return '""'
}
if (str instanceof Date) {
return '"' + str.toISOString() + '"'
}
if (str instanceof RegExp) {
str = str.source
} else {
str = str.toString()
}
}

// Fast escape chars check
if (!STR_ESCAPE.test(str)) {
return '"' + str + '"'
} else if (str.length < 42) {
return this.asStringSmall(str)
} else {
return JSON.stringify(str)
}
}
const serializerState = {"mode":"standalone"}
const serializer = Serializer.restoreFromState(serializerState)

// magically escape strings for json
// relying on their charCodeAt
// everything below 32 needs JSON.stringify()
// every string that contain surrogate needs JSON.stringify()
// 34 and 92 happens all the time, so we
// have a fast case for them
asStringSmall (str) {
const l = str.length
let result = ''
let last = 0
let found = false
let surrogateFound = false
let point = 255
// eslint-disable-next-line
for (var i = 0; i < l && point >= 32; i++) {
point = str.charCodeAt(i)
if (point >= 0xD800 && point <= 0xDFFF) {
// The current character is a surrogate.
surrogateFound = true
}
if (point === 34 || point === 92) {
result += str.slice(last, i) + '\\'
last = i
found = true
}
}
const validator = null

if (!found) {
result = str
} else {
result += str.slice(last)
}
return ((point < 32) || (surrogateFound === true)) ? JSON.stringify(str) : '"' + result + '"'
}
}


const serializer = new Serializer()

module.exports = function anonymous(validator,serializer
) {



function anonymous0 (input) {
// #
Expand Down Expand Up @@ -206,7 +54,6 @@ class Serializer {
}

const main = anonymous0
return main



module.exports = main
}(validator, serializer)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fastify",
"version": "4.15.0",
"version": "4.16.0",
"description": "Fast and low overhead web framework, for Node.js",
"main": "fastify.js",
"type": "commonjs",
Expand Down

0 comments on commit c2f3ff6

Please sign in to comment.