pema 0.14.0 → 0.14.2
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.
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
import is from "@rcompat/is";
|
|
2
2
|
export default function coerce_bigint(x) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
if (is.numeric(x)) {
|
|
4
|
+
// Retain non-finite rejection and bound exponent expansion. This number
|
|
5
|
+
// is only an eligibility check, never the source of the bigint value.
|
|
6
|
+
if (!is.finite(Number(x)))
|
|
7
|
+
return x;
|
|
8
|
+
const [coefficient, exponent = "0"] = x.trim().toLowerCase().split("e");
|
|
9
|
+
const [whole, fraction = ""] = coefficient.split(".");
|
|
10
|
+
const digits = whole + fraction;
|
|
11
|
+
if (/^[+-]?0+$/.test(digits))
|
|
12
|
+
return 0n;
|
|
13
|
+
const shift = Number(exponent) - fraction.length;
|
|
14
|
+
if (shift >= 0)
|
|
15
|
+
return BigInt(digits) * 10n ** BigInt(shift);
|
|
16
|
+
// A decimal shift may discard only zeroes, never a fractional value.
|
|
17
|
+
const end = digits.length + shift;
|
|
18
|
+
if (end <= 0 || /[1-9]/.test(digits.slice(end)))
|
|
19
|
+
return x;
|
|
20
|
+
return BigInt(digits.slice(0, end));
|
|
21
|
+
}
|
|
22
|
+
// Number inputs have already acquired JavaScript's precision semantics.
|
|
23
|
+
if (is.int(x))
|
|
24
|
+
return BigInt(x);
|
|
8
25
|
// bigint or invalid
|
|
9
26
|
return x;
|
|
10
27
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import regex from "#validator/regex";
|
|
2
|
-
|
|
2
|
+
// Choose the first dot after the domain's first character. Keeping dots out
|
|
3
|
+
// of the preceding repetition avoids quadratic backtracking on hostile input.
|
|
4
|
+
const re = /^[^\s@]+@[^\s@][^\s@.]*\.[^\s@]+$/u;
|
|
3
5
|
export default function email(options) {
|
|
4
6
|
return regex(re, options ?? (x => `"${x}" is not a valid email`));
|
|
5
7
|
}
|
package/package.json
CHANGED