@gukhanmun/stdict-cdb 0.4.0-dev.245 → 0.4.0-dev.248
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/dist/index.d.ts +14 -5
- package/dist/index.js +22 -7
- package/dist/stdict.cdb +0 -0
- package/dist/stdict.cdb.gz +0 -0
- package/package.json +5 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import { FileDictionarySource, FileDictionarySource as FileDictionarySource$1 } from "@gukhanmun/types";
|
|
2
|
-
/**
|
|
1
|
+
import { FileDictionarySource, FileDictionarySource as FileDictionarySource$1, SourceRole } from "@gukhanmun/types";
|
|
2
|
+
/**
|
|
3
|
+
* URL of the bundled, gzip-compressed Standard Korean Language Dictionary CDB.
|
|
4
|
+
*
|
|
5
|
+
* The URL now points to `stdict.cdb.gz` to fit registry per-file limits.
|
|
6
|
+
* {@link stdictCdbBytes} transparently returns the decompressed CDB bytes.
|
|
7
|
+
* The npm package also retains its raw `stdict.cdb` file export.
|
|
8
|
+
*/
|
|
3
9
|
export declare const stdictCdbUrl: URL;
|
|
4
10
|
/**
|
|
5
11
|
* Loads the bundled Standard Korean Language Dictionary as raw bytes.
|
|
@@ -15,7 +21,10 @@ export declare const stdictCdbUrl: URL;
|
|
|
15
21
|
* wrongly take the `node:fs` path and `readFile` would reject the `https:`
|
|
16
22
|
* URL with "The URL must be of scheme file".
|
|
17
23
|
*
|
|
18
|
-
*
|
|
24
|
+
* Gzip is detected from the payload's magic bytes, so compressed files are
|
|
25
|
+
* inflated transparently and relocated raw CDB files remain supported.
|
|
26
|
+
*
|
|
27
|
+
* @param url Location of the raw or gzip-compressed CDB to read. Defaults to the bundled
|
|
19
28
|
* {@link stdictCdbUrl}; pass another URL to load a relocated copy.
|
|
20
29
|
* @returns The CDB binary as a `Uint8Array`.
|
|
21
30
|
*/
|
|
@@ -24,7 +33,7 @@ export declare function stdictCdbBytes(url?: URL): Promise<Uint8Array<ArrayBuffe
|
|
|
24
33
|
* Loads the bundled Standard Korean Language Dictionary as a
|
|
25
34
|
* {@link FileDictionarySource} ready to pass to `load({ dictionaries: [...] })`.
|
|
26
35
|
*
|
|
27
|
-
* @returns A `FileDictionarySource` with `format: "cdb"`.
|
|
36
|
+
* @returns A `FileDictionarySource` with `format: "cdb"` and `role: "reference"`.
|
|
28
37
|
*/
|
|
29
38
|
export declare function stdictCdb(): Promise<FileDictionarySource$1>;
|
|
30
|
-
export type { FileDictionarySource };
|
|
39
|
+
export type { FileDictionarySource, SourceRole };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
// index.ts
|
|
2
|
-
/**
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* URL of the bundled, gzip-compressed Standard Korean Language Dictionary CDB.
|
|
4
|
+
*
|
|
5
|
+
* The URL now points to `stdict.cdb.gz` to fit registry per-file limits.
|
|
6
|
+
* {@link stdictCdbBytes} transparently returns the decompressed CDB bytes.
|
|
7
|
+
* The npm package also retains its raw `stdict.cdb` file export.
|
|
8
|
+
*/
|
|
9
|
+
const stdictCdbUrl = new URL("./stdict.cdb.gz", import.meta.url);
|
|
4
10
|
/**
|
|
5
11
|
* Loads the bundled Standard Korean Language Dictionary as raw bytes.
|
|
6
12
|
*
|
|
@@ -15,7 +21,10 @@ const stdictCdbUrl = new URL("./stdict.cdb", import.meta.url);
|
|
|
15
21
|
* wrongly take the `node:fs` path and `readFile` would reject the `https:`
|
|
16
22
|
* URL with "The URL must be of scheme file".
|
|
17
23
|
*
|
|
18
|
-
*
|
|
24
|
+
* Gzip is detected from the payload's magic bytes, so compressed files are
|
|
25
|
+
* inflated transparently and relocated raw CDB files remain supported.
|
|
26
|
+
*
|
|
27
|
+
* @param url Location of the raw or gzip-compressed CDB to read. Defaults to the bundled
|
|
19
28
|
* {@link stdictCdbUrl}; pass another URL to load a relocated copy.
|
|
20
29
|
* @returns The CDB binary as a `Uint8Array`.
|
|
21
30
|
*/
|
|
@@ -25,22 +34,28 @@ async function stdictCdbBytes(url = stdictCdbUrl) {
|
|
|
25
34
|
/* webpackIgnore: true */
|
|
26
35
|
"node:fs/promises"
|
|
27
36
|
)).readFile(url);
|
|
28
|
-
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
37
|
+
return inflateIfGzip(new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength));
|
|
29
38
|
}
|
|
30
39
|
const response = await fetch(url);
|
|
31
40
|
if (!response.ok) throw new Error(`Failed to fetch stdict CDB: HTTP ${response.status}`);
|
|
32
|
-
return new Uint8Array(await response.arrayBuffer());
|
|
41
|
+
return inflateIfGzip(new Uint8Array(await response.arrayBuffer()));
|
|
42
|
+
}
|
|
43
|
+
async function inflateIfGzip(bytes) {
|
|
44
|
+
if (bytes.length < 2 || bytes[0] !== 31 || bytes[1] !== 139) return bytes;
|
|
45
|
+
const stream = new Blob([bytes]).stream().pipeThrough(new DecompressionStream("gzip"));
|
|
46
|
+
return new Uint8Array(await new Response(stream).arrayBuffer());
|
|
33
47
|
}
|
|
34
48
|
/**
|
|
35
49
|
* Loads the bundled Standard Korean Language Dictionary as a
|
|
36
50
|
* {@link FileDictionarySource} ready to pass to `load({ dictionaries: [...] })`.
|
|
37
51
|
*
|
|
38
|
-
* @returns A `FileDictionarySource` with `format: "cdb"`.
|
|
52
|
+
* @returns A `FileDictionarySource` with `format: "cdb"` and `role: "reference"`.
|
|
39
53
|
*/
|
|
40
54
|
async function stdictCdb() {
|
|
41
55
|
return {
|
|
42
56
|
data: await stdictCdbBytes(),
|
|
43
|
-
format: "cdb"
|
|
57
|
+
format: "cdb",
|
|
58
|
+
role: "reference"
|
|
44
59
|
};
|
|
45
60
|
}
|
|
46
61
|
export { stdictCdb, stdictCdbBytes, stdictCdbUrl };
|
package/dist/stdict.cdb
CHANGED
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gukhanmun/stdict-cdb",
|
|
3
|
-
"version": "0.4.0-dev.
|
|
3
|
+
"version": "0.4.0-dev.248",
|
|
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": {
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"import": "./dist/index.js",
|
|
10
10
|
"default": "./dist/index.js"
|
|
11
11
|
},
|
|
12
|
-
"./stdict.cdb": "./dist/stdict.cdb"
|
|
12
|
+
"./stdict.cdb": "./dist/stdict.cdb",
|
|
13
|
+
"./stdict.cdb.gz": "./dist/stdict.cdb.gz"
|
|
13
14
|
},
|
|
14
15
|
"files": [
|
|
15
16
|
"dist"
|
|
@@ -55,9 +56,9 @@
|
|
|
55
56
|
"@gukhanmun/types": "*"
|
|
56
57
|
},
|
|
57
58
|
"devDependencies": {
|
|
58
|
-
"@gukhanmun/types": "0.4.0-dev.
|
|
59
|
+
"@gukhanmun/types": "0.4.0-dev.248+36997e7"
|
|
59
60
|
},
|
|
60
61
|
"scripts": {
|
|
61
|
-
"build": "tsdown && node -e \"require('node:fs')
|
|
62
|
+
"build": "tsdown && node -e \"const fs=require('node:fs');for(const f of ['stdict.cdb','stdict.cdb.gz'])fs.copyFileSync(f,'dist/'+f)\""
|
|
62
63
|
}
|
|
63
64
|
}
|