disarm 0.15.0 → 0.17.0

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/README.md CHANGED
@@ -10,7 +10,7 @@ prebuilt native addons install with no Rust toolchain.
10
10
  npm install disarm
11
11
  ```
12
12
 
13
- Ships TypeScript types (`.d.ts`) — no `@types/disarm` needed. Requires Node 14+.
13
+ Ships TypeScript types (`.d.ts`) — no `@types/disarm` needed. Requires Node 22+.
14
14
 
15
15
  ## Quick start
16
16
 
package/binding.d.ts CHANGED
@@ -1,5 +1,14 @@
1
1
  /* auto-generated by NAPI-RS */
2
2
  /* eslint-disable */
3
+
4
+ /**
5
+ * Which binding artifact the generated loader actually loaded: `'native'` for
6
+ * a native addon, otherwise the `platformArchABI` of the WASI flavor. Every
7
+ * flavor napi-rs can build is listed, because `NAPI_RS_NATIVE_LIBRARY_PATH`
8
+ * can point the loader at a WASI artifact this package does not build itself.
9
+ */
10
+ export declare const __napiBindingTarget: 'native' | 'wasm32-wasi' | 'wasm32-wasip1'
11
+
3
12
  /**
4
13
  * A reusable, opaque lexicon handle (HAI-SDLC 6.1).
5
14
  *
@@ -27,6 +36,17 @@ export declare class Lexicon {
27
36
  export declare class Pipeline {
28
37
  /** Run the named pipeline over `text`, returning the cleaned string. */
29
38
  process(text: string): string
39
+ /**
40
+ * What the named profile this was built from is for, in one sentence (#860).
41
+ * `null` for a pipeline not built from a profile.
42
+ */
43
+ get purpose(): string | null
44
+ /**
45
+ * A copy of this pipeline whose confusable passes fold under `digitPolicy` (#646).
46
+ * Throws when the profile has no confusables step and the policy is not the default:
47
+ * a setting that would never run is refused rather than kept.
48
+ */
49
+ withDigitPolicy(digitPolicy: string): Pipeline
30
50
  }
31
51
 
32
52
  /**
@@ -71,7 +91,7 @@ export interface AutoLangInspection {
71
91
  * WHEN the word also carries an ASCII letter, which is the gate that keeps ordinary
72
92
  * non-Latin text from firing; a delimiter-only string is not reported.
73
93
  */
74
- export declare function canonicalize(text: string): string
94
+ export declare function canonicalize(text: string, digitPolicy: string): string
75
95
 
76
96
  /**
77
97
  * Strip the non-interchange and invisible classes while KEEPING the script (#698).
@@ -88,20 +108,42 @@ export declare function canonicalize(text: string): string
88
108
  * — the point of the preset.
89
109
  * Canonicalize, but fail rather than silently normalize a structural difference away.
90
110
  */
91
- export declare function canonicalizeStrict(text: string): string
111
+ export declare function canonicalizeStrict(text: string, digitPolicy: string): string
92
112
 
93
113
  /**
94
114
  * Library catalog deduplication key (like `searchKey` plus confusable folding).
95
115
  * `lang` selects the transliteration table; `strict_iso9` picks the ISO 9:1995
96
116
  * Cyrillic scheme.
97
117
  */
98
- export declare function catalogKey(text: string, lang: string | undefined | null, strictIso9: boolean): string
118
+ export declare function catalogKey(text: string, lang: string | undefined | null, strictIso9: boolean, digitPolicy: string): string
99
119
 
100
120
  export declare function collapseWhitespace(text: string): string
101
121
 
122
+ /**
123
+ * TR39 sources whose prototype is in `script`, and how many the bundled tables fold
124
+ * (#963). The denominator `unmappedConfusables` does not have: it measures one table
125
+ * against the whole source population, so a script disarm ships no table for reports a
126
+ * number determined by that absence. An unknown name raises a
127
+ * `DisarmInvalidArgument`-tagged error.
128
+ */
129
+ export declare function confusableCoverage(script: string): ConfusableCoverage
130
+
131
+ /** Per-script confusable coverage — the fair denominator (#963). */
132
+ export interface ConfusableCoverage {
133
+ /** The script the figures are about, in disarm's spelling. */
134
+ script: string
135
+ /** TR39 sources whose prototype is in this script. */
136
+ sources: number
137
+ /** How many of those `sources` a bundled fold table reaches. */
138
+ folded: number
139
+ }
140
+
102
141
  export declare function confusablesVersion(): string
103
142
 
104
- /** Replace emoji with their plain names; `strip_modifiers` drops skin-tone marks. */
143
+ /**
144
+ * Replace emoji with their plain names; `strip_modifiers` drops skin-tone marks. An
145
+ * emoji CLDR cannot name becomes `[?]`, as in every binding.
146
+ */
105
147
  export declare function demojize(text: string, stripModifiers: boolean): string
106
148
 
107
149
  /**
@@ -110,6 +152,9 @@ export declare function demojize(text: string, stripModifiers: boolean): string
110
152
  */
111
153
  export declare function detectScripts(text: string): Array<string>
112
154
 
155
+ /** Levenshtein edit distance between `a` and `b`, in characters (#894). */
156
+ export declare function editDistance(a: string, b: string): number
157
+
113
158
  /** One reason a token is anomalous (a single finding). */
114
159
  export interface Finding {
115
160
  /** Which branch fired: `"invisible"` | `"bidi"` | `"zalgo"` | `"mixed_script"` | `"bidi_mixed"` | `"leet"` | `"segmentation"`. */
@@ -256,6 +301,9 @@ export declare function inspectAnomalies(text: string, lexicon: Array<string> |
256
301
  /** Explain how auto-language detection resolves `text`. */
257
302
  export declare function inspectAutoLang(text: string): AutoLangInspection
258
303
 
304
+ /** Whether `text` is already its own canonical form under `preset` (#730). */
305
+ export declare function isCanonical(text: string, preset: string): boolean
306
+
259
307
  /**
260
308
  * Whether case folding and simple lowercasing agree, so the value is a stable
261
309
  * identity key (#619).
@@ -279,7 +327,11 @@ export declare function isNormalized(text: string, form: string): boolean
279
327
  */
280
328
  export declare function isSuspiciousHostname(host: string): boolean
281
329
 
282
- export declare function isZalgo(text: string, threshold: number): boolean
330
+ /**
331
+ * Whether any base carries more than `threshold` marks; omitted, the core's default
332
+ * (`api::DEFAULT_ZALGO_THRESHOLD`, 3).
333
+ */
334
+ export declare function isZalgo(text: string, threshold?: number | undefined | null): boolean
283
335
 
284
336
  /** One group of distinct inputs that reduce to the same key (#620). */
285
337
  export interface KeyCollision {
@@ -327,8 +379,9 @@ export declare function listContextLangs(): Array<string>
327
379
  export declare function listScripts(): Array<string>
328
380
 
329
381
  /**
330
- * ML/NLP normalization: NFKC → emoji→text → transliterate → strip accents →
331
- * [case fold] → strip control → strip zero-width → collapse whitespace.
382
+ * ML/NLP normalization: resolve deletions → NFKC → emoji→text → transliterate →
383
+ * strip accents → emoji→text → [case fold] → strip control → strip zero-width →
384
+ * collapse whitespace → NFC.
332
385
  *
333
386
  * `fold_case` defaults to `true`. Pass `false` in front of a CASED model: the fold is
334
387
  * destructive, cannot be undone downstream, and an uncased evaluation harness cannot
@@ -336,12 +389,34 @@ export declare function listScripts(): Array<string>
336
389
  */
337
390
  export declare function mlNormalize(text: string, lang: string | undefined | null, emojiStyle: string, foldCase: boolean): string
338
391
 
392
+ /**
393
+ * The candidate closest to `value`, with its distance, or `null` beyond `max_distance`
394
+ * (#894). An exact match is reported with distance 0; ties go to the first candidate at
395
+ * the lowest distance.
396
+ */
397
+ export declare function nearestMatch(value: string, candidates: Array<string>, maxDistance: number): NearestMatch | null
398
+
399
+ /** A candidate and how far `nearestMatch` found it from the value asked about (#894). */
400
+ export interface NearestMatch {
401
+ /** The candidate, in the spelling the caller supplied. */
402
+ value: string
403
+ /** Its edit distance from the value asked about; `0` means the value *is* this candidate. */
404
+ distance: number
405
+ }
406
+
339
407
  /** Apply a normalization form: `"NFC"` | `"NFD"` | `"NFKC"` | `"NFKD"`. */
340
408
  export declare function normalize(text: string, form: string): string
341
409
 
342
410
  /** Fold cross-script confusables toward `target` (`"latin"` | `"cyrillic"` | `"arabic"` | `"hebrew"`). */
343
411
  export declare function normalizeConfusables(text: string, target: string, digitPolicy: string): string
344
412
 
413
+ /**
414
+ * Replace every emoji with `replacement`, verbatim (#972). The counterpart to
415
+ * `demojize`: that names an emoji from the CLDR table, which is wider than the emoji
416
+ * set, and this replaces what the UCD calls an emoji and nothing else.
417
+ */
418
+ export declare function replaceEmoji(text: string, replacement: string): string
419
+
345
420
  /** Reverse-transliterate Latin → native script. `lang` is `"el"` | `"ru"` | `"uk"`. */
346
421
  export declare function reverseTransliterate(text: string, lang: string): string
347
422
 
@@ -352,8 +427,12 @@ export declare function reverseTransliterate(text: string, lang: string): string
352
427
  * A safe **filename**, not a safe URL path segment. `%` is legal in a filename, so one
353
428
  * the caller typed is kept — `sanitizeFilename("..%2Fetc")` returns `"%2Fetc"` — and a
354
429
  * consumer that percent-decodes the result must validate *after* decoding. What this
355
- * will not do is manufacture one: `%` never appears in the output unless it appeared in
356
- * the input (#721).
430
+ * will not do is manufacture one: every `%` in the output is one the input contained, or
431
+ * part of the separator (#721).
432
+ *
433
+ * `separator` must be printable, non-space ASCII with no character illegal on
434
+ * `platform` and no path separator (`/`, `\`); anything else throws
435
+ * `DisarmInvalidArgument`. `""` is allowed.
357
436
  */
358
437
  export declare function sanitizeFilename(text: string, separator: string, maxLength: number, platform: string, lang: string | undefined | null, preserveExtension: boolean): string
359
438
 
@@ -379,7 +458,15 @@ export interface ScriptMeta {
379
458
  * Case/accent/script-insensitive search lookup key. `lang` selects the
380
459
  * transliteration table (omit for none).
381
460
  */
382
- export declare function searchKey(text: string, lang?: string | undefined | null): string
461
+ export declare function searchKey(text: string, lang: string | undefined | null, digitPolicy: string): string
462
+
463
+ /**
464
+ * The TR39 identifier skeleton plus the two prototype classes disarm's table keeps apart
465
+ * (#650). A spoof key: its only job is to make confusable identifiers collide, and its
466
+ * output is never for display. `digit_policy` is `"numeric"` (the letter half only),
467
+ * `"tr39"` (adds `1 ≡ l` and `0 ≡ O`) or `"preserve"`.
468
+ */
469
+ export declare function skeletonKey(text: string, digitPolicy: string): string
383
470
 
384
471
  /** Generate a URL-safe slug. */
385
472
  export declare function slugify(text: string, opts: SlugOptions): string
@@ -404,7 +491,7 @@ export interface SlugOptions {
404
491
  * Collation sort key (like `searchKey` but preserves base accented characters
405
492
  * for correct ordering). `lang` selects the transliteration table.
406
493
  */
407
- export declare function sortKey(text: string, lang?: string | undefined | null): string
494
+ export declare function sortKey(text: string, lang: string | undefined | null, digitPolicy: string): string
408
495
 
409
496
  export declare function stripAccents(text: string): string
410
497
 
@@ -417,7 +504,7 @@ export declare function stripFormat(text: string): string
417
504
  /** Strip every Unicode noncharacter (#413). */
418
505
  export declare function stripNoncharacters(text: string): string
419
506
 
420
- export declare function stripObfuscation(text: string): string
507
+ export declare function stripObfuscation(text: string, digitPolicy: string): string
421
508
 
422
509
  /** Strip every Private Use Area code point (#413). */
423
510
  export declare function stripPua(text: string): string
@@ -428,7 +515,11 @@ export declare function stripTags(text: string): string
428
515
  /** Strip every variation selector (VS1–VS256) (#413). */
429
516
  export declare function stripVariationSelectors(text: string): string
430
517
 
431
- export declare function stripZalgo(text: string, maxMarks: number): string
518
+ /**
519
+ * Cap combining marks per base at `max_marks`; omitted, the core's default
520
+ * (`api::DEFAULT_ZALGO_MAX_MARKS`, 3), so this binding never restates it (B1).
521
+ */
522
+ export declare function stripZalgo(text: string, maxMarks?: number | undefined | null): string
432
523
 
433
524
  export declare function stripZeroWidthChars(text: string): string
434
525
 
@@ -439,7 +530,8 @@ export declare function transliterate(text: string): string
439
530
 
440
531
  /**
441
532
  * Transliterate with a scheme (`"default"` | `"strict_iso9"` | `"gost7034"`)
442
- * and/or a language profile (`lang`), via the core's builder.
533
+ * and/or a language profile (`lang`), via the core's builder. An unknown `lang`
534
+ * throws `DisarmInvalidArgument`, as the key builders' always has.
443
535
  */
444
536
  export declare function transliterateOpts(text: string, scheme: string, lang?: string | undefined | null): string
445
537