@7365admin1/module-hygiene 4.29.1-staging.14 → 4.29.1-staging.15
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/.changeset/search-input-bounds.md +5 -0
- package/dist/index.js +10 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/test/escape-regex.util.test.mjs +26 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@7365admin1/module-hygiene",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "4.29.1-staging.
|
|
4
|
+
"version": "4.29.1-staging.15",
|
|
5
5
|
"author": "7365admin1",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.mjs",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
14
14
|
"release": "yarn run build && changeset publish",
|
|
15
15
|
"lint": "tsc",
|
|
16
|
-
"test": "tsup src/utils/hygiene-dashboard-metrics.util.ts src/utils/hygiene-checkout-decision.util.ts src/utils/completion-photo.util.ts src/utils/area-unit.util.ts --format esm --out-dir test/.build --no-dts --silent && node --test \"test/*.test.mjs\""
|
|
16
|
+
"test": "tsup src/utils/hygiene-dashboard-metrics.util.ts src/utils/hygiene-checkout-decision.util.ts src/utils/completion-photo.util.ts src/utils/area-unit.util.ts src/utils/escape-regex.util.ts --format esm --out-dir test/.build --no-dts --silent && node --test \"test/*.test.mjs\""
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@changesets/cli": "^2.26.0",
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { test } from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { readFileSync, readdirSync } from "node:fs";
|
|
4
|
+
import { escapeRegex } from "./.build/escape-regex.util.mjs";
|
|
5
|
+
|
|
6
|
+
test("search text is matched literally, not run as a pattern", () => {
|
|
7
|
+
for (const typed of [".*", "(a+)+$", "[", "a|b", "^x$", "\\", "50% off (new)"]) {
|
|
8
|
+
const rx = new RegExp(escapeRegex(typed), "i");
|
|
9
|
+
assert.ok(rx.test(`xx${typed}yy`), `${typed} should match itself`);
|
|
10
|
+
}
|
|
11
|
+
assert.equal(new RegExp(escapeRegex(".*"), "i").test("anything"), false);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test("missing or non-string search stays harmless", () => {
|
|
15
|
+
assert.equal(escapeRegex(undefined), "");
|
|
16
|
+
assert.equal(escapeRegex(null), "");
|
|
17
|
+
assert.equal(escapeRegex(42), "42");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("every repository $regex on a search box goes through escapeRegex", () => {
|
|
21
|
+
const dir = new URL("../src/repositories/", import.meta.url);
|
|
22
|
+
for (const f of readdirSync(dir)) {
|
|
23
|
+
const src = readFileSync(new URL(f, dir), "utf8");
|
|
24
|
+
assert.doesNotMatch(src, /\$regex:\s*search\b/, `${f} passes raw search into $regex`);
|
|
25
|
+
}
|
|
26
|
+
});
|