nko-kit 0.0.0-stage → 0.1.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 Hamed Domo Ouologuem
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 CHANGED
@@ -1,3 +1,92 @@
1
- # Temporary Holding Version
1
+ # nko-kit ߒߞߏ
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Boîte à outils TypeScript pour le N'Ko et le bambara : passer du N'Ko à l'alphabet latin et inversement, gérer les tons, les chiffres et l'affichage de droite à gauche. Zéro dépendance.
4
+
5
+ *A TypeScript toolkit for N'Ko and Bambara: N'Ko ↔ Latin transliteration, tones, digits and right-to-left display. Zero dependencies. [English below](#english).*
6
+
7
+ > ⚠️ **Version 0.1, à relire par des personnes qui écrivent le N'Ko.** Les tables de correspondance viennent du standard Unicode et des notes du W3C. Si vous voyez une erreur, [ouvrez une issue](https://github.com/MomoOuologuem/nko-kit/issues) : c'est la contribution la plus utile.
8
+
9
+ ## Pourquoi
10
+
11
+ Le N'Ko est très utilisé en ligne, notamment dans les groupes WhatsApp et Telegram, mais les développeurs ont peu d'outils pour le manipuler. `nko-kit` veut rendre le N'Ko aussi simple à gérer dans une application que l'alphabet latin.
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ npm install nko-kit
17
+ ```
18
+
19
+ ## Utilisation
20
+
21
+ ```ts
22
+ import { toLatin, toNko, toNkoDetailed, isNko, toNkoDigits, isolateRtl } from "nko-kit";
23
+
24
+ toLatin("ߒߞߏ"); // "nko"
25
+ toLatin("ߓߡߊߣߊ߲ߞߊ߲"); // "bamanankan" (la voyelle non répétée est restituée)
26
+ toLatin("ߓߊ߰", { tones: "accents" }); // "bàa"
27
+
28
+ toNko("bá"); // "ߓߊ߫"
29
+ toNkoDetailed("bamanankan");
30
+ // { text: "ߓߊߡߊߣߊ߲ߞߊ߲", missingTones: 4, warnings: [] }
31
+
32
+ isNko("ߒߞߏ"); // true
33
+ toNkoDigits("1949"); // "߁߉߄߉"
34
+ isolateRtl("ߒߞߏ"); // texte entouré d'isolats RTL pour l'affichage
35
+ ```
36
+
37
+ ## Ce qu'il faut savoir
38
+
39
+ **Les tons.** Le N'Ko note obligatoirement les tons, alors que le bambara en alphabet latin ne les écrit presque jamais. `toNko` ne peut donc pas deviner les tons : il convertit ceux qui sont écrits avec des accents (á haut, à bas, ǎ montant, â descendant) et compte les autres dans `missingTones`, pour qu'une personne les complète.
40
+
41
+ **La voyelle non répétée.** En N'Ko, quand deux syllabes qui se suivent ont la même voyelle, on n'écrit la voyelle qu'une fois : ߓߡߊߣߊ߲ se lit « bamanan ». `toLatin` restitue cette voyelle. `toNko` écrit pour l'instant toutes les voyelles.
42
+
43
+ **Les lettres à plusieurs lectures.** Certaines lettres se lisent différemment selon le dialecte. Par exemple, ߜ sert pour *jɛ́*, *gɛ̀lɛn* et *woló* en bambara. `toLatinDetailed` renvoie un avertissement dans ce cas.
44
+
45
+ ## API
46
+
47
+ | Fonction | Rôle |
48
+ |---|---|
49
+ | `toLatin(texte, options?)` | N'Ko → latin. `tones: "none"` (défaut) ou `"accents"` |
50
+ | `toLatinDetailed(texte, options?)` | Pareil, avec la liste des avertissements |
51
+ | `toNko(texte, options?)` | Latin → N'Ko, mode assisté |
52
+ | `toNkoDetailed(texte, options?)` | Pareil, avec `missingTones` et les avertissements |
53
+ | `isNko(texte)`, `containsNko(texte)` | Détection du N'Ko |
54
+ | `stripTones(texte)`, `stripDiacritics(texte)` | Retire les tons (et la nasalisation), utile pour la recherche |
55
+ | `normalizeNko(texte)` | Remet les signes combinés dans l'ordre canonique |
56
+ | `toLatinDigits`, `toNkoDigits` | Chiffres N'Ko ↔ 0-9 |
57
+ | `isolateRtl(texte)` | Affichage correct du N'Ko au milieu d'un texte en français |
58
+
59
+ ## Feuille de route
60
+
61
+ - [ ] Relecture complète des tables par des personnes qui écrivent le N'Ko
62
+ - [ ] Appliquer la règle de la voyelle non répétée dans `toNko`
63
+ - [ ] Composant React de clavier N'Ko
64
+ - [ ] Dictionnaire de tons pour les mots courants (licence des sources à vérifier)
65
+ - [ ] Prise en charge du maninka et du dioula
66
+
67
+ ## Contribuer
68
+
69
+ Les contributions sont les bienvenues, surtout de la part des personnes qui lisent et écrivent le N'Ko. Voir [CONTRIBUTING.md](CONTRIBUTING.md).
70
+
71
+ ## Sources
72
+
73
+ - [Tableau Unicode du bloc N'Ko (U+07C0–U+07FF)](https://unicode.org/charts/PDF/U07C0.pdf)
74
+ - [Notes sur l'orthographe N'Ko, r12a / W3C](https://r12a.github.io/scripts/nko/nqo.html)
75
+ - [Notes sur l'orthographe bambara en alphabet latin, r12a](https://r12a.github.io/scripts/latn/bm)
76
+ - [N'Ko Script Resources, W3C](https://www.w3.org/International/afrlreq/nko/)
77
+
78
+ ---
79
+
80
+ ## English
81
+
82
+ `nko-kit` is a zero-dependency TypeScript toolkit for N'Ko and Bambara.
83
+
84
+ - `toLatin` converts N'Ko to Latin Bambara, restoring the vowel N'Ko does not repeat (ߓߡߊߣߊ߲ → *bamanan*), with tones dropped or written as accents.
85
+ - `toNko` converts Latin Bambara to N'Ko in **assisted mode**: Latin Bambara rarely writes tones, so tones given as accents are converted and the others are counted in `missingTones` for a human to add.
86
+ - Helpers for detection, tone stripping, digits and RTL isolation.
87
+
88
+ This is version 0.1. The tables come from the Unicode standard and W3C notes and **need review by fluent N'Ko writers**. Issues and pull requests are very welcome.
89
+
90
+ ## Licence
91
+
92
+ MIT © Hamed Domo Ouologuem
@@ -0,0 +1,38 @@
1
+ /**
2
+ * N'Ko characters (Unicode block U+07C0–U+07FF) and their Latin
3
+ * correspondences in the Bambara (Bamanankan) orthography.
4
+ *
5
+ * Sources: Unicode code chart U+07C0, W3C N'Ko notes (r12a).
6
+ * The Latin values follow the official Malian orthography.
7
+ * Every row should be checked by fluent N'Ko writers: open an issue
8
+ * if something is wrong.
9
+ */
10
+ export declare const NKO_RANGE_START = 1984;
11
+ export declare const NKO_RANGE_END = 2047;
12
+ /** Vowels: N'Ko → Latin. */
13
+ export declare const VOWELS: Readonly<Record<string, string>>;
14
+ /** Consonants: N'Ko → Latin. */
15
+ export declare const CONSONANTS: Readonly<Record<string, string>>;
16
+ /** Syllabic nasal ߒ (n'ko, "I"). */
17
+ export declare const SYLLABIC_N = "\u07D2";
18
+ /** Dagbasinna ߑ: explicitly marks the absence of a vowel. */
19
+ export declare const DAGBASINNA = "\u07D1";
20
+ /** Letters whose Latin reading depends on dialect or context. */
21
+ export declare const AMBIGUOUS_LETTERS: ReadonlySet<string>;
22
+ export type Tone = "high" | "low" | "rising" | "falling";
23
+ export interface ToneMark {
24
+ tone: Tone;
25
+ long: boolean;
26
+ }
27
+ /** Combining tone marks. A vowel with no mark is short and falling. */
28
+ export declare const TONE_MARKS: Readonly<Record<string, ToneMark>>;
29
+ /** Combining nasalization mark ߲. */
30
+ export declare const NASALIZATION = "\u07F2";
31
+ /** Combining double dot above ߳ (used for borrowed sounds). */
32
+ export declare const DOUBLE_DOT_ABOVE = "\u07F3";
33
+ /** Punctuation and symbols: N'Ko → Latin. */
34
+ export declare const PUNCTUATION: Readonly<Record<string, string>>;
35
+ /** Characters that carry no Latin equivalent and are dropped. */
36
+ export declare const DROPPED: ReadonlySet<string>;
37
+ /** Latin combining accents used to write tones. */
38
+ export declare const LATIN_TONE_ACCENTS: Readonly<Record<Tone, string>>;
package/dist/chars.js ADDED
@@ -0,0 +1,97 @@
1
+ /**
2
+ * N'Ko characters (Unicode block U+07C0–U+07FF) and their Latin
3
+ * correspondences in the Bambara (Bamanankan) orthography.
4
+ *
5
+ * Sources: Unicode code chart U+07C0, W3C N'Ko notes (r12a).
6
+ * The Latin values follow the official Malian orthography.
7
+ * Every row should be checked by fluent N'Ko writers: open an issue
8
+ * if something is wrong.
9
+ */
10
+ export const NKO_RANGE_START = 0x07c0;
11
+ export const NKO_RANGE_END = 0x07ff;
12
+ /** Vowels: N'Ko → Latin. */
13
+ export const VOWELS = {
14
+ "\u07CA": "a", // ߊ
15
+ "\u07CB": "e", // ߋ
16
+ "\u07CC": "i", // ߌ
17
+ "\u07CD": "ɛ", // ߍ
18
+ "\u07CE": "u", // ߎ
19
+ "\u07CF": "o", // ߏ
20
+ "\u07D0": "ɔ", // ߐ
21
+ };
22
+ /** Consonants: N'Ko → Latin. */
23
+ export const CONSONANTS = {
24
+ "\u07D3": "b", // ߓ
25
+ "\u07D4": "p", // ߔ
26
+ "\u07D5": "t", // ߕ
27
+ "\u07D6": "j", // ߖ
28
+ "\u07D7": "c", // ߗ
29
+ "\u07D8": "d", // ߘ
30
+ "\u07D9": "r", // ߙ
31
+ "\u07DA": "rr", // ߚ
32
+ "\u07DB": "s", // ߛ
33
+ "\u07DC": "g", // ߜ (gb in Maninka; read g in Bambara)
34
+ "\u07DD": "f", // ߝ
35
+ "\u07DE": "k", // ߞ
36
+ "\u07DF": "l", // ߟ
37
+ "\u07E0": "n", // ߠ na woloso
38
+ "\u07E1": "m", // ߡ
39
+ "\u07E2": "ɲ", // ߢ
40
+ "\u07E3": "n", // ߣ
41
+ "\u07E4": "h", // ߤ
42
+ "\u07E5": "w", // ߥ
43
+ "\u07E6": "y", // ߦ
44
+ "\u07E7": "ɲ", // ߧ nya woloso
45
+ "\u07E8": "j", // ߨ jona ja (rare)
46
+ "\u07E9": "c", // ߩ jona cha (rare)
47
+ "\u07EA": "r", // ߪ jona ra (rare)
48
+ };
49
+ /** Syllabic nasal ߒ (n'ko, "I"). */
50
+ export const SYLLABIC_N = "\u07D2";
51
+ /** Dagbasinna ߑ: explicitly marks the absence of a vowel. */
52
+ export const DAGBASINNA = "\u07D1";
53
+ /** Letters whose Latin reading depends on dialect or context. */
54
+ export const AMBIGUOUS_LETTERS = new Set([
55
+ "\u07DC", // ߜ g / gb / w (e.g. jɛ́, gɛ̀lɛn, woló share it)
56
+ "\u07E8",
57
+ "\u07E9",
58
+ "\u07EA",
59
+ ]);
60
+ /** Combining tone marks. A vowel with no mark is short and falling. */
61
+ export const TONE_MARKS = {
62
+ "\u07EB": { tone: "high", long: false }, // ߫
63
+ "\u07EC": { tone: "low", long: false }, // ߬
64
+ "\u07ED": { tone: "rising", long: false }, // ߭
65
+ "\u07EE": { tone: "falling", long: true }, // ߮
66
+ "\u07EF": { tone: "high", long: true }, // ߯
67
+ "\u07F0": { tone: "low", long: true }, // ߰
68
+ "\u07F1": { tone: "rising", long: true }, // ߱
69
+ };
70
+ /** Combining nasalization mark ߲. */
71
+ export const NASALIZATION = "\u07F2";
72
+ /** Combining double dot above ߳ (used for borrowed sounds). */
73
+ export const DOUBLE_DOT_ABOVE = "\u07F3";
74
+ /** Punctuation and symbols: N'Ko → Latin. */
75
+ export const PUNCTUATION = {
76
+ "\u07F4": "'", // ߴ high tone apostrophe
77
+ "\u07F5": "'", // ߵ low tone apostrophe
78
+ "\u07F8": ",", // ߸ comma
79
+ "\u07F9": "!", // ߹ exclamation mark
80
+ "\u060C": ",", // ، Arabic comma, used in N'Ko text
81
+ "\u061B": ";", // ؛ Arabic semicolon
82
+ "\u061F": "?", // ؟ Arabic question mark
83
+ "\u2E1C": "«", // ⸜ left low paraphrase bracket
84
+ "\u2E1D": "»", // ⸝ right low paraphrase bracket
85
+ };
86
+ /** Characters that carry no Latin equivalent and are dropped. */
87
+ export const DROPPED = new Set([
88
+ "\u07FA", // ߺ lajanyalan (elongation)
89
+ "\u07FD", // ߽ dantayalan
90
+ ]);
91
+ /** Latin combining accents used to write tones. */
92
+ export const LATIN_TONE_ACCENTS = {
93
+ high: "\u0301", // á
94
+ low: "\u0300", // à
95
+ rising: "\u030C", // ǎ
96
+ falling: "\u0302", // â
97
+ };
@@ -0,0 +1,4 @@
1
+ export { containsNko, isNko, isolateRtl, normalizeNko, stripDiacritics, stripTones, toLatinDigits, toNkoDigits, } from "./text.js";
2
+ export { toLatin, toLatinDetailed, type ToLatinOptions, type ToLatinResult, type Warning, } from "./toLatin.js";
3
+ export { toNko, toNkoDetailed, type ToNkoOptions, type ToNkoResult, } from "./toNko.js";
4
+ export type { Tone } from "./chars.js";
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { containsNko, isNko, isolateRtl, normalizeNko, stripDiacritics, stripTones, toLatinDigits, toNkoDigits, } from "./text.js";
2
+ export { toLatin, toLatinDetailed, } from "./toLatin.js";
3
+ export { toNko, toNkoDetailed, } from "./toNko.js";
package/dist/text.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ /** True if the text contains at least one N'Ko character. */
2
+ export declare function containsNko(text: string): boolean;
3
+ /**
4
+ * True if every letter of the text is N'Ko. Spaces, digits and
5
+ * punctuation are ignored.
6
+ */
7
+ export declare function isNko(text: string): boolean;
8
+ /**
9
+ * Puts combining marks in canonical order (nasalization before tone)
10
+ * so that two spellings of the same word compare equal.
11
+ */
12
+ export declare function normalizeNko(text: string): string;
13
+ /** Removes tone marks, keeps nasalization. Useful for search. */
14
+ export declare function stripTones(text: string): string;
15
+ /** Removes tone marks and nasalization. */
16
+ export declare function stripDiacritics(text: string): string;
17
+ /** ߁߉߄߉ → 1949 */
18
+ export declare function toLatinDigits(text: string): string;
19
+ /** 1949 → ߁߉߄߉ */
20
+ export declare function toNkoDigits(text: string): string;
21
+ /**
22
+ * Wraps N'Ko text in Unicode directional isolates (RLI … PDI) so it
23
+ * displays right-to-left correctly inside left-to-right text, as the
24
+ * W3C recommends.
25
+ */
26
+ export declare function isolateRtl(text: string): string;
package/dist/text.js ADDED
@@ -0,0 +1,67 @@
1
+ import { NASALIZATION, NKO_RANGE_END, NKO_RANGE_START, TONE_MARKS, } from "./chars.js";
2
+ const NKO_DIGIT_ZERO = 0x07c0;
3
+ function isNkoCodePoint(cp) {
4
+ return cp >= NKO_RANGE_START && cp <= NKO_RANGE_END;
5
+ }
6
+ /** True if the text contains at least one N'Ko character. */
7
+ export function containsNko(text) {
8
+ for (const ch of text) {
9
+ if (isNkoCodePoint(ch.codePointAt(0)))
10
+ return true;
11
+ }
12
+ return false;
13
+ }
14
+ /**
15
+ * True if every letter of the text is N'Ko. Spaces, digits and
16
+ * punctuation are ignored.
17
+ */
18
+ export function isNko(text) {
19
+ let letters = 0;
20
+ for (const ch of text) {
21
+ const cp = ch.codePointAt(0);
22
+ if (isNkoCodePoint(cp)) {
23
+ letters++;
24
+ continue;
25
+ }
26
+ if (/\p{L}/u.test(ch))
27
+ return false;
28
+ }
29
+ return letters > 0;
30
+ }
31
+ /**
32
+ * Puts combining marks in canonical order (nasalization before tone)
33
+ * so that two spellings of the same word compare equal.
34
+ */
35
+ export function normalizeNko(text) {
36
+ return text.normalize("NFC");
37
+ }
38
+ /** Removes tone marks, keeps nasalization. Useful for search. */
39
+ export function stripTones(text) {
40
+ let out = "";
41
+ for (const ch of text) {
42
+ if (ch in TONE_MARKS)
43
+ continue;
44
+ out += ch;
45
+ }
46
+ return out;
47
+ }
48
+ /** Removes tone marks and nasalization. */
49
+ export function stripDiacritics(text) {
50
+ return stripTones(text).split(NASALIZATION).join("");
51
+ }
52
+ /** ߁߉߄߉ → 1949 */
53
+ export function toLatinDigits(text) {
54
+ return text.replace(/[\u07C0-\u07C9]/g, (d) => String(d.charCodeAt(0) - NKO_DIGIT_ZERO));
55
+ }
56
+ /** 1949 → ߁߉߄߉ */
57
+ export function toNkoDigits(text) {
58
+ return text.replace(/[0-9]/g, (d) => String.fromCharCode(NKO_DIGIT_ZERO + Number(d)));
59
+ }
60
+ /**
61
+ * Wraps N'Ko text in Unicode directional isolates (RLI … PDI) so it
62
+ * displays right-to-left correctly inside left-to-right text, as the
63
+ * W3C recommends.
64
+ */
65
+ export function isolateRtl(text) {
66
+ return `\u2067${text}\u2069`;
67
+ }
@@ -0,0 +1,28 @@
1
+ export interface ToLatinOptions {
2
+ /**
3
+ * "none" (default): no tones, like everyday Latin Bambara.
4
+ * "accents": tones as accents (á high, à low, ǎ rising).
5
+ */
6
+ tones?: "none" | "accents";
7
+ /**
8
+ * With tones: "accents", also write the default short falling tone
9
+ * (unmarked in N'Ko) as â. Off by default.
10
+ */
11
+ markFalling?: boolean;
12
+ /** Convert N'Ko digits to 0-9. Default true. */
13
+ digits?: boolean;
14
+ }
15
+ export interface Warning {
16
+ /** Index of the unit in the source text (in code points). */
17
+ index: number;
18
+ char: string;
19
+ message: string;
20
+ }
21
+ export interface ToLatinResult {
22
+ text: string;
23
+ warnings: Warning[];
24
+ }
25
+ /** N'Ko → Latin Bambara, with warnings for uncertain letters. */
26
+ export declare function toLatinDetailed(source: string, options?: ToLatinOptions): ToLatinResult;
27
+ /** N'Ko → Latin Bambara. */
28
+ export declare function toLatin(source: string, options?: ToLatinOptions): string;
@@ -0,0 +1,123 @@
1
+ import { AMBIGUOUS_LETTERS, CONSONANTS, DAGBASINNA, DOUBLE_DOT_ABOVE, DROPPED, LATIN_TONE_ACCENTS, NASALIZATION, PUNCTUATION, SYLLABIC_N, TONE_MARKS, VOWELS, } from "./chars.js";
2
+ import { toLatinDigits } from "./text.js";
3
+ function tokenize(source) {
4
+ const chars = Array.from(source.normalize("NFC"));
5
+ const units = [];
6
+ for (let i = 0; i < chars.length; i++) {
7
+ const ch = chars[i];
8
+ if (ch in VOWELS || ch === SYLLABIC_N) {
9
+ let tone;
10
+ let nasal = false;
11
+ while (i + 1 < chars.length) {
12
+ const next = chars[i + 1];
13
+ if (next in TONE_MARKS)
14
+ tone = TONE_MARKS[next];
15
+ else if (next === NASALIZATION)
16
+ nasal = true;
17
+ else if (next === DOUBLE_DOT_ABOVE) {
18
+ /* ignored on vowels */
19
+ }
20
+ else
21
+ break;
22
+ i++;
23
+ }
24
+ units.push(ch === SYLLABIC_N
25
+ ? { kind: "syllabicN", tone, nasal, index: i }
26
+ : { kind: "vowel", base: VOWELS[ch], tone, nasal, index: i });
27
+ }
28
+ else if (ch in CONSONANTS) {
29
+ let dotted = false;
30
+ while (i + 1 < chars.length && chars[i + 1] === DOUBLE_DOT_ABOVE) {
31
+ dotted = true;
32
+ i++;
33
+ }
34
+ units.push({ kind: "consonant", base: ch, dotted, index: i });
35
+ }
36
+ else if (ch === DAGBASINNA) {
37
+ units.push({ kind: "noVowel", index: i });
38
+ }
39
+ else if (DROPPED.has(ch)) {
40
+ continue;
41
+ }
42
+ else {
43
+ units.push({ kind: "other", text: PUNCTUATION[ch] ?? ch, index: i });
44
+ }
45
+ }
46
+ return units;
47
+ }
48
+ function accentFor(tone, opts) {
49
+ if (opts.tones !== "accents")
50
+ return "";
51
+ if (!tone)
52
+ return opts.markFalling ? LATIN_TONE_ACCENTS.falling : "";
53
+ return LATIN_TONE_ACCENTS[tone.tone];
54
+ }
55
+ function writeVowel(base, tone, nasal, opts) {
56
+ const accent = accentFor(tone, opts);
57
+ const long = tone?.long ? base : "";
58
+ return base + accent + long + (nasal ? "n" : "");
59
+ }
60
+ /**
61
+ * In N'Ko, when two syllables in a row share the same vowel, the first
62
+ * vowel is not written: ߓߡߊߣߊ߲ is read "bamanan". This finds the vowel
63
+ * a bare consonant borrows from the next syllable.
64
+ */
65
+ function borrowedVowel(units, from) {
66
+ const next = units[from + 1];
67
+ if (!next || next.kind !== "consonant")
68
+ return undefined;
69
+ for (let j = from + 1; j < units.length; j++) {
70
+ const u = units[j];
71
+ if (u.kind === "vowel")
72
+ return u;
73
+ if (u.kind !== "consonant")
74
+ return undefined;
75
+ }
76
+ return undefined;
77
+ }
78
+ /** N'Ko → Latin Bambara, with warnings for uncertain letters. */
79
+ export function toLatinDetailed(source, options = {}) {
80
+ const opts = { tones: "none", digits: true, ...options };
81
+ const units = tokenize(source);
82
+ const warnings = [];
83
+ let out = "";
84
+ units.forEach((u, idx) => {
85
+ switch (u.kind) {
86
+ case "vowel":
87
+ out += writeVowel(u.base, u.tone, u.nasal, opts);
88
+ break;
89
+ case "syllabicN":
90
+ out += "n" + accentFor(u.tone, opts) + (u.nasal ? "n" : "");
91
+ break;
92
+ case "consonant": {
93
+ out += CONSONANTS[u.base];
94
+ if (AMBIGUOUS_LETTERS.has(u.base) || u.dotted) {
95
+ warnings.push({
96
+ index: u.index,
97
+ char: u.base,
98
+ message: u.dotted
99
+ ? "Letter with double dot (borrowed sound): check the reading."
100
+ : "This letter can be read several ways depending on the dialect.",
101
+ });
102
+ }
103
+ const borrowed = borrowedVowel(units, idx);
104
+ if (borrowed && borrowed.kind === "vowel") {
105
+ out += writeVowel(borrowed.base, borrowed.tone, false, opts);
106
+ }
107
+ break;
108
+ }
109
+ case "noVowel":
110
+ break;
111
+ case "other":
112
+ out += u.text;
113
+ break;
114
+ }
115
+ });
116
+ if (opts.digits)
117
+ out = toLatinDigits(out);
118
+ return { text: out.normalize("NFC"), warnings };
119
+ }
120
+ /** N'Ko → Latin Bambara. */
121
+ export function toLatin(source, options = {}) {
122
+ return toLatinDetailed(source, options).text;
123
+ }
@@ -0,0 +1,26 @@
1
+ import type { Warning } from "./toLatin.js";
2
+ export interface ToNkoOptions {
3
+ /** Convert 0-9 to N'Ko digits. Default true. */
4
+ digits?: boolean;
5
+ }
6
+ export interface ToNkoResult {
7
+ text: string;
8
+ warnings: Warning[];
9
+ /**
10
+ * Number of vowels written without a tone mark because the Latin
11
+ * text did not give the tone. A fluent writer has to add them.
12
+ */
13
+ missingTones: number;
14
+ }
15
+ /**
16
+ * Latin Bambara → N'Ko, assisted mode.
17
+ *
18
+ * Everyday Latin Bambara does not write tones, but N'Ko must. Tones
19
+ * given as accents (á à ǎ â) are converted; every other vowel is left
20
+ * unmarked and counted in `missingTones` so a person can finish the job.
21
+ * All vowels are written in full (the N'Ko rule that drops a repeated
22
+ * vowel is not applied yet).
23
+ */
24
+ export declare function toNkoDetailed(source: string, options?: ToNkoOptions): ToNkoResult;
25
+ /** Latin Bambara → N'Ko (assisted mode, see toNkoDetailed). */
26
+ export declare function toNko(source: string, options?: ToNkoOptions): string;
package/dist/toNko.js ADDED
@@ -0,0 +1,179 @@
1
+ import { NASALIZATION, SYLLABIC_N } from "./chars.js";
2
+ import { toNkoDigits } from "./text.js";
3
+ const LATIN_VOWELS = {
4
+ a: "\u07CA",
5
+ e: "\u07CB",
6
+ i: "\u07CC",
7
+ "ɛ": "\u07CD",
8
+ u: "\u07CE",
9
+ o: "\u07CF",
10
+ "ɔ": "\u07D0",
11
+ };
12
+ const LATIN_CONSONANTS = {
13
+ b: "\u07D3",
14
+ p: "\u07D4",
15
+ t: "\u07D5",
16
+ j: "\u07D6",
17
+ c: "\u07D7",
18
+ d: "\u07D8",
19
+ r: "\u07D9",
20
+ s: "\u07DB",
21
+ g: "\u07DC",
22
+ f: "\u07DD",
23
+ k: "\u07DE",
24
+ l: "\u07DF",
25
+ m: "\u07E1",
26
+ "ɲ": "\u07E2",
27
+ n: "\u07E3",
28
+ h: "\u07E4",
29
+ w: "\u07E5",
30
+ y: "\u07E6",
31
+ };
32
+ const PUNCT = {
33
+ ",": "\u07F8",
34
+ "!": "\u07F9",
35
+ "?": "\u061F",
36
+ ";": "\u061B",
37
+ };
38
+ const ACCENT_TONES = {
39
+ "\u0301": "high",
40
+ "\u0300": "low",
41
+ "\u030C": "rising",
42
+ "\u0302": "falling",
43
+ };
44
+ const SHORT_MARKS = {
45
+ high: "\u07EB",
46
+ low: "\u07EC",
47
+ rising: "\u07ED",
48
+ falling: "", // short falling is the unmarked form
49
+ };
50
+ const LONG_MARKS = {
51
+ high: "\u07EF",
52
+ low: "\u07F0",
53
+ rising: "\u07F1",
54
+ falling: "\u07EE",
55
+ };
56
+ const isVowel = (c) => c !== undefined && c in LATIN_VOWELS;
57
+ const isLetter = (c) => c !== undefined && /\p{L}/u.test(c);
58
+ /**
59
+ * Latin Bambara → N'Ko, assisted mode.
60
+ *
61
+ * Everyday Latin Bambara does not write tones, but N'Ko must. Tones
62
+ * given as accents (á à ǎ â) are converted; every other vowel is left
63
+ * unmarked and counted in `missingTones` so a person can finish the job.
64
+ * All vowels are written in full (the N'Ko rule that drops a repeated
65
+ * vowel is not applied yet).
66
+ */
67
+ export function toNkoDetailed(source, options = {}) {
68
+ const opts = { digits: true, ...options };
69
+ const chars = Array.from(source.normalize("NFD").toLowerCase());
70
+ const warnings = [];
71
+ let missingTones = 0;
72
+ let out = "";
73
+ const readTone = (i) => {
74
+ let tone;
75
+ while (i < chars.length && ACCENT_TONES[chars[i]] !== undefined) {
76
+ tone = ACCENT_TONES[chars[i]];
77
+ i++;
78
+ }
79
+ return [tone, i];
80
+ };
81
+ let i = 0;
82
+ while (i < chars.length) {
83
+ const c = chars[i];
84
+ const prev = chars[i - 1];
85
+ if (isVowel(c)) {
86
+ const start = i;
87
+ let [tone, j] = readTone(i + 1);
88
+ let long = false;
89
+ if (chars[j] === c) {
90
+ long = true;
91
+ const [tone2, k] = readTone(j + 1);
92
+ tone = tone ?? tone2;
93
+ j = k;
94
+ }
95
+ let nasal = false;
96
+ if (chars[j] === "n" && !isVowel(chars[j + 1]) && chars[j + 1] !== "y") {
97
+ nasal = true;
98
+ j++;
99
+ }
100
+ let mark = "";
101
+ if (tone)
102
+ mark = long ? LONG_MARKS[tone] : SHORT_MARKS[tone];
103
+ else {
104
+ missingTones++;
105
+ if (long) {
106
+ warnings.push({
107
+ index: start,
108
+ char: c,
109
+ message: "Long vowel without a tone: the tone mark must be added by hand.",
110
+ });
111
+ }
112
+ }
113
+ out += LATIN_VOWELS[c] + (nasal ? NASALIZATION : "") + mark;
114
+ i = j;
115
+ continue;
116
+ }
117
+ // Syllabic n: a word-initial n before a consonant, or n alone.
118
+ if (c === "n" && !isLetter(prev) && !isVowel(chars[i + 1]) && chars[i + 1] !== "y") {
119
+ const [tone, j] = readTone(i + 1);
120
+ out += SYLLABIC_N + (tone ? SHORT_MARKS[tone] : "");
121
+ i = j;
122
+ continue;
123
+ }
124
+ const two = c + (chars[i + 1] ?? "");
125
+ if (two === "ny" && isVowel(chars[i + 2])) {
126
+ out += "\u07E2";
127
+ i += 2;
128
+ continue;
129
+ }
130
+ if (two === "rr") {
131
+ out += "\u07DA";
132
+ i += 2;
133
+ continue;
134
+ }
135
+ if (two === "gb") {
136
+ out += "\u07DC";
137
+ i += 2;
138
+ continue;
139
+ }
140
+ if (two === "sh") {
141
+ warnings.push({ index: i, char: "sh", message: "'sh' written as \u07DB (s): check." });
142
+ out += "\u07DB";
143
+ i += 2;
144
+ continue;
145
+ }
146
+ if (c === "ŋ") {
147
+ warnings.push({ index: i, char: c, message: "'ŋ' written as \u07D2: check." });
148
+ out += SYLLABIC_N;
149
+ i++;
150
+ continue;
151
+ }
152
+ if (c in LATIN_CONSONANTS) {
153
+ out += LATIN_CONSONANTS[c];
154
+ i++;
155
+ continue;
156
+ }
157
+ if (c in PUNCT) {
158
+ out += PUNCT[c];
159
+ i++;
160
+ continue;
161
+ }
162
+ if (isLetter(c)) {
163
+ warnings.push({
164
+ index: i,
165
+ char: c,
166
+ message: `No N'Ko letter for '${c}' yet: left as is.`,
167
+ });
168
+ }
169
+ out += c;
170
+ i++;
171
+ }
172
+ if (opts.digits)
173
+ out = toNkoDigits(out);
174
+ return { text: out.normalize("NFC"), warnings, missingTones };
175
+ }
176
+ /** Latin Bambara → N'Ko (assisted mode, see toNkoDetailed). */
177
+ export function toNko(source, options = {}) {
178
+ return toNkoDetailed(source, options).text;
179
+ }
package/package.json CHANGED
@@ -1,6 +1,49 @@
1
1
  {
2
2
  "name": "nko-kit",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "N'Ko and Bambara toolkit: N'Ko ↔ Latin transliteration, tones, digits, RTL helpers. Zero dependencies.",
5
+ "main": "dist/index.js",
6
+ "directories": {
7
+ "test": "test"
8
+ },
9
+ "scripts": {
10
+ "build": "tsc",
11
+ "test": "vitest run",
12
+ "prepublishOnly": "npm run build && npm test"
13
+ },
14
+ "keywords": [
15
+ "nko",
16
+ "n'ko",
17
+ "bambara",
18
+ "bamanankan",
19
+ "manding",
20
+ "mali",
21
+ "transliteration",
22
+ "rtl",
23
+ "africa"
24
+ ],
25
+ "author": "Hamed Domo Ouologuem",
26
+ "license": "MIT",
27
+ "devDependencies": {
28
+ "typescript": "^5.9.3",
29
+ "vitest": "^2.1.9"
30
+ },
31
+ "type": "module",
32
+ "types": "dist/index.d.ts",
33
+ "exports": {
34
+ ".": {
35
+ "types": "./dist/index.d.ts",
36
+ "import": "./dist/index.js"
37
+ }
38
+ },
39
+ "files": [
40
+ "dist"
41
+ ],
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "https://github.com/MomoOuologuem/nko-kit"
45
+ },
46
+ "engines": {
47
+ "node": ">=18"
48
+ }
49
+ }