nko-kit 0.1.0 → 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 +34 -7
- package/dist/cjs/chars.d.ts +38 -0
- package/dist/cjs/chars.js +100 -0
- package/dist/cjs/index.d.ts +5 -0
- package/dist/cjs/index.js +21 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/search.d.ts +13 -0
- package/dist/cjs/search.js +33 -0
- package/dist/cjs/text.d.ts +36 -0
- package/dist/cjs/text.js +132 -0
- package/dist/cjs/toLatin.d.ts +31 -0
- package/dist/cjs/toLatin.js +128 -0
- package/dist/cjs/toNko.d.ts +48 -0
- package/dist/cjs/toNko.js +246 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/search.d.ts +13 -0
- package/dist/search.js +30 -0
- package/dist/text.d.ts +10 -0
- package/dist/text.js +54 -0
- package/dist/toLatin.d.ts +4 -1
- package/dist/toLatin.js +4 -3
- package/dist/toNko.d.ts +24 -2
- package/dist/toNko.js +140 -77
- package/package.json +32 -21
package/README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
# nko-kit ߒߞߏ
|
|
2
2
|
|
|
3
|
+
[](https://github.com/MomoOuologuem/nko-kit/actions/workflows/ci.yml) [](https://www.npmjs.com/package/nko-kit)
|
|
4
|
+
|
|
3
5
|
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
6
|
|
|
5
7
|
*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
8
|
|
|
7
|
-
> ⚠️ **Version 0.
|
|
9
|
+
> ⚠️ **Version 0.2, à 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
10
|
|
|
9
11
|
## Pourquoi
|
|
10
12
|
|
|
@@ -16,19 +18,30 @@ Le N'Ko est très utilisé en ligne, notamment dans les groupes WhatsApp et Tele
|
|
|
16
18
|
npm install nko-kit
|
|
17
19
|
```
|
|
18
20
|
|
|
21
|
+
Le paquet se charge avec `import` (ESM) comme avec `require` (CommonJS) et n'utilise aucune API propre à Node.
|
|
22
|
+
|
|
19
23
|
## Utilisation
|
|
20
24
|
|
|
21
25
|
```ts
|
|
22
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
toLatin, toNko, toNkoDetailed, isNko, toNkoDigits, isolateRtl, searchKey, textDirection,
|
|
28
|
+
} from "nko-kit";
|
|
29
|
+
// ou, en CommonJS : const { toLatin } = require("nko-kit");
|
|
23
30
|
|
|
24
31
|
toLatin("ߒߞߏ"); // "nko"
|
|
25
32
|
toLatin("ߓߡߊߣߊ߲ߞߊ߲"); // "bamanankan" (la voyelle non répétée est restituée)
|
|
26
33
|
toLatin("ߓߊ߰", { tones: "accents" }); // "bàa"
|
|
27
34
|
|
|
28
35
|
toNko("bá"); // "ߓߊ߫"
|
|
36
|
+
toNko("bolo", { elideVowels: true }); // "ߓߟߏ" (voyelle non répétée)
|
|
37
|
+
toNko("sèbèn", { legacyLatin: true }); // comme toNko("sɛbɛn")
|
|
29
38
|
toNkoDetailed("bamanankan");
|
|
30
39
|
// { text: "ߓߊߡߊߣߊ߲ߞߊ߲", missingTones: 4, warnings: [] }
|
|
31
40
|
|
|
41
|
+
searchKey("ߓߡߊߣߊ߲ߞߊ߲"); // "bamanankan"
|
|
42
|
+
searchKey("Bámànànkàn"); // "bamanankan" : même clé dans les deux écritures
|
|
43
|
+
textDirection("ߒߞߏ"); // "rtl"
|
|
44
|
+
|
|
32
45
|
isNko("ߒߞߏ"); // true
|
|
33
46
|
toNkoDigits("1949"); // "߁߉߄߉"
|
|
34
47
|
isolateRtl("ߒߞߏ"); // texte entouré d'isolats RTL pour l'affichage
|
|
@@ -38,18 +51,26 @@ isolateRtl("ߒߞߏ"); // texte entouré d'isolats RTL pour l'affichag
|
|
|
38
51
|
|
|
39
52
|
**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
53
|
|
|
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
|
|
54
|
+
**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 toutes les voyelles par défaut. Avec `elideVowels: true`, il applique la règle telle que la décrivent les notes de r12a : « bolo » donne ߓߟߏ, mais « fafa » garde ses deux voyelles, car les deux consonnes sont identiques. Là où la source ne dit rien (tons différents, voyelles nasales ou longues), il garde la voyelle. Sans tons, il signale par un avertissement que les deux tons pourraient différer.
|
|
42
55
|
|
|
43
56
|
**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
57
|
|
|
58
|
+
**L'ancienne orthographe.** Des textes plus anciens écrivent è pour ɛ et ò pour ɔ. Avec `legacyLatin: true`, `toNko` les lit ainsi. L'accent grave sur e et o ne marque alors plus un ton bas.
|
|
59
|
+
|
|
60
|
+
**La recherche.** `searchKey` donne la même clé à un mot, qu'il soit écrit en N'Ko ou en latin, avec ou sans tons, avec ɛ, ɔ, ɲ ou avec e, o, ny. Comparez la clé de la recherche à celle du texte, jamais les textes eux-mêmes.
|
|
61
|
+
|
|
62
|
+
**L'affichage.** `textDirection` indique si un texte se lit de droite à gauche, comme `dir="auto"` en HTML : utile pour aligner une bulle de discussion. Les chiffres N'Ko s'écrivent eux aussi de droite à gauche. `isolateRtl` empêche un mot en N'Ko de bousculer la phrase en français qui l'entoure.
|
|
63
|
+
|
|
45
64
|
## API
|
|
46
65
|
|
|
47
66
|
| Fonction | Rôle |
|
|
48
67
|
|---|---|
|
|
49
68
|
| `toLatin(texte, options?)` | N'Ko → latin. `tones: "none"` (défaut) ou `"accents"` |
|
|
50
69
|
| `toLatinDetailed(texte, options?)` | Pareil, avec la liste des avertissements |
|
|
51
|
-
| `toNko(texte, options?)` | Latin → N'Ko, mode
|
|
70
|
+
| `toNko(texte, options?)` | Latin → N'Ko, mode assisté. Options `elideVowels`, `legacyLatin`, `digits` |
|
|
52
71
|
| `toNkoDetailed(texte, options?)` | Pareil, avec `missingTones` et les avertissements |
|
|
72
|
+
| `searchKey(texte)` | Clé de recherche commune au N'Ko et au latin |
|
|
73
|
+
| `textDirection(texte)` | `"rtl"`, `"ltr"` ou `"neutral"`, d'après le premier caractère fort |
|
|
53
74
|
| `isNko(texte)`, `containsNko(texte)` | Détection du N'Ko |
|
|
54
75
|
| `stripTones(texte)`, `stripDiacritics(texte)` | Retire les tons (et la nasalisation), utile pour la recherche |
|
|
55
76
|
| `normalizeNko(texte)` | Remet les signes combinés dans l'ordre canonique |
|
|
@@ -59,11 +80,13 @@ isolateRtl("ߒߞߏ"); // texte entouré d'isolats RTL pour l'affichag
|
|
|
59
80
|
## Feuille de route
|
|
60
81
|
|
|
61
82
|
- [ ] Relecture complète des tables par des personnes qui écrivent le N'Ko
|
|
62
|
-
- [
|
|
83
|
+
- [x] Appliquer la règle de la voyelle non répétée dans `toNko` (option `elideVowels`, à faire valider)
|
|
63
84
|
- [ ] Composant React de clavier N'Ko
|
|
64
85
|
- [ ] Dictionnaire de tons pour les mots courants (licence des sources à vérifier)
|
|
65
86
|
- [ ] Prise en charge du maninka et du dioula
|
|
66
87
|
|
|
88
|
+
Les changements de chaque version sont décrits dans [CHANGELOG.md](CHANGELOG.md).
|
|
89
|
+
|
|
67
90
|
## Contribuer
|
|
68
91
|
|
|
69
92
|
Les contributions sont les bienvenues, surtout de la part des personnes qui lisent et écrivent le N'Ko. Voir [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
@@ -71,9 +94,10 @@ Les contributions sont les bienvenues, surtout de la part des personnes qui lise
|
|
|
71
94
|
## Sources
|
|
72
95
|
|
|
73
96
|
- [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/
|
|
97
|
+
- [Notes sur l'orthographe N'Ko, r12a / W3C](https://r12a.github.io/scripts/nkoo/nqo.html)
|
|
75
98
|
- [Notes sur l'orthographe bambara en alphabet latin, r12a](https://r12a.github.io/scripts/latn/bm)
|
|
76
99
|
- [N'Ko Script Resources, W3C](https://www.w3.org/International/afrlreq/nko/)
|
|
100
|
+
- [Bambara's Latin Alphabet, An ka taa](https://kalan.ankataa.com/bambara-beg/grammar-i/bambaras-latin-alphabet) (ancienne orthographe è, ò)
|
|
77
101
|
|
|
78
102
|
---
|
|
79
103
|
|
|
@@ -83,9 +107,12 @@ Les contributions sont les bienvenues, surtout de la part des personnes qui lise
|
|
|
83
107
|
|
|
84
108
|
- `toLatin` converts N'Ko to Latin Bambara, restoring the vowel N'Ko does not repeat (ߓߡߊߣߊ߲ → *bamanan*), with tones dropped or written as accents.
|
|
85
109
|
- `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.
|
|
110
|
+
- `toNko` options: `elideVowels` drops a repeated vowel the N'Ko way ("bolo" → ߓߟߏ), `legacyLatin` reads the older spellings è and ò as ɛ and ɔ.
|
|
111
|
+
- `searchKey` gives the same search key to N'Ko and Latin spellings, with or without tones; `textDirection` tells whether a text runs right-to-left, like `dir="auto"`.
|
|
86
112
|
- Helpers for detection, tone stripping, digits and RTL isolation.
|
|
113
|
+
- Works with `import` (ESM) and `require` (CommonJS).
|
|
87
114
|
|
|
88
|
-
This is version 0.
|
|
115
|
+
This is version 0.2. 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
116
|
|
|
90
117
|
## Licence
|
|
91
118
|
|
|
@@ -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>>;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* N'Ko characters (Unicode block U+07C0–U+07FF) and their Latin
|
|
4
|
+
* correspondences in the Bambara (Bamanankan) orthography.
|
|
5
|
+
*
|
|
6
|
+
* Sources: Unicode code chart U+07C0, W3C N'Ko notes (r12a).
|
|
7
|
+
* The Latin values follow the official Malian orthography.
|
|
8
|
+
* Every row should be checked by fluent N'Ko writers: open an issue
|
|
9
|
+
* if something is wrong.
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.LATIN_TONE_ACCENTS = exports.DROPPED = exports.PUNCTUATION = exports.DOUBLE_DOT_ABOVE = exports.NASALIZATION = exports.TONE_MARKS = exports.AMBIGUOUS_LETTERS = exports.DAGBASINNA = exports.SYLLABIC_N = exports.CONSONANTS = exports.VOWELS = exports.NKO_RANGE_END = exports.NKO_RANGE_START = void 0;
|
|
13
|
+
exports.NKO_RANGE_START = 0x07c0;
|
|
14
|
+
exports.NKO_RANGE_END = 0x07ff;
|
|
15
|
+
/** Vowels: N'Ko → Latin. */
|
|
16
|
+
exports.VOWELS = {
|
|
17
|
+
"\u07CA": "a", // ߊ
|
|
18
|
+
"\u07CB": "e", // ߋ
|
|
19
|
+
"\u07CC": "i", // ߌ
|
|
20
|
+
"\u07CD": "ɛ", // ߍ
|
|
21
|
+
"\u07CE": "u", // ߎ
|
|
22
|
+
"\u07CF": "o", // ߏ
|
|
23
|
+
"\u07D0": "ɔ", // ߐ
|
|
24
|
+
};
|
|
25
|
+
/** Consonants: N'Ko → Latin. */
|
|
26
|
+
exports.CONSONANTS = {
|
|
27
|
+
"\u07D3": "b", // ߓ
|
|
28
|
+
"\u07D4": "p", // ߔ
|
|
29
|
+
"\u07D5": "t", // ߕ
|
|
30
|
+
"\u07D6": "j", // ߖ
|
|
31
|
+
"\u07D7": "c", // ߗ
|
|
32
|
+
"\u07D8": "d", // ߘ
|
|
33
|
+
"\u07D9": "r", // ߙ
|
|
34
|
+
"\u07DA": "rr", // ߚ
|
|
35
|
+
"\u07DB": "s", // ߛ
|
|
36
|
+
"\u07DC": "g", // ߜ (gb in Maninka; read g in Bambara)
|
|
37
|
+
"\u07DD": "f", // ߝ
|
|
38
|
+
"\u07DE": "k", // ߞ
|
|
39
|
+
"\u07DF": "l", // ߟ
|
|
40
|
+
"\u07E0": "n", // ߠ na woloso
|
|
41
|
+
"\u07E1": "m", // ߡ
|
|
42
|
+
"\u07E2": "ɲ", // ߢ
|
|
43
|
+
"\u07E3": "n", // ߣ
|
|
44
|
+
"\u07E4": "h", // ߤ
|
|
45
|
+
"\u07E5": "w", // ߥ
|
|
46
|
+
"\u07E6": "y", // ߦ
|
|
47
|
+
"\u07E7": "ɲ", // ߧ nya woloso
|
|
48
|
+
"\u07E8": "j", // ߨ jona ja (rare)
|
|
49
|
+
"\u07E9": "c", // ߩ jona cha (rare)
|
|
50
|
+
"\u07EA": "r", // ߪ jona ra (rare)
|
|
51
|
+
};
|
|
52
|
+
/** Syllabic nasal ߒ (n'ko, "I"). */
|
|
53
|
+
exports.SYLLABIC_N = "\u07D2";
|
|
54
|
+
/** Dagbasinna ߑ: explicitly marks the absence of a vowel. */
|
|
55
|
+
exports.DAGBASINNA = "\u07D1";
|
|
56
|
+
/** Letters whose Latin reading depends on dialect or context. */
|
|
57
|
+
exports.AMBIGUOUS_LETTERS = new Set([
|
|
58
|
+
"\u07DC", // ߜ g / gb / w (e.g. jɛ́, gɛ̀lɛn, woló share it)
|
|
59
|
+
"\u07E8",
|
|
60
|
+
"\u07E9",
|
|
61
|
+
"\u07EA",
|
|
62
|
+
]);
|
|
63
|
+
/** Combining tone marks. A vowel with no mark is short and falling. */
|
|
64
|
+
exports.TONE_MARKS = {
|
|
65
|
+
"\u07EB": { tone: "high", long: false }, // ߫
|
|
66
|
+
"\u07EC": { tone: "low", long: false }, // ߬
|
|
67
|
+
"\u07ED": { tone: "rising", long: false }, // ߭
|
|
68
|
+
"\u07EE": { tone: "falling", long: true }, // ߮
|
|
69
|
+
"\u07EF": { tone: "high", long: true }, // ߯
|
|
70
|
+
"\u07F0": { tone: "low", long: true }, // ߰
|
|
71
|
+
"\u07F1": { tone: "rising", long: true }, // ߱
|
|
72
|
+
};
|
|
73
|
+
/** Combining nasalization mark ߲. */
|
|
74
|
+
exports.NASALIZATION = "\u07F2";
|
|
75
|
+
/** Combining double dot above ߳ (used for borrowed sounds). */
|
|
76
|
+
exports.DOUBLE_DOT_ABOVE = "\u07F3";
|
|
77
|
+
/** Punctuation and symbols: N'Ko → Latin. */
|
|
78
|
+
exports.PUNCTUATION = {
|
|
79
|
+
"\u07F4": "'", // ߴ high tone apostrophe
|
|
80
|
+
"\u07F5": "'", // ߵ low tone apostrophe
|
|
81
|
+
"\u07F8": ",", // ߸ comma
|
|
82
|
+
"\u07F9": "!", // ߹ exclamation mark
|
|
83
|
+
"\u060C": ",", // ، Arabic comma, used in N'Ko text
|
|
84
|
+
"\u061B": ";", // ؛ Arabic semicolon
|
|
85
|
+
"\u061F": "?", // ؟ Arabic question mark
|
|
86
|
+
"\u2E1C": "«", // ⸜ left low paraphrase bracket
|
|
87
|
+
"\u2E1D": "»", // ⸝ right low paraphrase bracket
|
|
88
|
+
};
|
|
89
|
+
/** Characters that carry no Latin equivalent and are dropped. */
|
|
90
|
+
exports.DROPPED = new Set([
|
|
91
|
+
"\u07FA", // ߺ lajanyalan (elongation)
|
|
92
|
+
"\u07FD", // ߽ dantayalan
|
|
93
|
+
]);
|
|
94
|
+
/** Latin combining accents used to write tones. */
|
|
95
|
+
exports.LATIN_TONE_ACCENTS = {
|
|
96
|
+
high: "\u0301", // á
|
|
97
|
+
low: "\u0300", // à
|
|
98
|
+
rising: "\u030C", // ǎ
|
|
99
|
+
falling: "\u0302", // â
|
|
100
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { containsNko, isNko, isolateRtl, normalizeNko, stripDiacritics, stripTones, textDirection, toLatinDigits, toNkoDigits, type TextDirection, } from "./text.js";
|
|
2
|
+
export { searchKey } from "./search.js";
|
|
3
|
+
export { toLatin, toLatinDetailed, type ToLatinOptions, type ToLatinResult, type Warning, } from "./toLatin.js";
|
|
4
|
+
export { toNko, toNkoDetailed, type ToNkoOptions, type ToNkoResult, } from "./toNko.js";
|
|
5
|
+
export type { Tone } from "./chars.js";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toNkoDetailed = exports.toNko = exports.toLatinDetailed = exports.toLatin = exports.searchKey = exports.toNkoDigits = exports.toLatinDigits = exports.textDirection = exports.stripTones = exports.stripDiacritics = exports.normalizeNko = exports.isolateRtl = exports.isNko = exports.containsNko = void 0;
|
|
4
|
+
var text_js_1 = require("./text.js");
|
|
5
|
+
Object.defineProperty(exports, "containsNko", { enumerable: true, get: function () { return text_js_1.containsNko; } });
|
|
6
|
+
Object.defineProperty(exports, "isNko", { enumerable: true, get: function () { return text_js_1.isNko; } });
|
|
7
|
+
Object.defineProperty(exports, "isolateRtl", { enumerable: true, get: function () { return text_js_1.isolateRtl; } });
|
|
8
|
+
Object.defineProperty(exports, "normalizeNko", { enumerable: true, get: function () { return text_js_1.normalizeNko; } });
|
|
9
|
+
Object.defineProperty(exports, "stripDiacritics", { enumerable: true, get: function () { return text_js_1.stripDiacritics; } });
|
|
10
|
+
Object.defineProperty(exports, "stripTones", { enumerable: true, get: function () { return text_js_1.stripTones; } });
|
|
11
|
+
Object.defineProperty(exports, "textDirection", { enumerable: true, get: function () { return text_js_1.textDirection; } });
|
|
12
|
+
Object.defineProperty(exports, "toLatinDigits", { enumerable: true, get: function () { return text_js_1.toLatinDigits; } });
|
|
13
|
+
Object.defineProperty(exports, "toNkoDigits", { enumerable: true, get: function () { return text_js_1.toNkoDigits; } });
|
|
14
|
+
var search_js_1 = require("./search.js");
|
|
15
|
+
Object.defineProperty(exports, "searchKey", { enumerable: true, get: function () { return search_js_1.searchKey; } });
|
|
16
|
+
var toLatin_js_1 = require("./toLatin.js");
|
|
17
|
+
Object.defineProperty(exports, "toLatin", { enumerable: true, get: function () { return toLatin_js_1.toLatin; } });
|
|
18
|
+
Object.defineProperty(exports, "toLatinDetailed", { enumerable: true, get: function () { return toLatin_js_1.toLatinDetailed; } });
|
|
19
|
+
var toNko_js_1 = require("./toNko.js");
|
|
20
|
+
Object.defineProperty(exports, "toNko", { enumerable: true, get: function () { return toNko_js_1.toNko; } });
|
|
21
|
+
Object.defineProperty(exports, "toNkoDetailed", { enumerable: true, get: function () { return toNko_js_1.toNkoDetailed; } });
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A plain key for searching Bambara text whatever its script or spelling.
|
|
3
|
+
*
|
|
4
|
+
* N'Ko is first read as Latin (with `toLatin`). Then tones, accents and
|
|
5
|
+
* case are dropped, ɛ → e, ɔ → o, ɲ → ny, ŋ → ng, apostrophes vanish and
|
|
6
|
+
* every other run of characters that are not letters or digits becomes
|
|
7
|
+
* one space. Compare keys, never raw text:
|
|
8
|
+
*
|
|
9
|
+
* searchKey("ߓߡߊߣߊ߲ߞߊ߲") === "bamanankan"
|
|
10
|
+
* searchKey("Bámànànkàn") === "bamanankan"
|
|
11
|
+
* searchKey("ɲɔgɔn") === "nyogon"
|
|
12
|
+
*/
|
|
13
|
+
export declare function searchKey(text: string): string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.searchKey = searchKey;
|
|
4
|
+
const toLatin_js_1 = require("./toLatin.js");
|
|
5
|
+
/** Letters folded to what a keyboard without them would type. */
|
|
6
|
+
const FOLD = {
|
|
7
|
+
"ɛ": "e",
|
|
8
|
+
"ɔ": "o",
|
|
9
|
+
"ɲ": "ny",
|
|
10
|
+
"ŋ": "ng",
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* A plain key for searching Bambara text whatever its script or spelling.
|
|
14
|
+
*
|
|
15
|
+
* N'Ko is first read as Latin (with `toLatin`). Then tones, accents and
|
|
16
|
+
* case are dropped, ɛ → e, ɔ → o, ɲ → ny, ŋ → ng, apostrophes vanish and
|
|
17
|
+
* every other run of characters that are not letters or digits becomes
|
|
18
|
+
* one space. Compare keys, never raw text:
|
|
19
|
+
*
|
|
20
|
+
* searchKey("ߓߡߊߣߊ߲ߞߊ߲") === "bamanankan"
|
|
21
|
+
* searchKey("Bámànànkàn") === "bamanankan"
|
|
22
|
+
* searchKey("ɲɔgɔn") === "nyogon"
|
|
23
|
+
*/
|
|
24
|
+
function searchKey(text) {
|
|
25
|
+
return (0, toLatin_js_1.toLatin)(text)
|
|
26
|
+
.normalize("NFD")
|
|
27
|
+
.replace(/\p{M}/gu, "")
|
|
28
|
+
.toLowerCase()
|
|
29
|
+
.replace(/[ɛɔɲŋ]/gu, (ch) => FOLD[ch])
|
|
30
|
+
.replace(/['`´‘’ʼ]/gu, "")
|
|
31
|
+
.replace(/[^\p{L}\p{N}]+/gu, " ")
|
|
32
|
+
.trim();
|
|
33
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
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;
|
|
27
|
+
export type TextDirection = "rtl" | "ltr" | "neutral";
|
|
28
|
+
/**
|
|
29
|
+
* Direction of a text from its first strong character, like the HTML
|
|
30
|
+
* attribute dir="auto" and rule P2 of the Unicode bidi algorithm: N'Ko,
|
|
31
|
+
* Arabic, Hebrew, Adlam… give "rtl", Latin and other letters give "ltr".
|
|
32
|
+
* N'Ko and Adlam digits and the marks LRM, RLM and ALM also decide; other
|
|
33
|
+
* digits, punctuation, emoji and text inside directional isolates are
|
|
34
|
+
* skipped. A text with no strong character gives "neutral".
|
|
35
|
+
*/
|
|
36
|
+
export declare function textDirection(text: string): TextDirection;
|
package/dist/cjs/text.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.containsNko = containsNko;
|
|
4
|
+
exports.isNko = isNko;
|
|
5
|
+
exports.normalizeNko = normalizeNko;
|
|
6
|
+
exports.stripTones = stripTones;
|
|
7
|
+
exports.stripDiacritics = stripDiacritics;
|
|
8
|
+
exports.toLatinDigits = toLatinDigits;
|
|
9
|
+
exports.toNkoDigits = toNkoDigits;
|
|
10
|
+
exports.isolateRtl = isolateRtl;
|
|
11
|
+
exports.textDirection = textDirection;
|
|
12
|
+
const chars_js_1 = require("./chars.js");
|
|
13
|
+
const NKO_DIGIT_ZERO = 0x07c0;
|
|
14
|
+
function isNkoCodePoint(cp) {
|
|
15
|
+
return cp >= chars_js_1.NKO_RANGE_START && cp <= chars_js_1.NKO_RANGE_END;
|
|
16
|
+
}
|
|
17
|
+
/** True if the text contains at least one N'Ko character. */
|
|
18
|
+
function containsNko(text) {
|
|
19
|
+
for (const ch of text) {
|
|
20
|
+
if (isNkoCodePoint(ch.codePointAt(0)))
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* True if every letter of the text is N'Ko. Spaces, digits and
|
|
27
|
+
* punctuation are ignored.
|
|
28
|
+
*/
|
|
29
|
+
function isNko(text) {
|
|
30
|
+
let letters = 0;
|
|
31
|
+
for (const ch of text) {
|
|
32
|
+
const cp = ch.codePointAt(0);
|
|
33
|
+
if (isNkoCodePoint(cp)) {
|
|
34
|
+
letters++;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (/\p{L}/u.test(ch))
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
return letters > 0;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Puts combining marks in canonical order (nasalization before tone)
|
|
44
|
+
* so that two spellings of the same word compare equal.
|
|
45
|
+
*/
|
|
46
|
+
function normalizeNko(text) {
|
|
47
|
+
return text.normalize("NFC");
|
|
48
|
+
}
|
|
49
|
+
/** Removes tone marks, keeps nasalization. Useful for search. */
|
|
50
|
+
function stripTones(text) {
|
|
51
|
+
let out = "";
|
|
52
|
+
for (const ch of text) {
|
|
53
|
+
if (ch in chars_js_1.TONE_MARKS)
|
|
54
|
+
continue;
|
|
55
|
+
out += ch;
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
/** Removes tone marks and nasalization. */
|
|
60
|
+
function stripDiacritics(text) {
|
|
61
|
+
return stripTones(text).split(chars_js_1.NASALIZATION).join("");
|
|
62
|
+
}
|
|
63
|
+
/** ߁߉߄߉ → 1949 */
|
|
64
|
+
function toLatinDigits(text) {
|
|
65
|
+
return text.replace(/[\u07C0-\u07C9]/g, (d) => String(d.charCodeAt(0) - NKO_DIGIT_ZERO));
|
|
66
|
+
}
|
|
67
|
+
/** 1949 → ߁߉߄߉ */
|
|
68
|
+
function toNkoDigits(text) {
|
|
69
|
+
return text.replace(/[0-9]/g, (d) => String.fromCharCode(NKO_DIGIT_ZERO + Number(d)));
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Wraps N'Ko text in Unicode directional isolates (RLI … PDI) so it
|
|
73
|
+
* displays right-to-left correctly inside left-to-right text, as the
|
|
74
|
+
* W3C recommends.
|
|
75
|
+
*/
|
|
76
|
+
function isolateRtl(text) {
|
|
77
|
+
return `\u2067${text}\u2069`;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Unicode blocks of right-to-left scripts. Every letter inside them is
|
|
81
|
+
* right-to-left and every letter outside is not (checked against the
|
|
82
|
+
* Unicode 17 character database).
|
|
83
|
+
*/
|
|
84
|
+
const RTL_BLOCKS = [
|
|
85
|
+
[0x0590, 0x08ff], // Hebrew, Arabic, Syriac, Thaana, N'Ko, Samaritan, Mandaic
|
|
86
|
+
[0xfb1d, 0xfdff], // Hebrew and Arabic presentation forms
|
|
87
|
+
[0xfe70, 0xfeff], // Arabic presentation forms B
|
|
88
|
+
[0x10800, 0x10fff], // Garay, Hanifi Rohingya, Yezidi and older scripts
|
|
89
|
+
[0x1e800, 0x1efff], // Adlam, Mende Kikakui, Arabic mathematical letters
|
|
90
|
+
];
|
|
91
|
+
const LETTER = /\p{L}/u;
|
|
92
|
+
/** Modifier letters that are neutral for the bidi algorithm (Unicode 17). */
|
|
93
|
+
const NEUTRAL_LETTER = /[\u02B9\u02BA\u02C6-\u02CF\u02EC\u0374\u2E2F\uA67F\uA717-\uA71F\uA788]/u;
|
|
94
|
+
function isRtlBlock(cp) {
|
|
95
|
+
return RTL_BLOCKS.some(([start, end]) => cp >= start && cp <= end);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Direction of a text from its first strong character, like the HTML
|
|
99
|
+
* attribute dir="auto" and rule P2 of the Unicode bidi algorithm: N'Ko,
|
|
100
|
+
* Arabic, Hebrew, Adlam… give "rtl", Latin and other letters give "ltr".
|
|
101
|
+
* N'Ko and Adlam digits and the marks LRM, RLM and ALM also decide; other
|
|
102
|
+
* digits, punctuation, emoji and text inside directional isolates are
|
|
103
|
+
* skipped. A text with no strong character gives "neutral".
|
|
104
|
+
*/
|
|
105
|
+
function textDirection(text) {
|
|
106
|
+
let isolates = 0;
|
|
107
|
+
for (const ch of text) {
|
|
108
|
+
const cp = ch.codePointAt(0);
|
|
109
|
+
if (cp >= 0x2066 && cp <= 0x2068) {
|
|
110
|
+
isolates++; // LRI, RLI, FSI
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (cp === 0x2069) {
|
|
114
|
+
if (isolates > 0)
|
|
115
|
+
isolates--; // PDI
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (isolates > 0)
|
|
119
|
+
continue;
|
|
120
|
+
if (cp === 0x200e)
|
|
121
|
+
return "ltr"; // LEFT-TO-RIGHT MARK
|
|
122
|
+
if (cp === 0x200f || cp === 0x061c)
|
|
123
|
+
return "rtl"; // RIGHT-TO-LEFT MARK, ARABIC LETTER MARK
|
|
124
|
+
if ((cp >= 0x07c0 && cp <= 0x07c9) || (cp >= 0x1e950 && cp <= 0x1e959)) {
|
|
125
|
+
return "rtl"; // N'Ko and Adlam digits are strong right-to-left
|
|
126
|
+
}
|
|
127
|
+
if (!LETTER.test(ch) || NEUTRAL_LETTER.test(ch))
|
|
128
|
+
continue;
|
|
129
|
+
return isRtlBlock(cp) ? "rtl" : "ltr";
|
|
130
|
+
}
|
|
131
|
+
return "neutral";
|
|
132
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
/**
|
|
17
|
+
* Index of the character the warning is about, counted in code points
|
|
18
|
+
* of the source text after NFC normalization.
|
|
19
|
+
*/
|
|
20
|
+
index: number;
|
|
21
|
+
char: string;
|
|
22
|
+
message: string;
|
|
23
|
+
}
|
|
24
|
+
export interface ToLatinResult {
|
|
25
|
+
text: string;
|
|
26
|
+
warnings: Warning[];
|
|
27
|
+
}
|
|
28
|
+
/** N'Ko → Latin Bambara, with warnings for uncertain letters. */
|
|
29
|
+
export declare function toLatinDetailed(source: string, options?: ToLatinOptions): ToLatinResult;
|
|
30
|
+
/** N'Ko → Latin Bambara. */
|
|
31
|
+
export declare function toLatin(source: string, options?: ToLatinOptions): string;
|