diff --git a/deno.lock b/deno.lock index ed28ae0..5bd294b 100644 --- a/deno.lock +++ b/deno.lock @@ -5,6 +5,7 @@ "jsr:@deno/cache-dir@~0.10.3": "0.10.3", "jsr:@deno/dnt@~0.41.3": "0.41.3", "jsr:@deno/graph@~0.73.1": "0.73.1", + "jsr:@std/assert@*": "0.226.0", "jsr:@std/assert@0.223": "0.223.0", "jsr:@std/assert@0.226": "0.226.0", "jsr:@std/bytes@0.223": "0.223.0", @@ -14,6 +15,7 @@ "jsr:@std/fs@0.223": "0.223.0", "jsr:@std/fs@1": "1.0.4", "jsr:@std/fs@~0.229.3": "0.229.3", + "jsr:@std/internal@1": "1.0.4", "jsr:@std/io@0.223": "0.223.0", "jsr:@std/path@0.223": "0.223.0", "jsr:@std/path@1": "1.0.6", @@ -55,7 +57,10 @@ "integrity": "eb8d6d879d76e1cc431205bd346ed4d88dc051c6366365b1af47034b0670be24" }, "@std/assert@0.226.0": { - "integrity": "0dfb5f7c7723c18cec118e080fec76ce15b4c31154b15ad2bd74822603ef75b3" + "integrity": "0dfb5f7c7723c18cec118e080fec76ce15b4c31154b15ad2bd74822603ef75b3", + "dependencies": [ + "jsr:@std/internal" + ] }, "@std/bytes@0.223.0": { "integrity": "84b75052cd8680942c397c2631318772b295019098f40aac5c36cead4cba51a8" @@ -81,6 +86,9 @@ "jsr:@std/path@^1.0.6" ] }, + "@std/internal@1.0.4": { + "integrity": "62e8e4911527e5e4f307741a795c0b0a9e6958d0b3790716ae71ce085f755422" + }, "@std/io@0.223.0": { "integrity": "2d8c3c2ab3a515619b90da2c6ff5ea7b75a94383259ef4d02116b228393f84f1", "dependencies": [ diff --git a/src/mod.ts b/src/mod.ts index c545b3b..438f3c1 100644 --- a/src/mod.ts +++ b/src/mod.ts @@ -1,5 +1,5 @@ import { syllabify, getAksaraBySyllables } from "./utils.ts"; - +import { regexAnakHurufMap, regexIndukHurufMap } from "./regex.ts"; /** * Converts a given Latin script string into its corresponding Aksara Lampung script. * @@ -32,7 +32,59 @@ export function getAksara(latin: string): string { * @returns {string} The converted string in Latin script. */ export function getLatin(aksara: string): string { - // TODO: implement aksara to latin conversion + let latin: string = aksara; + + // Induk huruf + latin = latin.replace(regexIndukHurufMap.a, "a"); + latin = latin.replace(regexIndukHurufMap.ka, "ka"); + latin = latin.replace(regexIndukHurufMap.ga, "ga"); + latin = latin.replace(regexIndukHurufMap.pa, "pa"); + latin = latin.replace(regexIndukHurufMap.ba, "ba"); + latin = latin.replace(regexIndukHurufMap.ma, "ma"); + latin = latin.replace(regexIndukHurufMap.ta, "ta"); + latin = latin.replace(regexIndukHurufMap.da, "da"); + latin = latin.replace(regexIndukHurufMap.na, "na"); + latin = latin.replace(regexIndukHurufMap.ca, "ca"); + latin = latin.replace(regexIndukHurufMap.ja, "ja"); + latin = latin.replace(regexIndukHurufMap.ya, "ya"); + latin = latin.replace(regexIndukHurufMap.la, "la"); + latin = latin.replace(regexIndukHurufMap.ra, "ra"); + latin = latin.replace(regexIndukHurufMap.sa, "sa"); + latin = latin.replace(regexIndukHurufMap.wa, "wa"); + latin = latin.replace(regexIndukHurufMap.ha, "ha"); + latin = latin.replace(regexIndukHurufMap.gha, "gha"); + latin = latin.replace(regexIndukHurufMap.nga, "nga"); + latin = latin.replace(regexIndukHurufMap.nya, "nya"); + latin = latin.replace(regexIndukHurufMap.kha, "kha"); + + // Anak huruf + latin = latin.replace(regexAnakHurufMap.nengen, function (a) { + return a.substring(0, a.length - 2) + ""; + }); + latin = latin.replace(regexAnakHurufMap.ulan_i, function (a) { + return a.substring(0, a.length - 2) + "i"; + }); + latin = latin.replace(regexAnakHurufMap.ulan_e, function (a) { + return a.substring(0, a.length - 2) + "é"; + }); // Perlu dipertimbangkan alternatif untuk huruf é + latin = latin.replace(regexAnakHurufMap.bicek_e, function (a) { + return a.substring(0, a.length - 2) + "e"; + }); + latin = latin.replace(regexAnakHurufMap.bitan_o, function (a) { + return a.substring(0, a.length - 2) + "o"; + }); + latin = latin.replace(regexAnakHurufMap.bitan_u, function (a) { + return a.substring(0, a.length - 2) + "u"; + }); + latin = latin.replace(regexAnakHurufMap.tekelubang, "ng"); + latin = latin.replace(regexAnakHurufMap.rejunjung, "r"); + latin = latin.replace(regexAnakHurufMap.datasan, "n"); + latin = latin.replace(regexAnakHurufMap.tekelungau, "u"); + latin = latin.replace(regexAnakHurufMap.tekelingai, "i"); + latin = latin.replace(regexAnakHurufMap.keleniah, "h"); - return aksara; + const regextandabaca = + /[\,\!\@\.\*\+\?\$\^\/\\\;\:\'\"\[\]\{\}\(\)\%\#\$\^\-\+\=\_]/; + latin = latin.replace(regextandabaca, ""); + return latin; } diff --git a/src/regex.ts b/src/regex.ts new file mode 100644 index 0000000..eb6039f --- /dev/null +++ b/src/regex.ts @@ -0,0 +1,64 @@ +export const regexIndukHurufMap = { + ka: /[KkQq]/g, + ga: /[g]/g, + nga: /[G]/g, + pa: /[PpFfvV]/g, + ba: /[Bb]/g, + ma: /[Mm]/g, + ta: /[Tt]/g, + da: /[Dd]/g, + na: /[n]/g, + ca: /[Cc]/g, + ja: /[JjZz]/g, + nya: /[N]/g, + ya: /[y]/g, + a: /[a]/g, + la: /[Ll]/g, + ra: /[r]/g, + sa: /[Ss]/g, + wa: /[w]/g, + ha: /[h]/g, + kha: /[H]/g, + gha: /[H]/g, +}; + +export const regexAnakHurufMap = { + nengen: /a[\/]/g, + ulan_i: /a[i]/g, + ulan_e: /a[E]/g, + bicek_e: /a[e]/g, + bitan_o: /a[Oo]/g, + bitan_u: /a[u]/g, + tekelubang: /X/g, + rejunjung: /R/g, + datasan: /A/g, + tekelungau: /W/g, + tekelingai: /I/g, + keleniah: /x/g, +}; + +export const regexPatterns = { + ng: /(ng)[aiueoAIUEO]/g, + ny: /(ny)[aiueoAIUEOkKQqgpPfFvVbBmMtTdDcCjJzZyYlLsSwWGHh]/g, + gh: /(gh|kh)[aiueoAIUEOkKQqgpPfFvVbBmMtTdDcCjJzZyYlLsSwWGHh]/g, + vocal: /^[iIuUeEoO]/, + tandabaca: /[,!@.*+?$^/\\;:'"[\]{}()%#^+=_-]/, + ang: /[aiueoIUEO](ng)[kKQqgpPfFvVbBmMtTdDcCjJzZyYlLsSwWGHhnr,!@.*+?$^/\\;:'"[\]{}()%#^+=_-]]/g, + an: /[aiueoIUEO](n)[kKQqgpPfFvVbBmMtTdDcCjJzZyYlLsSwWGHhnr,!@.*+?$^/\\;:'"[\]{}()%#^+=_-]]/g, + ah: /[aiueoIUEO](h)[kKQqgpPfFvVbBmMtTdDcCjJzZyYlLsSwWGHhnr,!@.*+?$^/\\;:'"[\]{}()%#^+=_-]]/g, + ar: /[aiueoIUEO](r)[kKQqgpPfFvVbBmMtTdDcCjJzZyYlLsSwWGHhnr,!@.*+?$^/\\;:'"[\]{}()%#^+=_-]]/g, + ai: /[aiueoIUEO](i)[kKQqgpPfFvVbBmMtTdDcCjJzZyYlLsSwWGHhnr,!@.*+?$^/\\;:'"[\]{}()%#^+=_-]]/g, + au: /[aiueoIUEO](u)[kKQqgpPfFvVbBmMtTdDcCjJzZyYlLsSwWGHhnr,!@.*+?$^/\\;:'"[\]{}()%#^+=_-]]/g, + xawal: + /[aiueoIUEO][kKQqgpPfFvVbBmMtTdDcCjJzZyYlLsSwWH][kKQqgpPfFvVbBmMtTdDcCjJzZyYlLsSwWH][aiueoIUEO]/g, + x: /(?![aeiouAEIOU](R|r|u|n|h|ng|gh|kh|i))[aiueoIUEO]([kKQqgpPfFvVbBmMtTdDcCjJzZyYlLsSwWHnhriu])[,!@.*+?$^/\\;:'"[\]{}()%#^+=_-]?$/g, + xng: /[aiueoIUEO]ng$/g, + anx: /[aiueoIUEO]n/g, + ahx: /[aiueoIUEO]h/g, + arx: /[aiueoIUEO]r\b/g, + aix: /[aiueoIUEO]i/g, + aux: /[aiueoIUEO]u/g, + a: /[kKQqgpPfFvVbBmMtTdDcCjJzZyYlLsSwWGHhnr][a]/g, + awal: /\b[iIuUeEoOXAR]/g, + digraph: /(? { .replaceAll("x", "ks") .replaceAll("z", "j"); - const regexPatterns = { - ng: /(ng)[aiueoAIUEO]/g, - ny: /(ny)[aiueoAIUEOkKQqgpPfFvVbBmMtTdDcCjJzZyYlLsSwWGHh]/g, - gh: /(gh|kh)[aiueoAIUEOkKQqgpPfFvVbBmMtTdDcCjJzZyYlLsSwWGHh]/g, - vocal: /^[iIuUeEoO]/, - tandabaca: /[,!@.*+?$^/\\;:'"[\]{}()%#^+=_-]/, - ang: /[aiueoIUEO](ng)[kKQqgpPfFvVbBmMtTdDcCjJzZyYlLsSwWGHhnr,!@.*+?$^/\\;:'"[\]{}()%#^+=_-]]/g, - an: /[aiueoIUEO](n)[kKQqgpPfFvVbBmMtTdDcCjJzZyYlLsSwWGHhnr,!@.*+?$^/\\;:'"[\]{}()%#^+=_-]]/g, - ah: /[aiueoIUEO](h)[kKQqgpPfFvVbBmMtTdDcCjJzZyYlLsSwWGHhnr,!@.*+?$^/\\;:'"[\]{}()%#^+=_-]]/g, - ar: /[aiueoIUEO](r)[kKQqgpPfFvVbBmMtTdDcCjJzZyYlLsSwWGHhnr,!@.*+?$^/\\;:'"[\]{}()%#^+=_-]]/g, - ai: /[aiueoIUEO](i)[kKQqgpPfFvVbBmMtTdDcCjJzZyYlLsSwWGHhnr,!@.*+?$^/\\;:'"[\]{}()%#^+=_-]]/g, - au: /[aiueoIUEO](u)[kKQqgpPfFvVbBmMtTdDcCjJzZyYlLsSwWGHhnr,!@.*+?$^/\\;:'"[\]{}()%#^+=_-]]/g, - xawal: - /[aiueoIUEO][kKQqgpPfFvVbBmMtTdDcCjJzZyYlLsSwWH][kKQqgpPfFvVbBmMtTdDcCjJzZyYlLsSwWH][aiueoIUEO]/g, - x: /(?![aeiouAEIOU](R|r|u|n|h|ng|gh|kh|i))[aiueoIUEO]([kKQqgpPfFvVbBmMtTdDcCjJzZyYlLsSwWHnhriu])[,!@.*+?$^/\\;:'"[\]{}()%#^+=_-]?$/g, - xng: /[aiueoIUEO]ng$/g, - anx: /[aiueoIUEO]n/g, - ahx: /[aiueoIUEO]h/g, - arx: /[aiueoIUEO]r\b/g, - aix: /[aiueoIUEO]i/g, - aux: /[aiueoIUEO]u/g, - a: /[kKQqgpPfFvVbBmMtTdDcCjJzZyYlLsSwWGHhnr][a]/g, - awal: /\b[iIuUeEoOXAR]/g, - digraph: /(? { if (aksara.match(/nya(?![ionuh])/gi)) { diff --git a/test/getAksara.test.ts b/test/getAksara.test.ts index 1003b64..0e0c2f9 100644 --- a/test/getAksara.test.ts +++ b/test/getAksara.test.ts @@ -1,5 +1,5 @@ import { assertEquals } from "jsr:@std/assert"; -import { getAksara } from "../src/mod.ts"; +import { getAksara, getLatin } from "../src/mod.ts"; Deno.test("getAksara should return correct aksara for given input", () => { const input = "sikam haga mengan"; @@ -14,3 +14,10 @@ Deno.test("getAksara should handle empty input", () => { const result = getAksara(input); assertEquals(result, expectedOutput); }); + +Deno.test("should convert aksara string back to latin", () => { + const input = "sikm/ hg meGA"; + const expectedOutput = "sikam haga mengan"; + const result = getLatin(input); + assertEquals(result, expectedOutput); +});