@nsail/stack 0.1.775 → 0.1.779
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.
- package/dist/validation.js +21 -1
- package/package.json +1 -1
package/dist/validation.js
CHANGED
|
@@ -12,6 +12,26 @@ const exact = {
|
|
|
12
12
|
bigint: /^\s*[+-]?\d+\s*$/,
|
|
13
13
|
decimal: /^\s*[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?\s*$/,
|
|
14
14
|
};
|
|
15
|
+
// Compiled once per pattern, with `u` so \p{L} is a property class. A pattern `u` refuses is
|
|
16
|
+
// retried without it only when that cannot change its meaning (no \p{}, \P{}, \u{}); one
|
|
17
|
+
// JavaScript cannot compile is null: the server's rule alone judges it.
|
|
18
|
+
const compiled = new Map();
|
|
19
|
+
function build(pattern, flags) {
|
|
20
|
+
try {
|
|
21
|
+
return new RegExp(`^(?:${pattern})$`, flags);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function compile(pattern) {
|
|
28
|
+
let regex = compiled.get(pattern);
|
|
29
|
+
if (regex === undefined) {
|
|
30
|
+
regex = build(pattern, "u") ?? (/\\[pPu]\{/.test(pattern) ? null : build(pattern, ""));
|
|
31
|
+
compiled.set(pattern, regex);
|
|
32
|
+
}
|
|
33
|
+
return regex;
|
|
34
|
+
}
|
|
15
35
|
function issue(code, message, field, args = {}) {
|
|
16
36
|
return { code, message, source: field, arguments: { field, ...args } };
|
|
17
37
|
}
|
|
@@ -62,7 +82,7 @@ export function validateField(field, value) {
|
|
|
62
82
|
(field.format === "email" && !email.test(value)) ||
|
|
63
83
|
(field.format === "phone" && !phone.test(value)) ||
|
|
64
84
|
(field.format === "url" && !url.test(value)) ||
|
|
65
|
-
(field.pattern !== undefined &&
|
|
85
|
+
(field.pattern !== undefined && compile(field.pattern)?.test(value) === false);
|
|
66
86
|
if (formatted) {
|
|
67
87
|
issues.push(issue("InvalidFormat", `The field ${name} has an invalid format`, name));
|
|
68
88
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nsail/stack",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.779",
|
|
4
4
|
"description": "NSail's vendor-free client half: sends messages from the descriptors an Sdk generates, speaks the catalog, and holds the hooks a page reads with.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|