Skip to content

Commit

Permalink
fix(firstLetters): remove spaces from firstLetter input strings (#161)
Browse files Browse the repository at this point in the history
Prevents undefined being outputted in the resultant string

Fixes #160
  • Loading branch information
Harjot1Singh authored Jun 6, 2020
1 parent e0799a0 commit e2bb085
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/firstLetters.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const vowelFirstLetters = {
const firstLetters = line => line
// Split into words
.split( ' ' )
// Remove any wrods that are excess spaces
.filter( word => word.trim().length )
// Grab correct letter of each word
.map( word => {
const [ letter ] = word
Expand Down
4 changes: 3 additions & 1 deletion test/firstLetters.spec.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
const { expect } = require( 'chai' )

const { firstLetters, toHindi, toEnglish } = require( '../index' )
const { firstLetters, toUnicode, toHindi, toEnglish } = require( '../index' )

describe( 'firstLetters(gurmukhi)', () => {
const lines = [
[ 'ਗੁਰਮੁਖਿ ਲਾਧਾ ਮਨਮੁਖਿ ਗਵਾਇਆ ॥', 'ਗਲਮਗ॥' ],
[ 'ਗੁਰਮੁਖਿ ਲਾਧਾ ਮਨਮੁਖਿ ਗਵਾਇਆ ॥', 'ਗਲਮਗ॥' ],
[ 'ਜਿਨਿ ਹਰਿ ਸੇਵਿਆ ਤਿਨਿ ਸੁਖੁ ਪਾਇਆ ॥', 'ਜਹਸਤਸਪ॥' ],
[ 'ਗ਼ੈਰਿ ਹਮਦਿ ਹੱਕ ਨਿਆਇਦ ਬਰ ਜ਼ਬਾਨਮ ਹੀਚ ਗਾਹ', 'ਗ਼ਹਹਨਬਜ਼ਹਗ' ],
[ 'ਸਬਦਿ ਮਰੈ. ਸੋ ਮਰਿ ਰਹੈ; ਫਿਰਿ. ਮਰੈ ਨ, ਦੂਜੀ ਵਾਰ ॥', 'ਸਮ.ਸਮਰ;ਫ.ਮਨ,ਦਵ॥' ],
[ 'ਇਕਨਾ. ਹੁਕਮੀ ਬਖਸੀਸ; ਇਕਿ, ਹੁਕਮੀ ਸਦਾ ਭਵਾਈਅਹਿ ॥', 'ੲ.ਹਬ;ੲ,ਹਸਭ॥' ],
[ toUnicode( 'ik hr hSqo Ssq Awmdw cwkrS [148[' ), 'ਕਹਹਸ਼ਅਚ।' ],
]

lines.map( ( [ line, expectedFirstLetters ] ) => it( `should generate first letters for '${line}' as '${expectedFirstLetters}'`, () => {
Expand Down

0 comments on commit e2bb085

Please sign in to comment.