dicta-nakdan 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Moshe Malka
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # dicta-nakdan
2
+
3
+ Typed, zero-dependency client for **[Dicta](https://dicta.org.il/)'s free Nakdan API** — automatic Hebrew **vocalization** (adding niqqud / nikud to unpointed text), with per-word alternatives and confidence.
4
+
5
+ ```
6
+ npm install dicta-nakdan
7
+ ```
8
+
9
+ ## Why
10
+
11
+ Adding niqqud (vowel points) to Hebrew text is genuinely hard — it's a context-dependent NLP problem, not a lookup. Dicta, a nonprofit, offers a remarkably good vocalizer for free, but its raw API returns a terse word-array format with no types and no documented contract. This wraps it in a clean, typed TypeScript API and normalizes the response — so you can add nikud in one call.
12
+
13
+ ```ts
14
+ import { vocalize, nakdan } from "dicta-nakdan";
15
+
16
+ await vocalize("שלום עולם"); // "שָׁלוֹם עוֹלָם"
17
+
18
+ const r = await nakdan("בראשית ברא אלהים", { genre: "rabbinic" });
19
+ r.text; // the fully pointed string
20
+ r.words[0].vocalized; // "בְּרֵאשִׁית"
21
+ r.words[0].options; // alternative vocalizations Dicta considered
22
+ r.words[0].confident; // whether Dicta was sure
23
+ ```
24
+
25
+ ## API
26
+
27
+ - **`vocalize(text, opts?)`** → the pointed string (the common case).
28
+ - **`nakdan(text, opts?)`** → `{ text, words }`, where each word is `{ word, vocalized, isSeparator, options, confident }` — separators (spaces, punctuation) are preserved in order so you can reconstruct or re-render the text.
29
+
30
+ **`opts`**: `genre` (`"modern"` default, `"rabbinic"`, or `"poetry"`), `fetch` (inject for tests/proxies), `endpoint` (override the pinned API URL), `timeoutMs` (default 30000). Empty or non-Hebrew input, HTTP failures, timeouts, and unexpected responses all throw `NakdanError`.
31
+
32
+ The mocked test suite runs offline against a captured real response; `npm run smoke` calls the live API.
33
+
34
+ ## A note on the upstream service
35
+
36
+ Dicta is a nonprofit and the Nakdan API is offered free with no formal published contract; its endpoints are version-numbered. This package pins a working endpoint and lets you override it via `opts.endpoint` if Dicta rolls a new version. Please use the service considerately.
37
+
38
+ ## Related
39
+
40
+ By the same author: [`mispar`](https://github.com/moshejs/mispar) (Hebrew gematria, 13 classical methods) and [Gamatria](https://gamatria.vercel.app), a gematria search engine over the Tanakh and Mishnah.
41
+
42
+ ## Author
43
+
44
+ Built by **[Moshe Malka](https://moshemalka.com)** — engineering leader in New York City. Studio work at [Quentin.Code](https://www.quentin.software/).
45
+
46
+ MIT © Moshe Malka
package/dist/index.cjs ADDED
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ NakdanError: () => NakdanError,
24
+ nakdan: () => nakdan,
25
+ vocalize: () => vocalize
26
+ });
27
+ module.exports = __toCommonJS(index_exports);
28
+ var NakdanError = class extends Error {
29
+ constructor(message, status) {
30
+ super(message);
31
+ this.name = "NakdanError";
32
+ this.status = status;
33
+ }
34
+ };
35
+ var DEFAULT_ENDPOINT = "https://nakdan-2-0.loadbalancer.dicta.org.il/api";
36
+ function normalize(raw) {
37
+ const words = raw.map((r) => {
38
+ const isSeparator = r.sep === true;
39
+ const options = Array.isArray(r.options) ? r.options : [];
40
+ const vocalized = isSeparator ? r.word : options[0] ?? r.word;
41
+ return {
42
+ word: r.word,
43
+ vocalized,
44
+ isSeparator,
45
+ options,
46
+ confident: r.fconfident === true
47
+ };
48
+ });
49
+ return { text: words.map((w) => w.vocalized).join(""), words };
50
+ }
51
+ var HEBREW_RE = /[֐-׿]/;
52
+ async function nakdan(text, opts = {}) {
53
+ if (typeof text !== "string" || text.trim() === "") {
54
+ throw new NakdanError("nakdan requires non-empty text");
55
+ }
56
+ if (!HEBREW_RE.test(text)) {
57
+ throw new NakdanError("nakdan requires Hebrew text (no Hebrew characters found)");
58
+ }
59
+ const doFetch = opts.fetch ?? globalThis.fetch;
60
+ const endpoint = opts.endpoint ?? DEFAULT_ENDPOINT;
61
+ const genre = opts.genre ?? "modern";
62
+ const timeoutMs = opts.timeoutMs ?? 3e4;
63
+ const controller = new AbortController();
64
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
65
+ let res;
66
+ try {
67
+ res = await doFetch(endpoint, {
68
+ method: "POST",
69
+ headers: { "content-type": "application/json", accept: "application/json" },
70
+ body: JSON.stringify({ task: "nakdan", genre, data: text, addmorph: false, keepqq: false }),
71
+ signal: controller.signal
72
+ });
73
+ } catch (err) {
74
+ if (err instanceof Error && err.name === "AbortError") {
75
+ throw new NakdanError(`Nakdan request timed out after ${timeoutMs}ms`);
76
+ }
77
+ throw new NakdanError(`Nakdan request failed: ${err.message}`);
78
+ } finally {
79
+ clearTimeout(timer);
80
+ }
81
+ if (!res.ok) throw new NakdanError(`Nakdan request failed with HTTP ${res.status}`, res.status);
82
+ let raw;
83
+ try {
84
+ raw = await res.json();
85
+ } catch {
86
+ throw new NakdanError("Nakdan returned a non-JSON response");
87
+ }
88
+ if (!Array.isArray(raw)) {
89
+ throw new NakdanError("Unexpected Nakdan response shape (expected an array of words)");
90
+ }
91
+ return normalize(raw);
92
+ }
93
+ async function vocalize(text, opts = {}) {
94
+ return (await nakdan(text, opts)).text;
95
+ }
96
+ // Annotate the CommonJS export names for ESM import in node:
97
+ 0 && (module.exports = {
98
+ NakdanError,
99
+ nakdan,
100
+ vocalize
101
+ });
@@ -0,0 +1,70 @@
1
+ /**
2
+ * dicta-nakdan — typed, zero-dependency client for Dicta's free Nakdan
3
+ * (automatic Hebrew vocalization / niqqud) API.
4
+ *
5
+ * Send unpointed Hebrew text, get it back with niqqud, plus per-word
6
+ * alternatives and a confidence flag — normalized from Dicta's raw
7
+ * word-array format into a clean TypeScript shape.
8
+ *
9
+ * Dicta (dicta.org.il) is a nonprofit; the tools are free. There is no formal
10
+ * published API contract, and the service's endpoints are version-numbered,
11
+ * so a drift-resistant default endpoint is pinned and overridable.
12
+ */
13
+ /** Text genre — Dicta tunes vocalization to the register. */
14
+ type Genre = "modern" | "rabbinic" | "poetry";
15
+ interface NakdanOptions {
16
+ /** Custom fetch implementation (testing, proxies). Defaults to global fetch. */
17
+ fetch?: typeof globalThis.fetch;
18
+ /** Override the API endpoint (defaults to the pinned Nakdan endpoint). */
19
+ endpoint?: string;
20
+ /** Text genre. Default "modern". */
21
+ genre?: Genre;
22
+ /** Request timeout in milliseconds. Default 30000. */
23
+ timeoutMs?: number;
24
+ }
25
+ /** One token in the Nakdan result. */
26
+ interface NakdanWord {
27
+ /** The token text. For separators this is the whitespace/punctuation itself. */
28
+ word: string;
29
+ /** The vocalized (pointed) form — Dicta's top choice. Equals `word` for separators. */
30
+ vocalized: string;
31
+ /** True for whitespace/punctuation between words. */
32
+ isSeparator: boolean;
33
+ /** Alternative vocalizations Dicta considered (most likely first), if any. */
34
+ options: string[];
35
+ /** Dicta's confidence in the chosen vocalization (word tokens only). */
36
+ confident: boolean;
37
+ }
38
+ interface NakdanResult {
39
+ /** The fully vocalized text (all tokens' top choices concatenated). */
40
+ text: string;
41
+ /** Per-token detail, including separators, in order. */
42
+ words: NakdanWord[];
43
+ }
44
+ declare class NakdanError extends Error {
45
+ readonly status?: number;
46
+ constructor(message: string, status?: number);
47
+ }
48
+ /**
49
+ * Vocalize Hebrew text, returning the full result (text + per-word detail).
50
+ *
51
+ * ```ts
52
+ * const r = await nakdan("שלום עולם");
53
+ * r.text; // "שָׁלוֹם עוֹלָם"
54
+ * r.words[0].options; // alternative vocalizations of the first word
55
+ * ```
56
+ *
57
+ * @throws {NakdanError} on empty/non-Hebrew input, network failure, timeout,
58
+ * or an unexpected response shape.
59
+ */
60
+ declare function nakdan(text: string, opts?: NakdanOptions): Promise<NakdanResult>;
61
+ /**
62
+ * Vocalize Hebrew text and return just the pointed string — the common case.
63
+ *
64
+ * ```ts
65
+ * await vocalize("שלום עולם"); // "שָׁלוֹם עוֹלָם"
66
+ * ```
67
+ */
68
+ declare function vocalize(text: string, opts?: NakdanOptions): Promise<string>;
69
+
70
+ export { type Genre, NakdanError, type NakdanOptions, type NakdanResult, type NakdanWord, nakdan, vocalize };
@@ -0,0 +1,70 @@
1
+ /**
2
+ * dicta-nakdan — typed, zero-dependency client for Dicta's free Nakdan
3
+ * (automatic Hebrew vocalization / niqqud) API.
4
+ *
5
+ * Send unpointed Hebrew text, get it back with niqqud, plus per-word
6
+ * alternatives and a confidence flag — normalized from Dicta's raw
7
+ * word-array format into a clean TypeScript shape.
8
+ *
9
+ * Dicta (dicta.org.il) is a nonprofit; the tools are free. There is no formal
10
+ * published API contract, and the service's endpoints are version-numbered,
11
+ * so a drift-resistant default endpoint is pinned and overridable.
12
+ */
13
+ /** Text genre — Dicta tunes vocalization to the register. */
14
+ type Genre = "modern" | "rabbinic" | "poetry";
15
+ interface NakdanOptions {
16
+ /** Custom fetch implementation (testing, proxies). Defaults to global fetch. */
17
+ fetch?: typeof globalThis.fetch;
18
+ /** Override the API endpoint (defaults to the pinned Nakdan endpoint). */
19
+ endpoint?: string;
20
+ /** Text genre. Default "modern". */
21
+ genre?: Genre;
22
+ /** Request timeout in milliseconds. Default 30000. */
23
+ timeoutMs?: number;
24
+ }
25
+ /** One token in the Nakdan result. */
26
+ interface NakdanWord {
27
+ /** The token text. For separators this is the whitespace/punctuation itself. */
28
+ word: string;
29
+ /** The vocalized (pointed) form — Dicta's top choice. Equals `word` for separators. */
30
+ vocalized: string;
31
+ /** True for whitespace/punctuation between words. */
32
+ isSeparator: boolean;
33
+ /** Alternative vocalizations Dicta considered (most likely first), if any. */
34
+ options: string[];
35
+ /** Dicta's confidence in the chosen vocalization (word tokens only). */
36
+ confident: boolean;
37
+ }
38
+ interface NakdanResult {
39
+ /** The fully vocalized text (all tokens' top choices concatenated). */
40
+ text: string;
41
+ /** Per-token detail, including separators, in order. */
42
+ words: NakdanWord[];
43
+ }
44
+ declare class NakdanError extends Error {
45
+ readonly status?: number;
46
+ constructor(message: string, status?: number);
47
+ }
48
+ /**
49
+ * Vocalize Hebrew text, returning the full result (text + per-word detail).
50
+ *
51
+ * ```ts
52
+ * const r = await nakdan("שלום עולם");
53
+ * r.text; // "שָׁלוֹם עוֹלָם"
54
+ * r.words[0].options; // alternative vocalizations of the first word
55
+ * ```
56
+ *
57
+ * @throws {NakdanError} on empty/non-Hebrew input, network failure, timeout,
58
+ * or an unexpected response shape.
59
+ */
60
+ declare function nakdan(text: string, opts?: NakdanOptions): Promise<NakdanResult>;
61
+ /**
62
+ * Vocalize Hebrew text and return just the pointed string — the common case.
63
+ *
64
+ * ```ts
65
+ * await vocalize("שלום עולם"); // "שָׁלוֹם עוֹלָם"
66
+ * ```
67
+ */
68
+ declare function vocalize(text: string, opts?: NakdanOptions): Promise<string>;
69
+
70
+ export { type Genre, NakdanError, type NakdanOptions, type NakdanResult, type NakdanWord, nakdan, vocalize };
package/dist/index.js ADDED
@@ -0,0 +1,74 @@
1
+ // src/index.ts
2
+ var NakdanError = class extends Error {
3
+ constructor(message, status) {
4
+ super(message);
5
+ this.name = "NakdanError";
6
+ this.status = status;
7
+ }
8
+ };
9
+ var DEFAULT_ENDPOINT = "https://nakdan-2-0.loadbalancer.dicta.org.il/api";
10
+ function normalize(raw) {
11
+ const words = raw.map((r) => {
12
+ const isSeparator = r.sep === true;
13
+ const options = Array.isArray(r.options) ? r.options : [];
14
+ const vocalized = isSeparator ? r.word : options[0] ?? r.word;
15
+ return {
16
+ word: r.word,
17
+ vocalized,
18
+ isSeparator,
19
+ options,
20
+ confident: r.fconfident === true
21
+ };
22
+ });
23
+ return { text: words.map((w) => w.vocalized).join(""), words };
24
+ }
25
+ var HEBREW_RE = /[֐-׿]/;
26
+ async function nakdan(text, opts = {}) {
27
+ if (typeof text !== "string" || text.trim() === "") {
28
+ throw new NakdanError("nakdan requires non-empty text");
29
+ }
30
+ if (!HEBREW_RE.test(text)) {
31
+ throw new NakdanError("nakdan requires Hebrew text (no Hebrew characters found)");
32
+ }
33
+ const doFetch = opts.fetch ?? globalThis.fetch;
34
+ const endpoint = opts.endpoint ?? DEFAULT_ENDPOINT;
35
+ const genre = opts.genre ?? "modern";
36
+ const timeoutMs = opts.timeoutMs ?? 3e4;
37
+ const controller = new AbortController();
38
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
39
+ let res;
40
+ try {
41
+ res = await doFetch(endpoint, {
42
+ method: "POST",
43
+ headers: { "content-type": "application/json", accept: "application/json" },
44
+ body: JSON.stringify({ task: "nakdan", genre, data: text, addmorph: false, keepqq: false }),
45
+ signal: controller.signal
46
+ });
47
+ } catch (err) {
48
+ if (err instanceof Error && err.name === "AbortError") {
49
+ throw new NakdanError(`Nakdan request timed out after ${timeoutMs}ms`);
50
+ }
51
+ throw new NakdanError(`Nakdan request failed: ${err.message}`);
52
+ } finally {
53
+ clearTimeout(timer);
54
+ }
55
+ if (!res.ok) throw new NakdanError(`Nakdan request failed with HTTP ${res.status}`, res.status);
56
+ let raw;
57
+ try {
58
+ raw = await res.json();
59
+ } catch {
60
+ throw new NakdanError("Nakdan returned a non-JSON response");
61
+ }
62
+ if (!Array.isArray(raw)) {
63
+ throw new NakdanError("Unexpected Nakdan response shape (expected an array of words)");
64
+ }
65
+ return normalize(raw);
66
+ }
67
+ async function vocalize(text, opts = {}) {
68
+ return (await nakdan(text, opts)).text;
69
+ }
70
+ export {
71
+ NakdanError,
72
+ nakdan,
73
+ vocalize
74
+ };
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "dicta-nakdan",
3
+ "version": "1.0.0",
4
+ "description": "Typed, zero-dependency client for Dicta's free Nakdan API — automatic Hebrew vocalization (niqqud) with per-word alternatives. Add nikud to unpointed Hebrew text.",
5
+ "keywords": [
6
+ "hebrew",
7
+ "nakdan",
8
+ "niqqud",
9
+ "nikud",
10
+ "vocalization",
11
+ "diacritics",
12
+ "dicta",
13
+ "hebrew-nlp",
14
+ "judaica",
15
+ "torah",
16
+ "api-client"
17
+ ],
18
+ "homepage": "https://moshemalka.com",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/moshejs/dicta-nakdan.git"
22
+ },
23
+ "bugs": "https://github.com/moshejs/dicta-nakdan/issues",
24
+ "author": "Moshe Malka <hello@moshemalka.com> (https://moshemalka.com)",
25
+ "license": "MIT",
26
+ "type": "module",
27
+ "main": "./dist/index.cjs",
28
+ "module": "./dist/index.js",
29
+ "types": "./dist/index.d.ts",
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "import": "./dist/index.js",
34
+ "require": "./dist/index.cjs"
35
+ }
36
+ },
37
+ "files": [
38
+ "dist"
39
+ ],
40
+ "sideEffects": false,
41
+ "scripts": {
42
+ "build": "tsup src/index.ts --format esm,cjs --dts --clean",
43
+ "test": "vitest run",
44
+ "typecheck": "tsc --noEmit",
45
+ "smoke": "node scripts/smoke.mjs",
46
+ "prepublishOnly": "npm run typecheck && npm run test && npm run build"
47
+ },
48
+ "devDependencies": {
49
+ "tsup": "^8.5.0",
50
+ "typescript": "^5.8.0",
51
+ "vitest": "^3.2.0"
52
+ },
53
+ "engines": {
54
+ "node": ">=18"
55
+ }
56
+ }