Skip to content

Commit c23cca2

Browse files
fix: Add deno to the package.json export conditions. (#1004)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent a4704fa commit c23cca2

File tree

9 files changed

+1189
-19
lines changed

9 files changed

+1189
-19
lines changed

.github/workflows/autofix.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ jobs:
2727
- name: Build
2828
run: pnpm run build
2929

30+
- name: Build Readme
31+
run: pnpm run build:readme
32+
3033
- name: Fix Lint
3134
run: |
3235
pnpm run lint:fix

README.md

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
2931
import { workerMatchAll } from 'regexp-worker';
3032
//...
3133
const response = await workerMatchAll('Good Morning', /\b\w+/g);
3234
console.log(response.matches.map((m) => m[0]));
3335
```
3436

37+
<!--- @@inject-end: ./examples/example-words.js --->
38+
3539
Result:
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
4454
import { workerMatchAll } from 'regexp-worker';
4555

4656
const response = await workerMatchAll('Good Morning', /\b/g);
4757
console.log(response.matches.map((m) => m.index));
4858
```
4959

60+
<!--- @@inject-end: ./examples/example-indexes.js --->
61+
5062
Result:
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.

examples/example-words.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import { workerMatchAll } from 'regexp-worker';
2-
2+
//...
33
const response = await workerMatchAll('Good Morning', /\b\w+/g);
44
console.log(response.matches.map((m) => m[0]));

examples/example.deno.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* @file example.deno.ts
3+
* @description Example of using the `@streetsidesoftware/regexp-worker` package in Deno
4+
* to extract email addresses from a sample text using a Worker.
5+
*
6+
* Install:
7+
* ```sh
8+
* deno add jsr:@streetsidesoftware/regexp-worker
9+
* deno example.deno.ts # run this file.
10+
* ```
11+
*/
12+
13+
import { createRegExpWorker } from '@streetsidesoftware/regexp-worker';
14+
15+
const sampleText = `
16+
This is a sample text with some email addresses:
17+
18+
19+
`;
20+
21+
const regexpEmail = /([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})/g;
22+
23+
export async function getEmails(text: string): Promise<string[]> {
24+
await using worker = await createRegExpWorker();
25+
26+
const result = await worker.matchAll(text, regexpEmail);
27+
return result.matches.map((match) => match[0]);
28+
}
29+
30+
export async function run() {
31+
const emails = await getEmails(sampleText);
32+
console.log('Extracted emails:', emails);
33+
}
34+
35+
if (import.meta.main) {
36+
run();
37+
}

examples/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
},
1010
"license": "MIT",
1111
"dependencies": {
12+
"@streetsidesoftware/regexp-worker": "jsr:^4.1.6",
1213
"regexp-worker": "workspace:*"
1314
}
1415
}

jsr.json

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,7 @@
88
"./node": "./src/index.mts"
99
},
1010
"publish": {
11-
"include": [
12-
"LICENSE",
13-
"README.md",
14-
"src"
15-
],
16-
"exclude": [
17-
"**/*.test.ts",
18-
"**/*.test.mts"
19-
]
11+
"include": ["LICENSE", "README.md", "src"],
12+
"exclude": ["**/*.test.ts", "**/*.test.mts"]
2013
}
2114
}

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"lint:fix": "pnpm run lint:fix:eslint && pnpm run lint:fix:prettier",
1818
"lint:fix:eslint": "eslint . --fix",
1919
"lint:fix:prettier": "prettier --write .",
20+
"build:readme": "inject-markdown README.md",
2021
"build": "pnpm run build:worker && pnpm run build:code",
2122
"build:worker": "tsdown -c worker.tsdown.config.ts && node scripts/build-worker.js",
2223
"build:code": "pnpm run compile && tsdown -c tsdown.config.ts",
@@ -36,6 +37,7 @@
3637
"exports": {
3738
".": {
3839
"browser": "./dist/browser.js",
40+
"deno": "./dist/browser.js",
3941
"import": "./dist/index.js",
4042
"require": "./dist/index.cjs"
4143
}
@@ -77,6 +79,7 @@
7779
"eslint": "^9.30.0",
7880
"eslint-plugin-simple-import-sort": "^12.1.1",
7981
"globals": "^16.2.0",
82+
"inject-markdown": "^3.1.4",
8083
"lorem-ipsum": "^2.0.8",
8184
"prettier": "^3.6.2",
8285
"shx": "^0.4.0",

0 commit comments

Comments
 (0)