Skip to content

Commit

Permalink
Add old south arabia (#27)
Browse files Browse the repository at this point in the history
- Support Old South Arabian
  • Loading branch information
amerharb authored Feb 17, 2024
1 parent 120580c commit ba7fa55
Show file tree
Hide file tree
Showing 11 changed files with 221 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/abjad-convert/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!-- https://keepachangelog.com/en/1.0.0/ -->

## [0.5.0] 2024-02-12
### Added
- Support Old South Arabian

## [0.3.3] 2024-01-20
### Fixed
Expand Down
4 changes: 4 additions & 0 deletions packages/abjad-convert/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
current supported alphabets:
- Arabic
- Imperial Aramaic
- Old South Arabian
- Phoenician
- Syriac
- Tifinagh
Expand All @@ -33,6 +34,9 @@ const arabicWord = 'مرحبا';
const imperialAramaicWord = convert(arabicWord, Abjad.Arabic, Abjad.ImperialAramaic);
console.log(imperialAramaicWord); // 𐡌𐡓𐡇𐡁𐡀

const oldSouthArabianWord = convert(arabicWord, Abjad.Arabic, Abjad.OldSouthArabian);
console.log(oldSouthArabianWord); // 𐩣𐩧𐩢𐩨𐩡

const phoenicianWord = convert(arabicWord, Abjad.Arabic, Abjad.Phoenician);
console.log(phoenicianWord); // 𐤌𐤓𐤇𐤁𐤀

Expand Down
2 changes: 1 addition & 1 deletion packages/abjad-convert/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "abjad-convert",
"version": "0.5.0",
"version": "0.5.0-next.0",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"files": [
Expand Down
4 changes: 4 additions & 0 deletions packages/abjad-convert/src/converterFactory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Abjad } from './types'
import { IConverter } from './IConverter'
import { ArabicToImperialAramaicConverter } from './scripts/arabic/toImperialAramaic'
import { ArabicToOldSouthArabianConverter } from './scripts/arabic/toOldSouthArabian'
import { ArabicToPhoenicianConverter } from './scripts/arabic/toPhoenician'
import { ArabicToSyriacConverter } from './scripts/arabic/toSyriac'
import { ArabicToTifinaghConverter } from './scripts/arabic/toTifinagh'
Expand All @@ -10,14 +11,17 @@ import { PhoenicianToArabicConverter } from './scripts/phoenician/toArabic'
import { SyriacToArabicConverter } from './scripts/syriac/toArabic'
import { TifinaghToArabicConverter } from './scripts/tifinagh/toArabic'
import { UgariticToArabicConverter } from './scripts/ugaritic/toArabic'
import { OldSouthArabicToArabicConverter } from './scripts/oldSouthArabian/toArabic'

const converters: IConverter[] = [
new ArabicToImperialAramaicConverter(),
new ArabicToOldSouthArabianConverter(),
new ArabicToPhoenicianConverter(),
new ArabicToSyriacConverter(),
new ArabicToTifinaghConverter(),
new ArabicToUgariticConverter(),
new ImperialAramaicToArabicConverter(),
new OldSouthArabicToArabicConverter(),
new PhoenicianToArabicConverter(),
new SyriacToArabicConverter(),
new TifinaghToArabicConverter(),
Expand Down
3 changes: 3 additions & 0 deletions packages/abjad-convert/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getConverter } from './converterFactory'
import { Abjad } from './types'
import { arabic } from './scripts/arabic/letters'
import { imperialAramaic } from './scripts/imperialAramaic/letters'
import { oldSouthArabian } from './scripts/oldSouthArabian/letters'
import { phoenician } from './scripts/phoenician/letters'
import { syriac } from './scripts/syriac/letters'
import { tifinagh } from './scripts/tifinagh/letters'
Expand All @@ -23,6 +24,8 @@ export function getLetters(script: Abjad): readonly string[] {
return arabic.letters
case Abjad.ImperialAramaic:
return imperialAramaic.letters
case Abjad.OldSouthArabian:
return oldSouthArabian.letters
case Abjad.Phoenician:
return phoenician.letters
case Abjad.Syriac:
Expand Down
59 changes: 59 additions & 0 deletions packages/abjad-convert/src/scripts/arabic/toOldSouthArabian.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Ar } from './letters'
import { Sa } from '../oldSouthArabian/letters'
import { IConverter } from '../../IConverter'
import { Abjad } from '../../types'

export class ArabicToOldSouthArabianConverter implements IConverter {
public readonly from = Abjad.Arabic
public readonly to = Abjad.OldSouthArabian

private map = new Map<string, string>(
[
[' ', ' '],
[Ar.Hamza, Sa.Alef], // ء ->
[Ar.AlefMadda, Sa.Alef], // آ ->
[Ar.AlefHamza, Sa.Alef], // أ ->
[Ar.WawHamza, Sa.Waw], // ؤ ->
[Ar.AlefHamzaMaksura, Sa.Yodh], // ى ->
[Ar.Alef, Sa.Alef], // ا ->
[Ar.Ba, Sa.Beth], // ب ->
[Ar.TaMarbuta, Sa.He], // ة ->
[Ar.Ta, Sa.Taw], // ت ->
[Ar.Tha, Sa.Thaw], // ث ->
[Ar.Jeem, Sa.Gimel], // ج ->
[Ar.H7aa, Sa.Heth], // ح ->
[Ar.Khaa, Sa.Kheth], // خ ->
[Ar.Dal, Sa.Daleth], // د ->
[Ar.Thal, Sa.Dhaleth], // ذ ->
[Ar.Ra, Sa.Resh], // ر ->
[Ar.Zay, Sa.Zayn], // ز ->
[Ar.Seen, Sa.Sat], // س ->
[Ar.Sheen, Sa.Shin], // ش ->
[Ar.Sad, Sa.Sadhe], // ص ->
[Ar.Dad, Sa.Dhadhe], // ض ->
[Ar.TTa, Sa.Teth], // ط ->
[Ar.THa, Sa.Theth], // ظ ->
[Ar.Ayn, Sa.Ayin], // ع ->
[Ar.Ghayn, Sa.Ghayn], // غ ->
[Ar.Fa, Sa.Fe], // ف ->
[Ar.Qaf, Sa.Qoph], // ق ->
[Ar.Kaf, Sa.Kaph], // ك ->
[Ar.Lam, Sa.Lamedh], // ل ->
[Ar.Meem, Sa.Mem], // م ->
[Ar.Noon, Sa.Nun], // ن ->
[Ar.Ha, Sa.He], // ه ->
[Ar.Waw, Sa.Waw], // و ->
[Ar.Yaa, Sa.Yodh], // ي ->
[Ar.AlefMaksura, Sa.Alef], // ى ->
],
)

public convert(text: string): string {
let result = ''
for (const letter of text) {
const u = this.map.get(letter) ?? ''
result += u
}
return result
}
}
Binary file not shown.
81 changes: 81 additions & 0 deletions packages/abjad-convert/src/scripts/oldSouthArabian/letters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { Script } from '../Script'
import { Abjad } from '../../types'

/**
* Old South Arabian letters
*/
const letters = [
'\uD802\uDE60', /** #0 𐹠 U+10A60 OLD SOUTH ARABIAN LETTER He */
'\uD802\uDE61', /** #1 𐹡 U+10A61 OLD SOUTH ARABIAN LETTER Lamedh */
'\uD802\uDE62', /** #2 𐹢 U+10A62 OLD SOUTH ARABIAN LETTER Heth */
'\uD802\uDE63', /** #3 𐹣 U+10A63 OLD SOUTH ARABIAN LETTER Mem */
'\uD802\uDE64', /** #4 𐹤 U+10A64 OLD SOUTH ARABIAN LETTER Qoph */
'\uD802\uDE65', /** #5 𐹥 U+10A65 OLD SOUTH ARABIAN LETTER Waw */
'\uD802\uDE66', /** #6 𐹦 U+10A66 OLD SOUTH ARABIAN LETTER Shin */
'\uD802\uDE67', /** #7 𐹧 U+10A67 OLD SOUTH ARABIAN LETTER Resh */
'\uD802\uDE68', /** #8 𐹨 U+10A68 OLD SOUTH ARABIAN LETTER Beth */
'\uD802\uDE69', /** #9 𐹩 U+10A69 OLD SOUTH ARABIAN LETTER Taw */
'\uD802\uDE6A', /** #10 𐹪 U+10A6A OLD SOUTH ARABIAN LETTER Sat */
'\uD802\uDE6B', /** #11 𐹫 U+10A6B OLD SOUTH ARABIAN LETTER Kaph */
'\uD802\uDE6C', /** #12 𐹬 U+10A6C OLD SOUTH ARABIAN LETTER Nun */
'\uD802\uDE6D', /** #13 𐹭 U+10A6D OLD SOUTH ARABIAN LETTER Kheth */
'\uD802\uDE6E', /** #14 𐹮 U+10A6E OLD SOUTH ARABIAN LETTER Sadhe */
'\uD802\uDE6F', /** #15 𐹯 U+10A6F OLD SOUTH ARABIAN LETTER Samekh */
'\uD802\uDE70', /** #16 𐹰 U+10A70 OLD SOUTH ARABIAN LETTER Fe */
'\uD802\uDE71', /** #17 𐹱 U+10A71 OLD SOUTH ARABIAN LETTER Alef */
'\uD802\uDE72', /** #18 𐹲 U+10A72 OLD SOUTH ARABIAN LETTER Ayin */
'\uD802\uDE73', /** #19 𐹳 U+10A73 OLD SOUTH ARABIAN LETTER Dhadhe */
'\uD802\uDE74', /** #20 𐹴 U+10A74 OLD SOUTH ARABIAN LETTER Gimel */
'\uD802\uDE75', /** #21 𐹵 U+10A75 OLD SOUTH ARABIAN LETTER Daleth */
'\uD802\uDE76', /** #22 𐹶 U+10A76 OLD SOUTH ARABIAN LETTER Ghayn */
'\uD802\uDE77', /** #23 𐹷 U+10A77 OLD SOUTH ARABIAN LETTER Teth */
'\uD802\uDE78', /** #24 𐹸 U+10A78 OLD SOUTH ARABIAN LETTER Zayn */
'\uD802\uDE79', /** #25 𐹹 U+10A79 OLD SOUTH ARABIAN LETTER Dhaleth */
'\uD802\uDE7A', /** #26 𐹺 U+10A7A OLD SOUTH ARABIAN LETTER Yodh */
'\uD802\uDE7B', /** #27 𐹻 U+10A7B OLD SOUTH ARABIAN LETTER Thaw */
'\uD802\uDE7C', /** #28 𐹼 U+10A7C OLD SOUTH ARABIAN LETTER Theth */
'\uD802\uDE7D', /** #29 𐹽 U+10A7D OLD SOUTH ARABIAN NUMBER ONE */
'\uD802\uDE7E', /** #30 𐹾 U+10A7E OLD SOUTH ARABIAN NUMBER FIFTY */
'\uD802\uDE7F', /** #31 𐹿 U+10A7F OLD SOUTH ARABIAN NUMERIC INDICATOR */
] as const

export const Sa = {
He: letters[0], // 𐹠
Lamedh: letters[1], // 𐹡
Heth: letters[2], // 𐹢
Mem: letters[3], // 𐹣
Qoph: letters[4], // 𐹤
Waw: letters[5], // 𐹥
Shin: letters[6], // 𐹦
Resh: letters[7], // 𐹧
Beth: letters[8], // 𐹨
Taw: letters[9], // 𐹩
Sat: letters[10], // 𐹪
Kaph: letters[11], // 𐹫
Nun: letters[12], // 𐹬
Kheth: letters[13], // 𐹭
Sadhe: letters[14], // 𐹮
Samekh: letters[15], // 𐹯
Fe: letters[16], // 𐹰
Alef: letters[17], // 𐹱
Ayin: letters[18], // 𐹲
Dhadhe: letters[19], // 𐹳
Gimel: letters[20], // 𐹴
Daleth: letters[21], // 𐹵
Ghayn: letters[22], // 𐹶
Teth: letters[23], // 𐹷
Zayn: letters[24], // 𐹸
Dhaleth: letters[25], // 𐹹
Yodh: letters[26], // 𐹺
Thaw: letters[27], // 𐹻
Theth: letters[28], // 𐹼
ONE: letters[29], // 𐹽
FIFTY: letters[30], // 𐹾
INDICATOR: letters[31], // 𐹿
}

export const oldSouthArabian = new Script(
Abjad.OldSouthArabian,
true,
letters,
)
52 changes: 52 additions & 0 deletions packages/abjad-convert/src/scripts/oldSouthArabian/toArabic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Sa } from './letters'
import { Ar } from '../arabic/letters'
import { IConverter } from '../../IConverter'
import { Abjad } from '../../types'

