@@ -25,34 +25,50 @@ For the occasional request, this is the easiest way, but the Worker startup and
2525
2626### Find the words in some text
2727
28- ``` typescript
28+ <!-- - @@inject: ./examples/example-words.js --->
29+
30+ ``` js
2931import { workerMatchAll } from ' regexp-worker' ;
3032// ...
3133const response = await workerMatchAll (' Good Morning' , / \b \w + / g );
3234console .log (response .matches .map ((m ) => m[0 ]));
3335```
3436
37+ <!-- - @@inject-end: ./examples/example-words.js --->
38+
3539Result:
3640
41+ <!-- - @@inject: ./examples/output/example-words.js.out.txt --->
42+
3743```
3844[ 'Good', 'Morning' ]
3945```
4046
47+ <!-- - @@inject-end: ./examples/output/example-words.js.out.txt --->
48+
4149### Find the word breaks in some text
4250
43- ``` ts
51+ <!-- - @@inject: ./examples/example-indexes.js --->
52+
53+ ``` js
4454import { workerMatchAll } from ' regexp-worker' ;
4555
4656const response = await workerMatchAll (' Good Morning' , / \b / g );
4757console .log (response .matches .map ((m ) => m .index ));
4858```
4959
60+ <!-- - @@inject-end: ./examples/example-indexes.js --->
61+
5062Result:
5163
64+ <!-- - @@inject-code: examples/output/example-indexes.js.out.txt --->
65+
5266```
5367[ 0, 4, 5, 12 ]
5468```
5569
70+ <!-- - @@inject-end: examples/output/example-indexes.js.out.txt --->
71+
5672### Format of the response
5773
5874``` ts
@@ -117,3 +133,59 @@ class TimeoutError extends Error {
117133 elapsedTimeMs: number;
118134}
119135```
136+
137+ ## Deno
138+
139+ Deno uses the Web Worker interface instead of ` node:worker_threads ` .
140+ To make things easier, this library has been published to [ jsr.io] ( https://jsr.io/@streetsidesoftware/regexp-worker ) in addition to
141+ adding a deno export to ` package.json ` .
142+
143+ ** Example Using Deno:**
144+
145+ <!-- - @@inject: ./examples/example.deno.ts --->
146+
147+ ```` ts
148+ /**
149+ * @file example.deno.ts
150+ * @description Example of using the `@streetsidesoftware/regexp-worker` package in Deno
151+ * to extract email addresses from a sample text using a Worker.
152+ *
153+ * Install:
154+ * ```sh
155+ * deno add jsr:@streetsidesoftware/regexp-worker
156+ * deno example.deno.ts # run this file.
157+ * ```
158+ */
159+
160+ import { createRegExpWorker } from ' @streetsidesoftware/regexp-worker' ;
161+
162+ const sampleText = `
163+ This is a sample text with some email addresses:
164+ 165+ 166+ ` ;
167+
168+ const regexpEmail = / ([a-zA-Z0-9 . _%+-] + @[a-zA-Z0-9 . -] + \. [a-zA-Z ] {2,} )/ g ;
169+
170+ export async function getEmails(text : string ): Promise <string []> {
171+ await using worker = await createRegExpWorker ();
172+
173+ const result = await worker .matchAll (text , regexpEmail );
174+ return result .matches .map ((match ) => match [0 ]);
175+ }
176+
177+ export async function run() {
178+ const emails = await getEmails (sampleText );
179+ console .log (' Extracted emails:' , emails );
180+ }
181+
182+ if (import .meta .main ) {
183+ run ();
184+ }
185+ ````
186+
187+ <!-- - @@inject-end: ./examples/example.deno.ts --->
188+
189+ ## Bun
190+
191+ Bun does not currently work. It does not fully support ` node:worker_threads ` and the Web Worker API fails to communicate. Further investigation would be needed.
0 commit comments