@gukhanmun/stdict-cdb 0.1.0-dev.15 → 0.1.0-dev.18
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 +6 -3
- package/dist/index.d.ts +13 -2
- package/dist/index.js +19 -5
- package/dist/stdict.cdb +0 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -31,11 +31,14 @@ console.log(g.convert("漢字를 한글로")); // "한자를 한글로"
|
|
|
31
31
|
|
|
32
32
|
`stdictCdb()` returns a `DictionarySource` record (a
|
|
33
33
|
`{ format: "cdb", bytes: Uint8Array }` object). `stdictCdbBytes()` returns only
|
|
34
|
-
the `Uint8Array` when you need the raw bytes
|
|
34
|
+
the `Uint8Array` when you need the raw bytes; pass an explicit `URL` to load a
|
|
35
|
+
relocated copy instead of the bundled one. `stdictCdbUrl` is the URL of the
|
|
35
36
|
binary inside the package, useful for preloading or caching.
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
`stdictCdbBytes()` picks how to load from the URL scheme, not the runtime: a
|
|
39
|
+
`file:` URL (the usual case for an npm install) is read from disk with
|
|
40
|
+
`node:fs/promises`, while any other scheme (such as the `https:` URL of a Deno
|
|
41
|
+
install from JSR) is fetched with `fetch`.
|
|
39
42
|
|
|
40
43
|
|
|
41
44
|
Relation to `@gukhanmun/stdict-fst`
|
package/dist/index.d.ts
CHANGED
|
@@ -58,11 +58,22 @@ declare const stdictCdbUrl: URL;
|
|
|
58
58
|
/**
|
|
59
59
|
* Loads the bundled Standard Korean Language Dictionary as raw bytes.
|
|
60
60
|
*
|
|
61
|
-
*
|
|
61
|
+
* The access strategy is chosen from the URL scheme, not from the host
|
|
62
|
+
* runtime. A `file:` URL is read from disk with `node:fs/promises` (Node.js,
|
|
63
|
+
* Deno, and Bun all provide it, and it is the only option since Node.js's
|
|
64
|
+
* `fetch` rejects `file:` URLs); any other scheme is retrieved with `fetch`.
|
|
62
65
|
*
|
|
66
|
+
* Branching on the scheme is what makes a JSR install work on Deno: there
|
|
67
|
+
* `import.meta.url` (and therefore {@link stdictCdbUrl}) is an `https:` URL,
|
|
68
|
+
* yet Deno also exposes `process.versions.node`, so a runtime sniff would
|
|
69
|
+
* wrongly take the `node:fs` path and `readFile` would reject the `https:`
|
|
70
|
+
* URL with "The URL must be of scheme file".
|
|
71
|
+
*
|
|
72
|
+
* @param url Location of the CDB binary to read. Defaults to the bundled
|
|
73
|
+
* {@link stdictCdbUrl}; pass another URL to load a relocated copy.
|
|
63
74
|
* @returns The CDB binary as a `Uint8Array`.
|
|
64
75
|
*/
|
|
65
|
-
declare function stdictCdbBytes(): Promise<Uint8Array<ArrayBuffer>>;
|
|
76
|
+
declare function stdictCdbBytes(url?: URL): Promise<Uint8Array<ArrayBuffer>>;
|
|
66
77
|
/**
|
|
67
78
|
* Loads the bundled Standard Korean Language Dictionary as a
|
|
68
79
|
* {@link FileDictionarySource} ready to pass to `load({ dictionaries: [...] })`.
|
package/dist/index.js
CHANGED
|
@@ -4,16 +4,30 @@ const stdictCdbUrl = new URL("./stdict.cdb", import.meta.url);
|
|
|
4
4
|
/**
|
|
5
5
|
* Loads the bundled Standard Korean Language Dictionary as raw bytes.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* The access strategy is chosen from the URL scheme, not from the host
|
|
8
|
+
* runtime. A `file:` URL is read from disk with `node:fs/promises` (Node.js,
|
|
9
|
+
* Deno, and Bun all provide it, and it is the only option since Node.js's
|
|
10
|
+
* `fetch` rejects `file:` URLs); any other scheme is retrieved with `fetch`.
|
|
8
11
|
*
|
|
12
|
+
* Branching on the scheme is what makes a JSR install work on Deno: there
|
|
13
|
+
* `import.meta.url` (and therefore {@link stdictCdbUrl}) is an `https:` URL,
|
|
14
|
+
* yet Deno also exposes `process.versions.node`, so a runtime sniff would
|
|
15
|
+
* wrongly take the `node:fs` path and `readFile` would reject the `https:`
|
|
16
|
+
* URL with "The URL must be of scheme file".
|
|
17
|
+
*
|
|
18
|
+
* @param url Location of the CDB binary to read. Defaults to the bundled
|
|
19
|
+
* {@link stdictCdbUrl}; pass another URL to load a relocated copy.
|
|
9
20
|
* @returns The CDB binary as a `Uint8Array`.
|
|
10
21
|
*/
|
|
11
|
-
async function stdictCdbBytes() {
|
|
12
|
-
if (
|
|
13
|
-
const buf = await (await import(
|
|
22
|
+
async function stdictCdbBytes(url = stdictCdbUrl) {
|
|
23
|
+
if (url.protocol === "file:") {
|
|
24
|
+
const buf = await (await import(
|
|
25
|
+
/* webpackIgnore: true */
|
|
26
|
+
"node:fs/promises"
|
|
27
|
+
)).readFile(url);
|
|
14
28
|
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
15
29
|
}
|
|
16
|
-
const response = await fetch(
|
|
30
|
+
const response = await fetch(url);
|
|
17
31
|
if (!response.ok) throw new Error(`Failed to fetch stdict CDB: HTTP ${response.status}`);
|
|
18
32
|
return new Uint8Array(await response.arrayBuffer());
|
|
19
33
|
}
|
package/dist/stdict.cdb
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gukhanmun/stdict-cdb",
|
|
3
|
-
"version": "0.1.0-dev.
|
|
3
|
+
"version": "0.1.0-dev.18",
|
|
4
4
|
"description": "Standard Korean Language Dictionary bundled as a CDB binary for @gukhanmun/wasm and @gukhanmun/napi.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@gukhanmun/types": "*"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@gukhanmun/types": "0.1.0-dev.
|
|
49
|
+
"@gukhanmun/types": "0.1.0-dev.18+25611433dc656544ad355f3b96f45650c351cab9"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
52
|
"build": "tsdown && node -e \"require('node:fs').copyFileSync('stdict.cdb','dist/stdict.cdb')\""
|