lingotweaker-data 0.0.1 → 0.2.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
@@ -1,5 +1,53 @@
1
- # lingotweaker-data
1
+ # LingoTweaker data
2
2
 
3
- Placeholder release. The real package ships one gzipped data pack per language
4
- for the LingoTweaker proofreading engine. See
5
- https://github.com/fiduswriter/LingoTweaker
3
+ Runtime data for the LingoTweaker proofreading engine. This package is the
4
+ **code-only loader**: the actual language packs ship in one small package per
5
+ language (`lingotweaker-data-<lang>`, mirroring the per-language PyPI data
6
+ distributions), so npm never has to carry a single multi-language tarball.
7
+ Install the loader plus the languages you need:
8
+
9
+ ```sh
10
+ npm install lingotweaker-data lingotweaker-data-en
11
+ ```
12
+
13
+ ```js
14
+ const data = require("lingotweaker-data");
15
+ const { Engine } = require("lingotweaker");
16
+
17
+ const engine = new Engine("en-US", { dataDir: data.packPath("en") });
18
+ for (const match of engine.check("I can heard you.").matches) {
19
+ console.log(match.rule_id, match.suggestions);
20
+ }
21
+ ```
22
+
23
+ ```js
24
+ import init, { LtEngine } from "lingotweaker-wasm";
25
+ import { packPath } from "lingotweaker-data";
26
+ import { readFileSync } from "node:fs";
27
+
28
+ await init();
29
+ const pack = readFileSync(packPath("en"));
30
+ const engine = new LtEngine("en-US", pack, JSON.stringify({ today: new Date().toISOString() }));
31
+ ```
32
+
33
+ - `packPath(lang)` — absolute path of a language pack, resolved from the
34
+ installed `lingotweaker-data-<lang>` package (which must be installed
35
+ separately; resolution starts next to this package and falls back to the
36
+ process working directory for pnpm/workspace layouts)
37
+ - `languages()` — the base codes with a published pack
38
+ - `dataManifest()` — version, upstream commit and per-language `bytes`/`sha256`;
39
+ the `file` paths are relative to the per-language package
40
+
41
+ The packs are the same artifacts attached to each GitHub Release
42
+ (`packs/<lang>.pack.gz`) and used by the browser demo, so all channels serve
43
+ identical data.
44
+
45
+ Note for layouts where package resolution cannot reach the per-language
46
+ packages from inside this one (strict pnpm), declare
47
+ `lingotweaker-data-<lang>` as a dependency of the consuming package so the
48
+ package manager links it.
49
+
50
+ Vendored rule data, dictionaries and models keep their upstream licenses; see
51
+ `THIRD_PARTY_NOTICES.md` in the repository.
52
+
53
+ License (packaging code): LGPL-2.1-or-later.
package/index.d.ts ADDED
@@ -0,0 +1,40 @@
1
+ /** Loader for the LingoTweaker engine's runtime data (code-only package). */
2
+
3
+ export interface DataFileEntry {
4
+ /**
5
+ * Path relative to the per-language package `lingotweaker-data-<lang>`
6
+ * (e.g. `packs/en.pack.gz`), not to this package.
7
+ */
8
+ file: string;
9
+ bytes: number;
10
+ sha256: string;
11
+ }
12
+
13
+ export interface DataLanguageEntry {
14
+ pack: DataFileEntry;
15
+ }
16
+
17
+ export interface LingoTweakerDataManifest {
18
+ version: string;
19
+ upstream_commit: string;
20
+ languages: Record<string, DataLanguageEntry>;
21
+ }
22
+
23
+ /** Languages with a published data pack (base codes: `en`, `de`, `gn`, …). */
24
+ export function languages(): string[];
25
+
26
+ /**
27
+ * Absolute path of the gzipped data pack for `lang`.
28
+ *
29
+ * The pack lives in the per-language package `lingotweaker-data-<lang>`,
30
+ * which must be installed separately (`npm install lingotweaker-data-<lang>`).
31
+ */
32
+ export function packPath(lang: string): string;
33
+
34
+ /**
35
+ * The data manifest (version, upstream commit, per-language sha256).
36
+ *
37
+ * The `file` paths are relative to the per-language package
38
+ * `lingotweaker-data-<lang>`, not to this package.
39
+ */
40
+ export function dataManifest(): LingoTweakerDataManifest;
package/index.js ADDED
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ // Loader for the LingoTweaker engine's runtime data.
4
+ //
5
+ // This package is code-only: the packs ship in one small package per language
6
+ // (`lingotweaker-data-<lang>`, mirroring the per-language PyPI data
7
+ // distributions). Install the languages you need alongside it:
8
+ //
9
+ // npm install lingotweaker-data lingotweaker-data-en
10
+ //
11
+ // const data = require("lingotweaker-data");
12
+ // const { Engine } = require("lingotweaker");
13
+ // const engine = new Engine("en-US", { dataDir: data.packPath("en") });
14
+
15
+ const { join } = require("node:path");
16
+ const { createRequire } = require("node:module");
17
+ const manifest = require("./manifest.json");
18
+
19
+ // Resolve from this package's location first (npm's flat node_modules puts the
20
+ // per-language packages next to it); fall back to the process working
21
+ // directory for layouts where they are not siblings (pnpm, workspace hoisting
22
+ // differences), where the per-language package is resolvable from the
23
+ // consuming project but not from inside this package's store path.
24
+ const hereRequire = createRequire(__filename);
25
+ const cwdRequire = createRequire(join(process.cwd(), "index.js"));
26
+
27
+ /** Languages with a published data pack (base codes: `en`, `de`, `gn`, …). */
28
+ function languages() {
29
+ return Object.keys(manifest.languages ?? {}).sort();
30
+ }
31
+
32
+ /**
33
+ * Absolute path of the gzipped data pack for `lang`.
34
+ *
35
+ * The pack lives in the per-language package `lingotweaker-data-<lang>` at
36
+ * the manifest's `file` path (e.g. `packs/en.pack.gz`); it must be installed
37
+ * separately (`npm install lingotweaker-data-<lang>`).
38
+ */
39
+ function packPath(lang) {
40
+ const entry = manifest.languages?.[lang];
41
+ if (!entry?.pack?.file) {
42
+ throw new Error(
43
+ `lingotweaker-data: no pack for ${JSON.stringify(lang)}; ` +
44
+ `available: ${languages().join(", ")}`,
45
+ );
46
+ }
47
+ const name = `lingotweaker-data-${lang}`;
48
+ let cause;
49
+ for (const req of [hereRequire, cwdRequire]) {
50
+ try {
51
+ return req.resolve(`${name}/${entry.pack.file}`);
52
+ } catch (err) {
53
+ cause = err;
54
+ }
55
+ }
56
+ throw new Error(
57
+ `lingotweaker-data: the ${JSON.stringify(lang)} pack is not installed; ` +
58
+ `run \`npm install ${name}\` (available: ${languages().join(", ")})`,
59
+ { cause },
60
+ );
61
+ }
62
+
63
+ /**
64
+ * The data manifest (version, upstream commit, per-language sha256).
65
+ *
66
+ * The `file` paths are relative to the per-language package
67
+ * `lingotweaker-data-<lang>`, not to this package.
68
+ */
69
+ function dataManifest() {
70
+ return manifest;
71
+ }
72
+
73
+ module.exports = {
74
+ languages,
75
+ packPath,
76
+ manifest: dataManifest,
77
+ };
package/index.mjs ADDED
@@ -0,0 +1,69 @@
1
+ // Loader for the LingoTweaker engine's runtime data.
2
+ //
3
+ // This package is code-only: the packs ship in one small package per language
4
+ // (`lingotweaker-data-<lang>`, mirroring the per-language PyPI data
5
+ // distributions). Install the languages you need alongside it:
6
+ //
7
+ // npm install lingotweaker-data lingotweaker-data-en
8
+ //
9
+ // import { packPath } from "lingotweaker-data";
10
+ // import { Engine } from "lingotweaker";
11
+ // const engine = new Engine("en-US", { dataDir: packPath("en") });
12
+
13
+ import { join } from "node:path";
14
+ import { createRequire } from "node:module";
15
+
16
+ // Resolve from this package's location first (npm's flat node_modules puts the
17
+ // per-language packages next to it); fall back to the process working
18
+ // directory for layouts where they are not siblings (pnpm, workspace hoisting
19
+ // differences), where the per-language package is resolvable from the
20
+ // consuming project but not from inside this package's store path.
21
+ const hereRequire = createRequire(import.meta.url);
22
+ const cwdRequire = createRequire(join(process.cwd(), "index.js"));
23
+ const manifest = hereRequire("./manifest.json");
24
+
25
+ /** Languages with a published data pack (base codes: `en`, `de`, `gn`, …). */
26
+ export function languages() {
27
+ return Object.keys(manifest.languages ?? {}).sort();
28
+ }
29
+
30
+ /**
31
+ * Absolute path of the gzipped data pack for `lang`.
32
+ *
33
+ * The pack lives in the per-language package `lingotweaker-data-<lang>` at
34
+ * the manifest's `file` path (e.g. `packs/en.pack.gz`); it must be installed
35
+ * separately (`npm install lingotweaker-data-<lang>`).
36
+ */
37
+ export function packPath(lang) {
38
+ const entry = manifest.languages?.[lang];
39
+ if (!entry?.pack?.file) {
40
+ throw new Error(
41
+ `lingotweaker-data: no pack for ${JSON.stringify(lang)}; ` +
42
+ `available: ${languages().join(", ")}`,
43
+ );
44
+ }
45
+ const name = `lingotweaker-data-${lang}`;
46
+ let cause;
47
+ for (const req of [hereRequire, cwdRequire]) {
48
+ try {
49
+ return req.resolve(`${name}/${entry.pack.file}`);
50
+ } catch (err) {
51
+ cause = err;
52
+ }
53
+ }
54
+ throw new Error(
55
+ `lingotweaker-data: the ${JSON.stringify(lang)} pack is not installed; ` +
56
+ `run \`npm install ${name}\` (available: ${languages().join(", ")})`,
57
+ { cause },
58
+ );
59
+ }
60
+
61
+ /**
62
+ * The data manifest (version, upstream commit, per-language sha256).
63
+ *
64
+ * The `file` paths are relative to the per-language package
65
+ * `lingotweaker-data-<lang>`, not to this package.
66
+ */
67
+ export function dataManifest() {
68
+ return manifest;
69
+ }
package/manifest.json ADDED
@@ -0,0 +1,272 @@
1
+ {
2
+ "version": "0.2.0",
3
+ "upstream_commit": "7bd1f99b849b1de66845113010b3c9261c3f37e0",
4
+ "languages": {
5
+ "ar": {
6
+ "pack": {
7
+ "file": "packs/ar.pack.gz",
8
+ "bytes": 14796535,
9
+ "sha256": "49f50889896a59e8c22d4dc2f4403e1715b259acab11cca47a1602dc770dded0"
10
+ }
11
+ },
12
+ "ast": {
13
+ "pack": {
14
+ "file": "packs/ast.pack.gz",
15
+ "bytes": 965053,
16
+ "sha256": "3ea7e9f5d95e2bd399e9d92556cf7ee555a846d9f26f5fb983d656c59e97680e"
17
+ }
18
+ },
19
+ "be": {
20
+ "pack": {
21
+ "file": "packs/be.pack.gz",
22
+ "bytes": 934715,
23
+ "sha256": "1527268186811899b8ceb66532353e30094acd64cda1e2d832cc3bb704dd9ec5"
24
+ }
25
+ },
26
+ "br": {
27
+ "pack": {
28
+ "file": "packs/br.pack.gz",
29
+ "bytes": 2004587,
30
+ "sha256": "26c30386a95b60e049443c61705d30dcb21b85a40bc3a04d331d474244198884"
31
+ }
32
+ },
33
+ "ca": {
34
+ "pack": {
35
+ "file": "packs/ca.pack.gz",
36
+ "bytes": 11454474,
37
+ "sha256": "966930437bcddc9849f361ada380c854436c155e52d8488abdf902f16ed8e364"
38
+ }
39
+ },
40
+ "crh": {
41
+ "pack": {
42
+ "file": "packs/crh.pack.gz",
43
+ "bytes": 2564074,
44
+ "sha256": "4edbd8c127f2060ff35614f15f970bf78e1b6a93eba2c9eb70d02bd1c26091cd"
45
+ }
46
+ },
47
+ "da": {
48
+ "pack": {
49
+ "file": "packs/da.pack.gz",
50
+ "bytes": 2425873,
51
+ "sha256": "0fef17b0b7ecbfa603ec5d61ba0b58eef644b702c440a1fcb1d71b569ba19056"
52
+ }
53
+ },
54
+ "de": {
55
+ "pack": {
56
+ "file": "packs/de.pack.gz",
57
+ "bytes": 21967951,
58
+ "sha256": "e006baa5667867a3f9b4034d1beae131afc1cf93dc97482e93759f0d1004ffc8"
59
+ }
60
+ },
61
+ "el": {
62
+ "pack": {
63
+ "file": "packs/el.pack.gz",
64
+ "bytes": 830640,
65
+ "sha256": "3943fd3d379bd0afbcdf02f888007c9a5b57957081c46fcf6b5fc8dce688ab35"
66
+ }
67
+ },
68
+ "en": {
69
+ "pack": {
70
+ "file": "packs/en.pack.gz",
71
+ "bytes": 15250759,
72
+ "sha256": "4eca72fac3b1905e1f8e7462959016e60ad6933cf122e0472162804d14e2af62"
73
+ }
74
+ },
75
+ "eo": {
76
+ "pack": {
77
+ "file": "packs/eo.pack.gz",
78
+ "bytes": 518057,
79
+ "sha256": "f5151af3f570c6f7bb344f13d40f12bdfb4e6b4bb111f7207366ae61bf935fb8"
80
+ }
81
+ },
82
+ "es": {
83
+ "pack": {
84
+ "file": "packs/es.pack.gz",
85
+ "bytes": 3773233,
86
+ "sha256": "a01cb04af857160b94e5d9a23b36f5abec2e4767f161afdc70ae5b458848694e"
87
+ }
88
+ },
89
+ "fa": {
90
+ "pack": {
91
+ "file": "packs/fa.pack.gz",
92
+ "bytes": 338405,
93
+ "sha256": "d300c27db1677168f7b73f93c260743ef8b236d11f25aa7ec291503cd744d2ca"
94
+ }
95
+ },
96
+ "fr": {
97
+ "pack": {
98
+ "file": "packs/fr.pack.gz",
99
+ "bytes": 3291344,
100
+ "sha256": "bc112a7731c291be5054de0433246d7c1c9ee4b9aab50ff7016519fc7510a175"
101
+ }
102
+ },
103
+ "gl": {
104
+ "pack": {
105
+ "file": "packs/gl.pack.gz",
106
+ "bytes": 4638344,
107
+ "sha256": "a6d82aee58fe31e9c5384104b1a0d517d31d3ced1685c517f05f1540819c73b4"
108
+ }
109
+ },
110
+ "gn": {
111
+ "pack": {
112
+ "file": "packs/gn.pack.gz",
113
+ "bytes": 290293,
114
+ "sha256": "fe60b1c22072799e07cca2c861a045c09699c635add4198f71f9733df6e5f10d"
115
+ }
116
+ },
117
+ "is": {
118
+ "pack": {
119
+ "file": "packs/is.pack.gz",
120
+ "bytes": 927358,
121
+ "sha256": "2822e39529d854d8635e83250e09f105240a0e4bfb95b7bde30d196d06d035f3"
122
+ }
123
+ },
124
+ "it": {
125
+ "pack": {
126
+ "file": "packs/it.pack.gz",
127
+ "bytes": 1115580,
128
+ "sha256": "bb3906451dc45bee7b738ef492cc18dff3d7f967e1c902439291af1598a722c2"
129
+ }
130
+ },
131
+ "ja": {
132
+ "pack": {
133
+ "file": "packs/ja.pack.gz",
134
+ "bytes": 10708382,
135
+ "sha256": "8e9bfc15c94b59a5bbb4270033febed8c895db11f4637d93d71f1a8577fd8b90"
136
+ }
137
+ },
138
+ "km": {
139
+ "pack": {
140
+ "file": "packs/km.pack.gz",
141
+ "bytes": 808549,
142
+ "sha256": "db450508e2e1d9e8a77de652b0b7d9b0b8cbfa2538de27ba446b620f7f8634cb"
143
+ }
144
+ },
145
+ "lt": {
146
+ "pack": {
147
+ "file": "packs/lt.pack.gz",
148
+ "bytes": 604799,
149
+ "sha256": "30794e3cd0bd8350420a4f2875bd9e05ffc6c1f4306889feec5d9faebf7831fb"
150
+ }
151
+ },
152
+ "ml": {
153
+ "pack": {
154
+ "file": "packs/ml.pack.gz",
155
+ "bytes": 959275,
156
+ "sha256": "f8126ec84bc57fb230a3f7256e8d3a9af73044f6e5c0b814852913f6f570e885"
157
+ }
158
+ },
159
+ "nl": {
160
+ "pack": {
161
+ "file": "packs/nl.pack.gz",
162
+ "bytes": 38077206,
163
+ "sha256": "c1db973c09be9b98e4447323a088be354267dd2edeb5653efa1f67791958caa1"
164
+ }
165
+ },
166
+ "nn": {
167
+ "pack": {
168
+ "file": "packs/nn.pack.gz",
169
+ "bytes": 1827886,
170
+ "sha256": "d171a11030221db5e035baa3524722af06c4be0c94630df499eba05d16391757"
171
+ }
172
+ },
173
+ "no": {
174
+ "pack": {
175
+ "file": "packs/no.pack.gz",
176
+ "bytes": 6244378,
177
+ "sha256": "9b2dd53af5632be218961d85ab6b15bf029c5e222e789b11c13fe705a027ea47"
178
+ }
179
+ },
180
+ "nrd": {
181
+ "pack": {
182
+ "file": "packs/nrd.pack.gz",
183
+ "bytes": 5015821,
184
+ "sha256": "bd0fc69f330c6bc596bef407fabee5384b5b0e49b65bd448becf85fecda4769c"
185
+ }
186
+ },
187
+ "pl": {
188
+ "pack": {
189
+ "file": "packs/pl.pack.gz",
190
+ "bytes": 6799941,
191
+ "sha256": "73ac39f1e2ec91dbdb08e5615f293afcde22070af11110447909ba194d814623"
192
+ }
193
+ },
194
+ "pt": {
195
+ "pack": {
196
+ "file": "packs/pt.pack.gz",
197
+ "bytes": 6455461,
198
+ "sha256": "0f7b0a6d6f5c2bea7e1c1d1b21890fb1c81ddc0a4afa051f30cb703b380a3e2f"
199
+ }
200
+ },
201
+ "ro": {
202
+ "pack": {
203
+ "file": "packs/ro.pack.gz",
204
+ "bytes": 1661169,
205
+ "sha256": "f4994bfad320a0acbb283635ea862bd288132fd0dc8e483acc18325a46fe6917"
206
+ }
207
+ },
208
+ "ru": {
209
+ "pack": {
210
+ "file": "packs/ru.pack.gz",
211
+ "bytes": 6293233,
212
+ "sha256": "57c5cd17781fd0a74acb8415eaaa3b22598fb2cdbf270e6763f1d023443b04f9"
213
+ }
214
+ },
215
+ "sk": {
216
+ "pack": {
217
+ "file": "packs/sk.pack.gz",
218
+ "bytes": 2859673,
219
+ "sha256": "30a6f391d6634230f17c7b2456d2215fb82f379a63ccf56b1b1a4b85aaf1be73"
220
+ }
221
+ },
222
+ "sl": {
223
+ "pack": {
224
+ "file": "packs/sl.pack.gz",
225
+ "bytes": 528116,
226
+ "sha256": "a957b0424e392d7605132d5f977a74d0eed8500e32d20c9fa64a96c8fd31692f"
227
+ }
228
+ },
229
+ "sr": {
230
+ "pack": {
231
+ "file": "packs/sr.pack.gz",
232
+ "bytes": 6662107,
233
+ "sha256": "82a22f113ab7b34fac084dee6d295a4a967e56a696270172e9f2c9525f077284"
234
+ }
235
+ },
236
+ "sv": {
237
+ "pack": {
238
+ "file": "packs/sv.pack.gz",
239
+ "bytes": 2027483,
240
+ "sha256": "a4941d8faa6b5cc9c7f5945b5716ab220787474cd3a0c7002f74785cdeb59b34"
241
+ }
242
+ },
243
+ "ta": {
244
+ "pack": {
245
+ "file": "packs/ta.pack.gz",
246
+ "bytes": 314872,
247
+ "sha256": "db8f327b9a2f927945430612a8f37d4c5db30540061d16da9aadccf879c2b5f0"
248
+ }
249
+ },
250
+ "tl": {
251
+ "pack": {
252
+ "file": "packs/tl.pack.gz",
253
+ "bytes": 401001,
254
+ "sha256": "5de86a3656536f89f39cce552c8d6857e51a1bfe7c831b6e111875f124409fcd"
255
+ }
256
+ },
257
+ "uk": {
258
+ "pack": {
259
+ "file": "packs/uk.pack.gz",
260
+ "bytes": 7129147,
261
+ "sha256": "51d196a669494ec273d394d6dfde1796b19e1c2d0478654038caca63864dfb2a"
262
+ }
263
+ },
264
+ "zh": {
265
+ "pack": {
266
+ "file": "packs/zh.pack.gz",
267
+ "bytes": 14113621,
268
+ "sha256": "4dc30fe21f758bcdad1899dd005c6d049539bb87601b4059a68855231dd72ce2"
269
+ }
270
+ }
271
+ }
272
+ }
package/package.json CHANGED
@@ -1,11 +1,40 @@
1
1
  {
2
2
  "name": "lingotweaker-data",
3
- "version": "0.0.1",
4
- "description": "Runtime language data packs for the LingoTweaker proofreading engine",
3
+ "version": "0.2.0",
4
+ "description": "Loader for the LingoTweaker proofreading engine's runtime data packs (the packs ship in per-language lingotweaker-data-<lang> packages)",
5
5
  "license": "LGPL-2.1-or-later",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/fiduswriter/LingoTweaker.git"
9
9
  },
10
- "homepage": "https://fiduswriter.github.io/LingoTweaker/"
11
- }
10
+ "homepage": "https://fiduswriter.github.io/LingoTweaker/",
11
+ "keywords": [
12
+ "proofreading",
13
+ "grammar",
14
+ "spellcheck",
15
+ "nlp",
16
+ "language",
17
+ "data"
18
+ ],
19
+ "main": "./index.js",
20
+ "types": "./index.d.ts",
21
+ "exports": {
22
+ ".": {
23
+ "types": "./index.d.ts",
24
+ "import": "./index.mjs",
25
+ "require": "./index.js"
26
+ },
27
+ "./manifest.json": "./manifest.json",
28
+ "./package.json": "./package.json"
29
+ },
30
+ "files": [
31
+ "manifest.json",
32
+ "index.js",
33
+ "index.mjs",
34
+ "index.d.ts",
35
+ "README.md"
36
+ ],
37
+ "engines": {
38
+ "node": ">= 18"
39
+ }
40
+ }