Skip to content

Commit

Permalink
Merge pull request #134 from ShabadOS/subscript-support
Browse files Browse the repository at this point in the history
fix(toEnglish): add passthrough for letters that are not in the transliteration map

#Patch fix
  • Loading branch information
Harjot1Singh authored Mar 30, 2020
2 parents f6443de + a497a4a commit 88476b4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 49 deletions.
50 changes: 1 addition & 49 deletions lib/toEnglish.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,6 @@ const spaceChars = [ ' ', ...vishraams ]
// Escape characters and wrap into regex
const spaceCharsRegex = `([${spaceChars.join( '' ).replace( /[.*+?^${}()|[\]\\]/g, '\\$&' )}])`

// Characters that can pass through the transliterator
const passThrough = [
'!',
'"',
'#',
'$',
'%',
"'",
'(',
')',
'*',
'+',
'-',
'/',
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
':',
'=',
'?',
'_',
'{',
'}',
'¢',
'£',
'¥',
'±',
'—',
'•',
'…',
'¶',
'‘',
'’',
'“',
'”',
'\n',
...vishraams,
]

// Characters that should be supressed into empty characters
const supressions = [ '@', '`', '~', '¤', 'ª', '°', 'Ç', 'Ó', 'Ô', 'Ø', 'æ', 'Œ', '‰' ]

Expand Down Expand Up @@ -144,8 +98,6 @@ const transliterationMap = {
'†': 'tt',
// Expand out supressions as char: ''
...supressions.reduce( ( chars, char ) => ( { ...chars, [ char ]: '' } ), {} ),
// Expand out pass through chars as char: char
...passThrough.reduce( ( chars, char ) => ( { ...chars, [ char ]: char } ) ),
}

// Replacements for the initial input
Expand Down Expand Up @@ -239,7 +191,7 @@ const toEnglish = line => {
const nextNextLetter = line[ index + 2 ] || ''

// Map letter using transliteration map
let mappedLetter = transliterationMap[ letter ]
let mappedLetter = transliterationMap[ letter ] || letter

// Add in extra `a` if every rule is met
if ( extraARules.every( fn => fn( mappedLetter, nextLetter, nextNextLetter ) ) ) { mappedLetter += 'a' }
Expand Down
1 change: 1 addition & 0 deletions test/toEnglish.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const transliterations = [
[ 'ਹੁਕਮੈ ਅੰਦਰਿ. ਸਭੁ ਕੋ; ਬਾਹਰਿ ਹੁਕਮ. ਨ ਕੋਇ ॥', 'hukamai andar. sabh ko; baahar hukam. na koe |' ],
[ 'ਸਹਜ; ਸਸਹਜ ਅਨਹਦ ਰਹਤ ਕਹਤ ਪਹਰ, ਸਹਸ ਮਹਲ ਟਹਲ ਕਹਨਨ ਕਹਨ', 'sehaj; sasahaj anahad rehat kehat pehar, sehas mehal ttehal kahanan kehan' ],
[ 'ਸਭ ਭਇਓ ਪਰਾਇਓ', 'sabh bheo paraaeo' ],
[ 'ਆਸਾ ਮਹਲਾ ੫ ਪੰਚਪਦੇ₃ ॥', 'aasaa mahalaa 5 panchapade₃ |' ],
]

describe( 'toEnglish()', () => {
Expand Down

0 comments on commit 88476b4

Please sign in to comment.