export class OldSouthArabicToArabicConverter implements IConverter {
public readonly from = Abjad.OldSouthArabian
public readonly to = Abjad.Arabic

private map = new Map<string, string>(
[
[' ', ' '],
[Sa.He, Ar.Ha],
[Sa.Lamedh, Ar.Lam],
[Sa.Heth, Ar.H7aa],
[Sa.Mem, Ar.Meem],
[Sa.Qoph, Ar.Qaf],
[Sa.Waw, Ar.Waw],
[Sa.Shin, Ar.Sheen],
[Sa.Resh, Ar.Ra],
[Sa.Beth, Ar.Ba],
[Sa.Taw, Ar.Ta],
[Sa.Sat, Ar.Seen],
[Sa.Kaph, Ar.Kaf],
[Sa.Nun, Ar.Noon],
[Sa.Kheth, Ar.Khaa],
[Sa.Sadhe, Ar.Sad],
[Sa.Samekh, Ar.Sad],
[Sa.Fe, Ar.Fa],
[Sa.Alef, Ar.Alef],
[Sa.Ayin, Ar.Ayn],
[Sa.Dhadhe, Ar.Dad],
[Sa.Gimel, Ar.Jeem],
[Sa.Daleth, Ar.Dal],
[Sa.Ghayn, Ar.Ghayn],
[Sa.Teth, Ar.TTa],
[Sa.Zayn, Ar.Zay],
[Sa.Dhaleth, Ar.Thal],
[Sa.Yodh, Ar.Yaa],
[Sa.Thaw, Ar.Tha],
[Sa.Theth, Ar.THa],
]
)

public convert(text: string): string {
let result = ''
for (const letter of text) {
result += this.map.get(letter) ?? ''
}
return result
}
}
1 change: 1 addition & 0 deletions packages/abjad-convert/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export enum Abjad {
Arabic = 'arabic',
ImperialAramaic = 'imperial-aramaic',
OldSouthArabian = 'old-south-arabian',
Phoenician = 'phoenician',
Syriac = 'syriac',
Tifinagh = 'tifinagh',
Expand Down
14 changes: 14 additions & 0 deletions packages/abjad-convert/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ describe('convert()', () => {
expect(actual).toEqual('𐡀 𐡁 𐡂')
})
})
describe('to OldSouthArabian', () => {
it('convert ا ب ج into \uD802\uDE71 \uD802\uDE68 \uD802\uDE74', () => {
const actual = convert('ا ب ج', Abjad.Arabic, Abjad.OldSouthArabian)
expect(actual).toEqual('\uD802\uDE71 \uD802\uDE68 \uD802\uDE74')
})
})
describe('to Phoenician', () => {
it('convert ا ب ج into 𐤀𐤟𐤁𐤟𐤂', () => {
const actual = convert('ا ب ج', Abjad.Arabic, Abjad.Phoenician)
Expand Down Expand Up @@ -66,6 +72,14 @@ describe('convert()', () => {
})
})
})
describe('from OldSouthArabian', () => {
describe('to Arabic', () => {
it('convert \uD802\uDE71 \uD802\uDE68 \uD802\uDE74 into ا ب ج', () => {
const actual = convert('\uD802\uDE71 \uD802\uDE68 \uD802\uDE74', Abjad.OldSouthArabian, Abjad.Arabic)
expect(actual).toEqual('ا ب ج')
})
})
})
describe('from Phoenician', () => {
describe('to Arabic', () => {
it('convert 𐤀𐤟𐤁𐤟𐤂 into ا ب ج', () => {
Expand Down

0 comments on commit ba7fa55

Please sign in to comment.