lyric-romanizer 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 +21 -0
- package/README.md +70 -0
- package/dist/detector.d.ts +5 -0
- package/dist/detector.d.ts.map +1 -0
- package/dist/detector.js +41 -0
- package/dist/detector.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/romanizer.d.ts +4 -0
- package/dist/romanizer.d.ts.map +1 -0
- package/dist/romanizer.js +112 -0
- package/dist/romanizer.js.map +1 -0
- package/dist/types.d.ts +20 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/package.json +71 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 David Weng
|
|
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,70 @@
|
|
|
1
|
+
# lyric-romanizer
|
|
2
|
+
|
|
3
|
+
Script detection and local romanization engine for lyrics. Supports Japanese, Chinese, Korean, Cyrillic, Indic scripts (Devanagari, Gujarati, Gurmukhi, Telugu, Kannada, Odia), Tamil, Thai, and Latin.
|
|
4
|
+
|
|
5
|
+
Extracted from [Spotify Karaoke](https://github.com/haroldalan/spotify-karaoke).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install lyric-romanizer
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## API
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import {
|
|
17
|
+
createRomanizer,
|
|
18
|
+
detectScript,
|
|
19
|
+
isLatinScript,
|
|
20
|
+
requiresExternalRomanization,
|
|
21
|
+
} from 'lyric-romanizer';
|
|
22
|
+
|
|
23
|
+
// Subpath import for detector only
|
|
24
|
+
import { detectScript } from 'lyric-romanizer/detector';
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### `detectScript(lines: readonly string[]): ScriptType`
|
|
28
|
+
|
|
29
|
+
Detects the dominant script in the given lines. Returns one of: `japanese`, `chinese`, `korean`, `cyrillic`, `devanagari`, `gujarati`, `gurmukhi`, `telugu`, `kannada`, `odia`, `tamil`, `malayalam`, `bengali`, `arabic`, `hebrew`, `thai`, `latin`, `other`.
|
|
30
|
+
|
|
31
|
+
### `isLatinScript(lines: readonly string[]): boolean`
|
|
32
|
+
|
|
33
|
+
Fast check for whether the text is Latin-only (no non-Latin characters).
|
|
34
|
+
|
|
35
|
+
### `requiresExternalRomanization(script: ScriptType): boolean`
|
|
36
|
+
|
|
37
|
+
Returns `true` for scripts that cannot be romanized locally (`malayalam`, `bengali`, `arabic`, `hebrew`, `other`).
|
|
38
|
+
|
|
39
|
+
### `createRomanizer(options?: { japaneseDictPath?: string }): Romanizer`
|
|
40
|
+
|
|
41
|
+
Creates a romanizer instance. The optional `japaneseDictPath` overrides the default [Kuromoji](https://github.com/takuyaa/kuromoji.js) dictionary CDN path.
|
|
42
|
+
|
|
43
|
+
### `Romanizer.romanizeLine(line: string, options?: { script?: ScriptType }): Promise<string>`
|
|
44
|
+
|
|
45
|
+
Romanizes a single line. If `script` is omitted, it is auto-detected.
|
|
46
|
+
|
|
47
|
+
### `Romanizer.romanizeLines(lines: readonly string[], options?: { script?: ScriptType }): Promise<{ script: ScriptType, lines: string[] }>`
|
|
48
|
+
|
|
49
|
+
Romanizes multiple lines at once.
|
|
50
|
+
|
|
51
|
+
## Supported Local Scripts
|
|
52
|
+
|
|
53
|
+
| Script | Library |
|
|
54
|
+
|--------|---------|
|
|
55
|
+
| Japanese | [@sglkc/kuroshiro](https://github.com/sglkc/kuroshiro-ts) + [kuromoji](https://github.com/takuyaa/kuromoji.js) |
|
|
56
|
+
| Chinese | [pinyin-pro](https://github.com/zh-lx/pinyin-pro) |
|
|
57
|
+
| Korean | [@romanize/korean](https://github.com/kntng/romanize) |
|
|
58
|
+
| Cyrillic (Russian/Ukrainian) | [cyrillic-to-translit-js](https://github.com/greybax/CyrillicToTranslitJS) |
|
|
59
|
+
| Devanagari, Gujarati, Gurmukhi, Telugu, Kannada, Odia | [@indic-transliteration/sanscript](https://github.com/indic-transliteration/sanscript.js) |
|
|
60
|
+
| Tamil | [tamil-romanizer](https://github.com/haroldalan/tamil-romanizer) |
|
|
61
|
+
| Thai | [@dehoist/romanize-thai](https://github.com/Dehoist/Open-Source) |
|
|
62
|
+
| Latin | no-op (returned as-is) |
|
|
63
|
+
|
|
64
|
+
## External Romanization Scripts
|
|
65
|
+
|
|
66
|
+
`malayalam`, `bengali`, `arabic`, `hebrew`, and `other` are marked as external. Use `requiresExternalRomanization(script)` to branch to an API-based romanizer. Calling `romanizeLine`/`romanizeLines` for these throws `UnsupportedRomanizationError`.
|
|
67
|
+
|
|
68
|
+
## License
|
|
69
|
+
|
|
70
|
+
MIT
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ScriptType } from './types.js';
|
|
2
|
+
export declare const NON_LATIN_SCRIPT_RE: RegExp;
|
|
3
|
+
export declare function isLatinScript(lines: readonly string[]): boolean;
|
|
4
|
+
export declare function detectScript(lines: readonly string[]): ScriptType;
|
|
5
|
+
//# sourceMappingURL=detector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detector.d.ts","sourceRoot":"","sources":["../src/detector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAwB7C,eAAO,MAAM,mBAAmB,QAC8E,CAAC;AAE/G,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAG/D;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,UAAU,CAcjE"}
|
package/dist/detector.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const LETTER_RE = /\p{L}/u;
|
|
2
|
+
const SCRIPT_SCORES = [
|
|
3
|
+
['chinese', /[\u4E00-\u9FFF]/g],
|
|
4
|
+
['korean', /[\uAC00-\uD7AF]/g],
|
|
5
|
+
['cyrillic', /[\u0400-\u04FF]/g],
|
|
6
|
+
['devanagari', /[\u0900-\u097F]/g],
|
|
7
|
+
['gujarati', /[\u0A80-\u0AFF]/g],
|
|
8
|
+
['gurmukhi', /[\u0A00-\u0A7F]/g],
|
|
9
|
+
['telugu', /[\u0C00-\u0C7F]/g],
|
|
10
|
+
['kannada', /[\u0C80-\u0CFF]/g],
|
|
11
|
+
['odia', /[\u0B00-\u0B7F]/g],
|
|
12
|
+
['tamil', /[\u0B80-\u0BFF]/g],
|
|
13
|
+
['malayalam', /[\u0D00-\u0D7F]/g],
|
|
14
|
+
['bengali', /[\u0980-\u09FF]/g],
|
|
15
|
+
['arabic', /[\u0600-\u06FF]/g],
|
|
16
|
+
['hebrew', /[\u0590-\u05FF]/g],
|
|
17
|
+
['thai', /[\u0E00-\u0E7F]/g],
|
|
18
|
+
];
|
|
19
|
+
// Keep this range aligned with extension content script behavior for the
|
|
20
|
+
// "latin fast path" check used during mode switching.
|
|
21
|
+
export const NON_LATIN_SCRIPT_RE = /[\u3040-\u30FF\u4E00-\u9FFF\uAC00-\uD7AF\u0400-\u04FF\u0900-\u0D7F\u0600-\u06FF\u0590-\u05FF\u0E00-\u0E7F]/;
|
|
22
|
+
export function isLatinScript(lines) {
|
|
23
|
+
const text = lines.join('');
|
|
24
|
+
return !NON_LATIN_SCRIPT_RE.test(text) && LETTER_RE.test(text);
|
|
25
|
+
}
|
|
26
|
+
export function detectScript(lines) {
|
|
27
|
+
const text = lines.join('');
|
|
28
|
+
// Japanese: any kana is definitive and must be checked before CJK scoring.
|
|
29
|
+
if (/[\u3040-\u30FF]/.test(text))
|
|
30
|
+
return 'japanese';
|
|
31
|
+
let best = ['other', 0];
|
|
32
|
+
for (const [script, pattern] of SCRIPT_SCORES) {
|
|
33
|
+
const score = (text.match(pattern) ?? []).length;
|
|
34
|
+
if (score > best[1])
|
|
35
|
+
best = [script, score];
|
|
36
|
+
}
|
|
37
|
+
if (best[1] > 0)
|
|
38
|
+
return best[0];
|
|
39
|
+
return LETTER_RE.test(text) ? 'latin' : 'other';
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=detector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detector.js","sourceRoot":"","sources":["../src/detector.ts"],"names":[],"mappings":"AAEA,MAAM,SAAS,GAAG,QAAQ,CAAC;AAE3B,MAAM,aAAa,GAAyC;IAC1D,CAAC,SAAS,EAAE,kBAAkB,CAAC;IAC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AI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;QACjD,IAAI,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC;YAAE,IAAI,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC9C,CAAC;IAED,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC;IAChC,OAAO,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;AAClD,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { detectScript, isLatinScript, NON_LATIN_SCRIPT_RE } from './detector.js';
|
|
2
|
+
export { createRomanizer, requiresExternalRomanization } from './romanizer.js';
|
|
3
|
+
export { UnsupportedRomanizationError, type RomanizeOptions, type RomanizeResult, type Romanizer, type RomanizerOptions, type ScriptType, } from './types.js';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACjF,OAAO,EAAE,eAAe,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EACL,4BAA4B,EAC5B,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,UAAU,GAChB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACjF,OAAO,EAAE,eAAe,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAC/E,OAAO,EACL,4BAA4B,GAM7B,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Romanizer, RomanizerOptions, ScriptType } from './types.js';
|
|
2
|
+
export declare function requiresExternalRomanization(script: ScriptType): boolean;
|
|
3
|
+
export declare function createRomanizer(options?: RomanizerOptions): Romanizer;
|
|
4
|
+
//# sourceMappingURL=romanizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"romanizer.d.ts","sourceRoot":"","sources":["../src/romanizer.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAGV,SAAS,EACT,gBAAgB,EAChB,UAAU,EACX,MAAM,YAAY,CAAC;AAwBpB,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAExE;AAsFD,wBAAgB,eAAe,CAAC,OAAO,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAErE"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import Kuroshiro from '@sglkc/kuroshiro';
|
|
2
|
+
import KuromojiAnalyzer from '@sglkc/kuroshiro-analyzer-kuromoji';
|
|
3
|
+
import { pinyin } from 'pinyin-pro';
|
|
4
|
+
import CyrillicToTranslit from 'cyrillic-to-translit-js';
|
|
5
|
+
import Sanscript from '@indic-transliteration/sanscript';
|
|
6
|
+
import { romanize as romanizeKorean } from '@romanize/korean';
|
|
7
|
+
import romanizeThai from '@dehoist/romanize-thai';
|
|
8
|
+
import { romanize as romanizeTamil } from 'tamil-romanizer';
|
|
9
|
+
import { detectScript } from './detector.js';
|
|
10
|
+
import { UnsupportedRomanizationError } from './types.js';
|
|
11
|
+
const DEFAULT_JAPANESE_DICT_PATH = 'https://cdn.jsdelivr.net/npm/kuromoji/dict';
|
|
12
|
+
const EXTERNAL_ROMANIZATION_SCRIPTS = new Set([
|
|
13
|
+
'malayalam',
|
|
14
|
+
'bengali',
|
|
15
|
+
'arabic',
|
|
16
|
+
'hebrew',
|
|
17
|
+
'other',
|
|
18
|
+
]);
|
|
19
|
+
const cyrillicTranslitRu = CyrillicToTranslit({ preset: 'ru' });
|
|
20
|
+
const cyrillicTranslitUk = CyrillicToTranslit({ preset: 'uk' });
|
|
21
|
+
const SANSCRIPT_SCHEME = {
|
|
22
|
+
devanagari: 'devanagari',
|
|
23
|
+
gujarati: 'gujarati',
|
|
24
|
+
gurmukhi: 'gurmukhi',
|
|
25
|
+
telugu: 'telugu',
|
|
26
|
+
kannada: 'kannada',
|
|
27
|
+
odia: 'oriya',
|
|
28
|
+
};
|
|
29
|
+
export function requiresExternalRomanization(script) {
|
|
30
|
+
return EXTERNAL_ROMANIZATION_SCRIPTS.has(script);
|
|
31
|
+
}
|
|
32
|
+
class DefaultRomanizer {
|
|
33
|
+
japaneseDictPath;
|
|
34
|
+
kuroshiroReady = null;
|
|
35
|
+
constructor(options) {
|
|
36
|
+
this.japaneseDictPath = options?.japaneseDictPath ?? DEFAULT_JAPANESE_DICT_PATH;
|
|
37
|
+
}
|
|
38
|
+
async romanizeLine(line, options) {
|
|
39
|
+
if (!line.trim() || !/\p{L}/u.test(line))
|
|
40
|
+
return line;
|
|
41
|
+
const script = options?.script ?? detectScript([line]);
|
|
42
|
+
if (script === 'latin')
|
|
43
|
+
return line;
|
|
44
|
+
if (requiresExternalRomanization(script)) {
|
|
45
|
+
throw new UnsupportedRomanizationError(script);
|
|
46
|
+
}
|
|
47
|
+
switch (script) {
|
|
48
|
+
case 'japanese': {
|
|
49
|
+
const k = await this.getKuroshiro();
|
|
50
|
+
return k.convert(line, { to: 'romaji', mode: 'spaced' });
|
|
51
|
+
}
|
|
52
|
+
case 'chinese':
|
|
53
|
+
return pinyin(line, { toneType: 'symbol', type: 'string' });
|
|
54
|
+
case 'korean':
|
|
55
|
+
return romanizeKorean(line);
|
|
56
|
+
case 'cyrillic':
|
|
57
|
+
return /[іїєґ]/i.test(line)
|
|
58
|
+
? cyrillicTranslitUk.transform(line)
|
|
59
|
+
: cyrillicTranslitRu.transform(line);
|
|
60
|
+
case 'devanagari':
|
|
61
|
+
case 'gujarati':
|
|
62
|
+
case 'gurmukhi':
|
|
63
|
+
case 'telugu':
|
|
64
|
+
case 'kannada':
|
|
65
|
+
case 'odia': {
|
|
66
|
+
const scheme = SANSCRIPT_SCHEME[script];
|
|
67
|
+
if (!scheme)
|
|
68
|
+
throw new Error(`Missing Sanscript scheme mapping for '${script}'.`);
|
|
69
|
+
if (!Sanscript.schemes?.[scheme]) {
|
|
70
|
+
throw new Error(`Sanscript does not support scheme '${scheme}' for '${script}'.`);
|
|
71
|
+
}
|
|
72
|
+
return Sanscript.t(line, scheme, 'iast');
|
|
73
|
+
}
|
|
74
|
+
case 'tamil':
|
|
75
|
+
return romanizeTamil(line);
|
|
76
|
+
case 'thai':
|
|
77
|
+
return romanizeThai(line);
|
|
78
|
+
default:
|
|
79
|
+
throw new UnsupportedRomanizationError(script);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async romanizeLines(lines, options) {
|
|
83
|
+
const script = options?.script ?? detectScript(lines);
|
|
84
|
+
if (requiresExternalRomanization(script)) {
|
|
85
|
+
throw new UnsupportedRomanizationError(script);
|
|
86
|
+
}
|
|
87
|
+
if (script === 'latin') {
|
|
88
|
+
return { script, lines: [...lines] };
|
|
89
|
+
}
|
|
90
|
+
const romanized = await Promise.all(lines.map((line) => this.romanizeLine(line, { script })));
|
|
91
|
+
return { script, lines: romanized };
|
|
92
|
+
}
|
|
93
|
+
async getKuroshiro() {
|
|
94
|
+
if (!this.kuroshiroReady) {
|
|
95
|
+
this.kuroshiroReady = (async () => {
|
|
96
|
+
const instance = new Kuroshiro();
|
|
97
|
+
await instance.init(new KuromojiAnalyzer({
|
|
98
|
+
dictPath: this.japaneseDictPath,
|
|
99
|
+
}));
|
|
100
|
+
return instance;
|
|
101
|
+
})().catch((error) => {
|
|
102
|
+
this.kuroshiroReady = null;
|
|
103
|
+
throw error;
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return this.kuroshiroReady;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
export function createRomanizer(options) {
|
|
110
|
+
return new DefaultRomanizer(options);
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=romanizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"romanizer.js","sourceRoot":"","sources":["../src/romanizer.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,kBAAkB,CAAC;AACzC,OAAO,gBAAgB,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,kBAAkB,MAAM,yBAAyB,CAAC;AACzD,OAAO,SAAS,MAAM,kCAAkC,CAAC;AACzD,OAAO,EAAE,QAAQ,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,YAAY,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,QAAQ,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAQ7C,OAAO,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAC;AAE1D,MAAM,0BAA0B,GAAG,4CAA4C,CAAC;AAChF,MAAM,6BAA6B,GAAG,IAAI,GAAG,CAAa;IACxD,WAAW;IACX,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,OAAO;CACR,CAAC,CAAC;AAEH,MAAM,kBAAkB,GAAG,kBAAkB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;AAChE,MAAM,kBAAkB,GAAG,kBAAkB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;AAEhE,MAAM,gBAAgB,GAAwC;IAC5D,UAAU,EAAE,YAAY;IACxB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EA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AAE,CAAC;YACvB,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,EAAE,CAAC;QACvC,CAAC;QAED,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;QAC9F,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;IACtC,CAAC;IAEO,KAAK,CAAC,YAAY;QACxB,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC;YACzB,IAAI,CAAC,cAAc,GAAG,CAAC,KAAK,IAAI,EAAE;gBAChC,MAAM,QAAQ,GAAG,IAAI,SAAS,EAAE,CAAC;gBACjC,MAAM,QAAQ,CAAC,IAAI,CACjB,IAAI,gBAAgB,CAAC;oBACnB,QAAQ,EAAE,IAAI,CAAC,gBAAgB;iBAChC,CAAC,CACH,CAAC;gBACF,OAAO,QAAQ,CAAC;YAClB,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;gBACnB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;gBAC3B,MAAM,KAAK,CAAC;YACd,CAAC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;CACF;AAED,MAAM,UAAU,eAAe,CAAC,OAA0B;IACxD,OAAO,IAAI,gBAAgB,CAAC,OAAO,CAAC,CAAC;AACvC,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type ScriptType = 'japanese' | 'chinese' | 'korean' | 'cyrillic' | 'devanagari' | 'gujarati' | 'gurmukhi' | 'telugu' | 'kannada' | 'odia' | 'tamil' | 'malayalam' | 'bengali' | 'arabic' | 'hebrew' | 'thai' | 'latin' | 'other';
|
|
2
|
+
export type RomanizerOptions = {
|
|
3
|
+
japaneseDictPath?: string;
|
|
4
|
+
};
|
|
5
|
+
export type RomanizeOptions = {
|
|
6
|
+
script?: ScriptType;
|
|
7
|
+
};
|
|
8
|
+
export type RomanizeResult = {
|
|
9
|
+
script: ScriptType;
|
|
10
|
+
lines: string[];
|
|
11
|
+
};
|
|
12
|
+
export interface Romanizer {
|
|
13
|
+
romanizeLine(line: string, options?: RomanizeOptions): Promise<string>;
|
|
14
|
+
romanizeLines(lines: readonly string[], options?: RomanizeOptions): Promise<RomanizeResult>;
|
|
15
|
+
}
|
|
16
|
+
export declare class UnsupportedRomanizationError extends Error {
|
|
17
|
+
readonly script: ScriptType;
|
|
18
|
+
constructor(script: ScriptType);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,GAClB,UAAU,GACV,SAAS,GACT,QAAQ,GACR,UAAU,GACV,YAAY,GACZ,UAAU,GACV,UAAU,GACV,QAAQ,GACR,SAAS,GACT,MAAM,GACN,OAAO,GACP,WAAW,GACX,SAAS,GACT,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,OAAO,GACP,OAAO,CAAC;AAEZ,MAAM,MAAM,gBAAgB,GAAG;IAC7B,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,CAAC,EAAE,UAAU,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,UAAU,CAAC;IACnB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB,CAAC;AAEF,MAAM,WAAW,SAAS;IACxB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACvE,aAAa,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;CAC7F;AAED,qBAAa,4BAA6B,SAAQ,KAAK;IACrD,SAAgB,MAAM,EAAE,UAAU,CAAC;gBAEvB,MAAM,EAAE,UAAU;CAK/B"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export class UnsupportedRomanizationError extends Error {
|
|
2
|
+
script;
|
|
3
|
+
constructor(script) {
|
|
4
|
+
super(`Script '${script}' requires external romanization.`);
|
|
5
|
+
this.name = 'UnsupportedRomanizationError';
|
|
6
|
+
this.script = script;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAsCA,MAAM,OAAO,4BAA6B,SAAQ,KAAK;IACrC,MAAM,CAAa;IAEnC,YAAY,MAAkB;QAC5B,KAAK,CAAC,WAAW,MAAM,mCAAmC,CAAC,CAAC;QAC5D,IAAI,CAAC,IAAI,GAAG,8BAA8B,CAAC;QAC3C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "lyric-romanizer",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Script detection and local romanization engine for lyrics — supports Japanese, Chinese, Korean, Cyrillic, Indic scripts, Tamil, Thai, and more",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"default": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./detector": {
|
|
19
|
+
"types": "./dist/detector.d.ts",
|
|
20
|
+
"import": "./dist/detector.js",
|
|
21
|
+
"default": "./dist/detector.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"README.md"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "rm -rf dist && tsc -p tsconfig.build.json",
|
|
30
|
+
"clean": "rm -rf dist",
|
|
31
|
+
"prepack": "npm run build",
|
|
32
|
+
"test": "vitest run",
|
|
33
|
+
"test:watch": "vitest"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@dehoist/romanize-thai": "^1.0.0",
|
|
37
|
+
"@indic-transliteration/sanscript": "^1.3.3",
|
|
38
|
+
"@romanize/korean": "^0.1.3",
|
|
39
|
+
"@sglkc/kuroshiro": "^1.0.1",
|
|
40
|
+
"@sglkc/kuroshiro-analyzer-kuromoji": "^1.0.1",
|
|
41
|
+
"cyrillic-to-translit-js": "^3.2.1",
|
|
42
|
+
"pinyin-pro": "^3.28.0",
|
|
43
|
+
"tamil-romanizer": "^1.0.2"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"typescript": "^5.7.3",
|
|
47
|
+
"vitest": "^4.0.18"
|
|
48
|
+
},
|
|
49
|
+
"keywords": [
|
|
50
|
+
"romanization",
|
|
51
|
+
"romanize",
|
|
52
|
+
"lyrics",
|
|
53
|
+
"pinyin",
|
|
54
|
+
"kuroshiro",
|
|
55
|
+
"korean",
|
|
56
|
+
"cyrillic",
|
|
57
|
+
"tamil",
|
|
58
|
+
"thai",
|
|
59
|
+
"devanagari",
|
|
60
|
+
"transliteration",
|
|
61
|
+
"script-detection"
|
|
62
|
+
],
|
|
63
|
+
"repository": {
|
|
64
|
+
"type": "git",
|
|
65
|
+
"url": "https://github.com/thedavidweng/lyric-romanizer.git"
|
|
66
|
+
},
|
|
67
|
+
"bugs": {
|
|
68
|
+
"url": "https://github.com/thedavidweng/lyric-romanizer/issues"
|
|
69
|
+
},
|
|
70
|
+
"homepage": "https://github.com/thedavidweng/lyric-romanizer#readme"
|
|
71
|
+
}
|