textoneitor 0.0.0-stage → 1.2.1

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.
Files changed (77) hide show
  1. package/LICENSE +101 -0
  2. package/LICENSE-AGPL-3.0 +661 -0
  3. package/README.md +69 -2
  4. package/dist/api/index.d.ts +34 -0
  5. package/dist/api/index.js +98 -0
  6. package/dist/baseline/index.d.ts +20 -0
  7. package/dist/baseline/index.js +81 -0
  8. package/dist/bundle/dist/cli.mjs +29861 -0
  9. package/dist/bundle/package.json +6 -0
  10. package/dist/bundle/rulepack/rulepack.json +1496 -0
  11. package/dist/bundle/rules/situaciones.yml +27 -0
  12. package/dist/cli/benchmark.d.ts +89 -0
  13. package/dist/cli/benchmark.js +185 -0
  14. package/dist/cli/main.d.ts +2 -0
  15. package/dist/cli/main.js +357 -0
  16. package/dist/config/core.d.ts +55 -0
  17. package/dist/config/core.js +244 -0
  18. package/dist/config/glob.d.ts +2 -0
  19. package/dist/config/glob.js +72 -0
  20. package/dist/config/index.d.ts +8 -0
  21. package/dist/config/index.js +38 -0
  22. package/dist/config/situaciones.d.ts +17 -0
  23. package/dist/config/situaciones.js +43 -0
  24. package/dist/contracts/index.d.ts +238 -0
  25. package/dist/contracts/index.js +4 -0
  26. package/dist/document/index.d.ts +10 -0
  27. package/dist/document/index.js +68 -0
  28. package/dist/document/text.d.ts +22 -0
  29. package/dist/document/text.js +91 -0
  30. package/dist/document/tokenize.d.ts +4 -0
  31. package/dist/document/tokenize.js +59 -0
  32. package/dist/markdown/index.d.ts +7 -0
  33. package/dist/markdown/index.js +178 -0
  34. package/dist/paths.d.ts +4 -0
  35. package/dist/paths.js +14 -0
  36. package/dist/reporters/index.d.ts +29 -0
  37. package/dist/reporters/index.js +182 -0
  38. package/dist/rules/compiler/build.d.ts +1 -0
  39. package/dist/rules/compiler/build.js +46 -0
  40. package/dist/rules/compiler/index.d.ts +40 -0
  41. package/dist/rules/compiler/index.js +343 -0
  42. package/dist/rules/compiler/safety.d.ts +16 -0
  43. package/dist/rules/compiler/safety.js +124 -0
  44. package/dist/rules/detectors/index.d.ts +4 -0
  45. package/dist/rules/detectors/index.js +636 -0
  46. package/dist/rules/detectors/shared.d.ts +30 -0
  47. package/dist/rules/detectors/shared.js +87 -0
  48. package/dist/rules/runtime/index.d.ts +17 -0
  49. package/dist/rules/runtime/index.js +74 -0
  50. package/dist/runner/index.d.ts +16 -0
  51. package/dist/runner/index.js +171 -0
  52. package/dist/runner/lint-text.d.ts +19 -0
  53. package/dist/runner/lint-text.js +20 -0
  54. package/dist/scoring/index.d.ts +16 -0
  55. package/dist/scoring/index.js +41 -0
  56. package/dist/suppressions/index.d.ts +23 -0
  57. package/dist/suppressions/index.js +86 -0
  58. package/dist/web/engine.meta.json +1 -0
  59. package/dist/web/engine.mjs +11018 -0
  60. package/dist/web/index.d.ts +39 -0
  61. package/dist/web/index.js +37 -0
  62. package/dist/web/node-crypto-shim.d.ts +9 -0
  63. package/dist/web/node-crypto-shim.js +24 -0
  64. package/dist/web/sha256.d.ts +11 -0
  65. package/dist/web/sha256.js +89 -0
  66. package/package.json +88 -4
  67. package/rulepack/rulepack.json +1496 -0
  68. package/rules/profiles/academico.yml +4 -0
  69. package/rules/profiles/chat.yml +4 -0
  70. package/rules/profiles/correo.yml +3 -0
  71. package/rules/profiles/general.yml +2 -0
  72. package/rules/profiles/marketing.yml +4 -0
  73. package/rules/profiles/readme.yml +5 -0
  74. package/rules/profiles/redes.yml +6 -0
  75. package/rules/profiles/tecnico.yml +4 -0
  76. package/rules/situaciones.yml +27 -0
  77. package/schemas/rule.schema.json +90 -0
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Seguridad de patrones. Se aplica a toda expresión regular que llegue al Rule Pack:
3
+ * patrones `regex`, términos `re:` de léxicos y excepciones.
4
+ */
5
+ export interface SafetyPolicy {
6
+ forbid_backreferences: boolean;
7
+ forbid_nested_quantifiers: boolean;
8
+ forbid_empty_match: boolean;
9
+ max_pattern_length: number;
10
+ }
11
+ export declare const DEFAULT_SAFETY: SafetyPolicy;
12
+ export declare function checkPattern(source: string, policy?: SafetyPolicy): string[];
13
+ /** Detecta `(…X+…)+`, `(…X*…)*` y variantes {n,m} sobre grupos que ya contienen cuantificadores. */
14
+ export declare function hasNestedQuantifier(source: string): boolean;
15
+ /** Texto adversarial determinista para pruebas de tiempo: repeticiones largas, símbolos y casi-coincidencias. */
16
+ export declare function adversarialText(bytes: number): string;
@@ -0,0 +1,124 @@
1
+ export const DEFAULT_SAFETY = {
2
+ forbid_backreferences: true,
3
+ forbid_nested_quantifiers: true,
4
+ forbid_empty_match: true,
5
+ max_pattern_length: 400,
6
+ };
7
+ export function checkPattern(source, policy = DEFAULT_SAFETY) {
8
+ const errors = [];
9
+ if (source.length === 0)
10
+ return ["patrón vacío"];
11
+ if (source.length > policy.max_pattern_length)
12
+ errors.push(`patrón demasiado largo (${source.length} > ${policy.max_pattern_length})`);
13
+ let re;
14
+ try {
15
+ re = new RegExp(source, "iu");
16
+ }
17
+ catch (e) {
18
+ return [`patrón inválido: ${e.message}`];
19
+ }
20
+ if (policy.forbid_backreferences && /\\[1-9]|\\k<|\(\?[=!<][^)]*\\[1-9]/.test(source))
21
+ errors.push("retroreferencias no permitidas");
22
+ if (/\.\*|\.\+|\[\^[^\]]*\][*+]/.test(source))
23
+ errors.push("patrón no acotado (.*, .+ o clase negada sin límite); usa un cuantificador con máximo, p. ej. {1,60}");
24
+ if (policy.forbid_nested_quantifiers && hasNestedQuantifier(source))
25
+ errors.push("cuantificador anidado sobre un grupo con cuantificador");
26
+ if (/\{\d*,\s*\}/.test(source))
27
+ errors.push("cuantificador {n,} sin máximo");
28
+ if (/\{\d+,(\d+)\}/.test(source)) {
29
+ for (const m of source.matchAll(/\{\d+,(\d+)\}/g)) {
30
+ if (Number(m[1]) > 200)
31
+ errors.push(`cuantificador con máximo demasiado alto ({..,${m[1]}} > 200)`);
32
+ }
33
+ }
34
+ if (policy.forbid_empty_match) {
35
+ if (re.test(""))
36
+ errors.push("el patrón puede coincidir con la cadena vacía");
37
+ }
38
+ return errors;
39
+ }
40
+ /** Detecta `(…X+…)+`, `(…X*…)*` y variantes {n,m} sobre grupos que ya contienen cuantificadores. */
41
+ export function hasNestedQuantifier(source) {
42
+ const stack = [];
43
+ let i = 0;
44
+ let inClass = false;
45
+ let lastWasGroupClose = false;
46
+ while (i < source.length) {
47
+ const c = source[i];
48
+ if (c === "\\") {
49
+ i += 2;
50
+ lastWasGroupClose = false;
51
+ continue;
52
+ }
53
+ if (inClass) {
54
+ if (c === "]")
55
+ inClass = false;
56
+ i++;
57
+ continue;
58
+ }
59
+ if (c === "[") {
60
+ inClass = true;
61
+ i++;
62
+ continue;
63
+ }
64
+ if (c === "(") {
65
+ stack.push({ hasQuant: false });
66
+ i++;
67
+ lastWasGroupClose = false;
68
+ continue;
69
+ }
70
+ if (c === ")") {
71
+ const g = stack.pop();
72
+ lastWasGroupClose = true;
73
+ // El siguiente carácter decide si el grupo se cuantifica.
74
+ const next = source[i + 1];
75
+ const quantified = next === "+" || next === "*" || next === "{" || (next === "?" && g !== undefined && false);
76
+ if (quantified && g?.hasQuant)
77
+ return true;
78
+ if (g?.hasQuant && stack.length)
79
+ stack[stack.length - 1].hasQuant = true;
80
+ if (quantified && stack.length)
81
+ stack[stack.length - 1].hasQuant = true;
82
+ i++;
83
+ continue;
84
+ }
85
+ if (c === "+" || c === "*" || c === "{") {
86
+ // `?` solo (opcional) no se considera peligroso.
87
+ if (stack.length && !lastWasGroupClose)
88
+ stack[stack.length - 1].hasQuant = true;
89
+ if (c === "{") {
90
+ const close = source.indexOf("}", i);
91
+ i = close === -1 ? i + 1 : close + 1;
92
+ lastWasGroupClose = false;
93
+ continue;
94
+ }
95
+ }
96
+ lastWasGroupClose = false;
97
+ i++;
98
+ }
99
+ return false;
100
+ }
101
+ /** Texto adversarial determinista para pruebas de tiempo: repeticiones largas, símbolos y casi-coincidencias. */
102
+ export function adversarialText(bytes) {
103
+ const seeds = [
104
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
105
+ "no no no no no no no no no no no no no no no no no no no no no no no no no no no no no no no no no,",
106
+ "en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en en",
107
+ "es importante es importante es importante es importante es importante es importante es importante",
108
+ "sino sino sino sino sino sino sino sino sino sino sino sino sino sino sino sino sino sino sino sino",
109
+ "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!",
110
+ "—————————————————————————————————————————————————————————————————————————————————————————————————",
111
+ ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,",
112
+ "desde desde desde hasta hasta hasta pasando pasando pasando por por por por por por por por por por",
113
+ "En primer lugar en primer lugar en primer lugar en primer lugar en primer lugar en primer lugar",
114
+ "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀",
115
+ "palabra, palabra, palabra, palabra, palabra, palabra, palabra, palabra, palabra, palabra y palabra",
116
+ ];
117
+ let out = "";
118
+ let i = 0;
119
+ while (out.length < bytes) {
120
+ out += seeds[i % seeds.length] + (i % 7 === 0 ? "\n\n" : " ");
121
+ i++;
122
+ }
123
+ return out;
124
+ }
@@ -0,0 +1,4 @@
1
+ import type { DetectorKind } from "../../contracts/index.js";
2
+ import { type Detector } from "./shared.js";
3
+ export type { RawMatch, Detector } from "./shared.js";
4
+ export declare const DETECTORS: Record<DetectorKind, Detector>;