From 59ce4f7e773006c16e2520335836cd7f29600720 Mon Sep 17 00:00:00 2001 From: francesco Date: Mon, 18 Mar 2024 17:26:16 +0100 Subject: [PATCH 1/6] chore(perf): fast regex (#696) Signed-off-by: francesco --- lib/serializer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/serializer.js b/lib/serializer.js index 387e8927..3e290c24 100644 --- a/lib/serializer.js +++ b/lib/serializer.js @@ -1,7 +1,7 @@ 'use strict' // eslint-disable-next-line -const STR_ESCAPE = /[\u0000-\u001f\u0022\u005c\ud800-\udfff]|[\ud800-\udbff](?![\udc00-\udfff])|(?:[^\ud800-\udbff]|^)[\udc00-\udfff]/ +const STR_ESCAPE = /[\u0000-\u001f\u0022\u005c\ud800-\udfff]/ module.exports = class Serializer { constructor (options) { From b07e60723c1165f896d0a376091c093a85608a65 Mon Sep 17 00:00:00 2001 From: francesco Date: Mon, 18 Mar 2024 17:27:21 +0100 Subject: [PATCH 2/6] chore(perf): reduce if statement call on `"` and `\` (#695) With this PR when a `"` or `\` is into the string, the if statement for surrogate check is not called. This is a little performance improvment Signed-off-by: francesco --- lib/serializer.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/serializer.js b/lib/serializer.js index 3e290c24..9a3bbd4e 100644 --- a/lib/serializer.js +++ b/lib/serializer.js @@ -128,10 +128,6 @@ module.exports = class Serializer { // eslint-disable-next-line for (var i = 0; i < len; i++) { point = str.charCodeAt(i) - if (point < 32 || (point >= 0xD800 && point <= 0xDFFF)) { - // The current character is non-printable characters or a surrogate. - return JSON.stringify(str) - } if ( point === 0x22 || // '"' point === 0x5c // '\' @@ -139,6 +135,9 @@ module.exports = class Serializer { last === -1 && (last = 0) result += str.slice(last, i) + '\\' last = i + } else if (point < 32 || (point >= 0xD800 && point <= 0xDFFF)) { + // The current character is non-printable characters or a surrogate. + return JSON.stringify(str) } } From 7051fe6657bbcd526018e44d0e2e3a2bd28fa700 Mon Sep 17 00:00:00 2001 From: francesco Date: Mon, 18 Mar 2024 17:28:32 +0100 Subject: [PATCH 3/6] perf: reduce if statement for `NaN` (micro-optimization) (#697) * chore(perf): reduce if statement for `NaN` Signed-off-by: francesco * isInteger return false for Infinity and NaN Signed-off-by: francesco * fast check for NaN Signed-off-by: francesco * disable lint Signed-off-by: francesco * disable only for self-compare NaN Co-authored-by: Aras Abbasi Signed-off-by: francesco * fast check for NaN Signed-off-by: francesco --------- Signed-off-by: francesco Co-authored-by: Aras Abbasi --- lib/serializer.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/serializer.js b/lib/serializer.js index 9a3bbd4e..1ad588a1 100644 --- a/lib/serializer.js +++ b/lib/serializer.js @@ -25,13 +25,12 @@ module.exports = class Serializer { 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)) { + // check if number is Infinity or NaN + // eslint-disable-next-line no-self-compare + if (i === Infinity || i === -Infinity || i !== i) { throw new Error(`The value "${i}" cannot be converted to an integer.`) } return this.parseInteger(i) @@ -52,7 +51,9 @@ module.exports = class Serializer { asNumber (i) { const num = Number(i) - if (Number.isNaN(num)) { + // check if number is NaN + // eslint-disable-next-line no-self-compare + if (num !== num) { throw new Error(`The value "${i}" cannot be converted to a number.`) } else if (!Number.isFinite(num)) { return 'null' From 4afc53520c5fc759903b33384a698efe4eb193aa Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Apr 2024 14:36:43 +0000 Subject: [PATCH 4/6] build(deps): bump ajv-formats from 2.1.1 to 3.0.1 (#702) Bumps [ajv-formats](https://github.com/ajv-validator/ajv-formats) from 2.1.1 to 3.0.1. - [Release notes](https://github.com/ajv-validator/ajv-formats/releases) - [Commits](https://github.com/ajv-validator/ajv-formats/compare/v2.1.1...v3.0.1) --- updated-dependencies: - dependency-name: ajv-formats dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7bf62f94..674183cd 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ }, "dependencies": { "ajv": "^8.10.0", - "ajv-formats": "^2.1.1", + "ajv-formats": "^3.0.1", "fast-deep-equal": "^3.1.3", "fast-uri": "^2.1.0", "rfdc": "^1.2.0", From b75db8ec440b860653b5ef85313de1a67490fdf0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 1 Apr 2024 14:37:52 +0000 Subject: [PATCH 5/6] build(deps-dev): bump tsd from 0.30.7 to 0.31.0 (#703) Bumps [tsd](https://github.com/tsdjs/tsd) from 0.30.7 to 0.31.0. - [Release notes](https://github.com/tsdjs/tsd/releases) - [Commits](https://github.com/tsdjs/tsd/compare/v0.30.7...v0.31.0) --- updated-dependencies: - dependency-name: tsd dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 674183cd..d12ee447 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "simple-git": "^3.7.1", "standard": "^17.0.0", "tap": "^16.0.1", - "tsd": "^0.30.3", + "tsd": "^0.31.0", "webpack": "^5.40.0", "fast-json-stringify": "." }, From bb08e776af393aa4d0b321088105d96f3e335ffe Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Tue, 9 Apr 2024 10:07:26 +0200 Subject: [PATCH 6/6] 5.14.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d12ee447..27c7d017 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fast-json-stringify", - "version": "5.13.0", + "version": "5.14.0", "description": "Stringify your JSON at max speed", "main": "index.js", "type": "commonjs",