rregex 1.13.2 → 2.0.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
@@ -8,6 +8,7 @@ A dependency-free WebAssembly build of [Rust Regex](https://docs.rs/regex/latest
8
8
  - [Why Rust Regex](#why-rust-regex)
9
9
  - [Install](#install)
10
10
  - [Supported Runtimes](#supported-runtimes)
11
+ - [Options](#options)
11
12
  - [API](https://tsdocs.dev/docs/rregex/latest)
12
13
  - [`RRegex`](https://tsdocs.dev/docs/rregex/latest/classes/RRegex.html)
13
14
  - [`RRegexSet`](https://tsdocs.dev/docs/rregex/latest/classes/RRegexSet.html)
@@ -52,9 +53,49 @@ This package includes builds for multiple runtimes
52
53
  | Node.js (commonjs) | `const { RRegex, RRegexSet } = require('rregex')` | `*` |
53
54
  | Deno | `import { RRegex, RRegexSet } from '@rregex/rregex'` | `>=1.10.8` |
54
55
  | Bun | `import { RRegex, RRegexSet } from '@rregex/rregex'` | `>=1.10.8` |
55
- | Cloudflare Workers | `import { RRegex, RRegexSet } from 'rregex/lib/cf.mjs'` | `>=1.10.8` |
56
- | Browser | TODO | |
57
- | Standalone | TODO | |
56
+ | Cloudflare Workers | `import { RRegex, RRegexSet } from 'rregex'` | `>=1.10.8` |
57
+ | Browser | `import init, { RRegex } from 'rregex/web'` | `*` |
58
+ | Standalone | `<script src=".../rregex/lib/standalone.js">` | `*` |
59
+ | Any runtime | `import { initSync, RRegex } from 'rregex/core'` | `*` |
60
+
61
+ The Node.js, Deno, Bun and Cloudflare Workers builds load the WebAssembly module
62
+ when you import them. The other builds do not: call `init()` or `initSync()`
63
+ once before you use `RRegex` or `RRegexSet`.
64
+
65
+ ```ts
66
+ // Browser: fetches `rregex.wasm` from the same directory as `web.js`
67
+ import init, { RRegex } from "rregex/web";
68
+ await init();
69
+
70
+ // Standalone: exposes the global `rregex`
71
+ await rregex.init();
72
+ new rregex.RRegex("a+").isMatch("aaa");
73
+
74
+ // Any runtime: you provide the module (bytes, `WebAssembly.Module` or a `Response`)
75
+ import { init, initSync, RRegex } from "rregex/core";
76
+ initSync({ module: wasmBytes });
77
+ await init({ module_or_path: fetch(wasmUrl) });
78
+ ```
79
+
80
+ ## Options
81
+
82
+ `RRegex` and `RRegexSet` accept an optional second argument. The options only
83
+ apply to that instance.
84
+
85
+ | Option | Default | Description |
86
+ | -------------- | ------- | ------------------------------------------------------------------------------------- |
87
+ | `sizeLimit` | 10 MiB | Size limit of the compiled regex. If the regex is bigger, the constructor throws. |
88
+ | `dfaSizeLimit` | 2 MiB | Cache size of the lazy DFA. A bigger cache can make searches on big patterns faster. |
89
+ | `nestLimit` | 250 | Nesting limit of the parser. If the pattern is nested deeper, the constructor throws. |
90
+
91
+ ```ts
92
+ // Unicode classes make this pattern exceed the default 10 MiB size limit
93
+ new RRegex("\\w{200}\\s\\w{200}\\s\\w{200}"); // throws: Compiled regex exceeds size limit
94
+ new RRegex("\\w{200}\\s\\w{200}\\s\\w{200}", { sizeLimit: 200 * 1024 * 1024 }); // ok
95
+ ```
96
+
97
+ The compiled regex uses WebAssembly memory, which does not shrink after the
98
+ instance is freed. Increase the limits only for the patterns that need them.
58
99
 
59
100
  ## Benchmarks
60
101