Skip to content

Commit 9402c9b

Browse files
committed
further improve regex perf
1 parent 7247c70 commit 9402c9b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/core/json.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ export const toJson = (
5050
return originalStringify(value, replacer as never, space);
5151
}
5252

53-
const bigInts = /([\[:])?"(-?\d+)n"($|([\n]|\s)*(\s|[\n])*[,\}\]])/g;
54-
const noise = /([\[:])?("-?\d+n+)n("$|"([\n]|\s)*(\s|[\n])*[,\}\]])/g;
53+
const bigInts = /([\[:])?"(-?\d+)n"($|\s*[,\}\]])/g;
54+
const noise = /([\[:])?("-?\d+n+)n("$|"\s*[,\}\]])/g;
5555
const convertedToCustomJSON = originalStringify(
5656
value,
5757
(key, val) => {
@@ -105,7 +105,7 @@ export function fromJson<T = unknown>(
105105

106106
const MAX_INT = Number.MAX_SAFE_INTEGER.toString();
107107
const MAX_DIGITS = MAX_INT.length;
108-
const stringsOrLargeNumbers = /"(?:\\.|[^"])*"|-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?/g;
108+
const stringsOrLargeNumbers = /"(?:[^"\\]|\\.)*"|-?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?/g;
109109
const noiseValueWithQuotes = /^"-?\d+n+"$/; // Noise - strings that match the custom format before being converted to it
110110
const customFormat = /^-?\d+n$/;
111111

0 commit comments

Comments
 (0)