Gurmukhi Utils

Gurmukhi Utils is a library for converting, analyzing, and testing gurmukhi strings. Try gurmukhi-utils in your browser.

Usage#

Gurmukhi Utils is available as the gurmukhi-utils package on npm.

Additionally, the package is available for web use via unpkg CDN:

<script src="https://unpkg.com/gurmukhi-utils"></script>

People#

The original author and current lead maintainer of Gurmukhi Utils is Harjot Singh (@harjot1singh).

"Thank you!" to all the volunteers who've already contributed to Gurmukhi Utils. Additional thanks to:

  • Preetcharan S (@NerdSingh) and Basics of Sikhi for english pronunciation guidelines
  • Dr. Gurpreet S Lehal (Punjabi University, Patiala) for his work in Gurmukhi-Hindi (Devanagri) and Gurmukhi-Shahmukhi (Urdu) transliteration

API#

countSyllables(text) ⇒ number#

Calculates the number of syllables according to Sanskrit prosody, Pingala, Matra/Meter/Morae

Returns: number - An integer adding up all the 1's (laghu/light/short) and 2's (guru/heavy/long).

ParamTypeDescription
textStringThe string to analyze

Example

countSyllables('ਪ੍ਰਭੂ ਪ੍ਰੇਮੀ ਪੜ੍ਹ ਚੜ੍ਹ ਦ੍ਵੈਤ')
// expected output: 14

firstLetters(line) ⇒ String#

Generates the first letters for a unicode Gurmukhi, Hindi transliteration, or English transliteration string. Includes any end-word vishraams, and line-end characters.

Returns: String - The first letters of each word in the provided Gurmukhi line.

ParamTypeDescription
lineStringThe line to generate the first letters for.

Example (Gurmukhi first letters)

firstLetters('ਸਬਦਿ ਮਰੈ. ਸੋ ਮਰਿ ਰਹੈ; ਫਿਰਿ. ਮਰੈ ਨ, ਦੂਜੀ ਵਾਰ ॥') // => ਸਮ.ਸਮਰ;ਫ.ਮਨ,ਦਵ॥

Example (Hindi first letters)

firstLetters('गुरमुखि लाधा मनमुखि गवाइआ ॥') // => गलमग॥

Example (English first letters)

firstLetters('sabad marai. so mar rahai; fir. marai na, doojee vaar |') // => sm.smr;f.mn,dv|

isGurmukhi(text, [exhaustive]) ⇒ boolean#

Checks if first char in string is part of the Gurmukhi Unicode block.

Returns: boolean - True if Unicode Gurmukhi, false if other.

ParamTypeDescription
textStringThe text to check.
[exhaustive]booleanIf true, checks if the whole string is Unicode Gurmukhi.

Example

isGurmukhi('ਗੁਰਮੁਖੀ') // => true
isGurmukhi('gurmuKI') // => false

stripAccents(text) ⇒ String#

Removes accents from ASCII/Unicode Gumrukhi letters with their base letter. Useful for generalising search queries.

Returns: String - A simplified version of the provided Gurmukhi string.

ParamTypeDescription
textStringThe text to convert.

Example

stripAccents('ਜ਼ਫ਼ੈਸ਼ਸਓ') // => ਜਫੈਸਸੳ
stripAccents('Z^Svb') // => gKsvb

stripEndings(text) ⇒ String#

Strips line endings from any Gurmukhi or translation string. Accepts both Unicode and ASCII input. Useful for generating accurate first letters or modifying non-Gurbani for better display. Not designed for headings or Sirlekhs.

Returns: String - A ending-less version of the text.

ParamTypeDescription
textStringThe text to stip endings from.

Example (Line ending phrases)

stripEndings('ਸੋ ਘਰੁ ਰਾਖੁ; ਵਡਾਈ ਤੋਇ ॥੧॥ ਰਹਾਉ ॥') // => ਸੋ ਘਰੁ ਰਾਖੁ; ਵਡਾਈ ਤੋਇ
stripEndings('ਹੁਕਮੁ ਪਛਾਣਿ; ਤਾ ਖਸਮੈ ਮਿਲਣਾ ॥੧॥ ਰਹਾਉ ਦੂਜਾ ॥') // => ਹੁਕਮੁ ਪਛਾਣਿ; ਤਾ ਖਸਮੈ ਮਿਲਣਾ
stripEndings('ਜਨ ਨਾਨਕ. ਗੁਰਮੁਖਿ ਜਾਤਾ ਰਾਮ ॥੪॥੬॥ ਛਕਾ ੧ ॥') // => ਜਨ ਨਾਨਕ. ਗੁਰਮੁਖਿ ਜਾਤਾ ਰਾਮ

Example (English Translations)

stripEndings('O Nanak, Forever And Ever True. ||1||') // => O Nanak, Forever And Ever True.
stripEndings('lush greenery. ||1||Pause||') // => lush greenery.
stripEndings('always I live within the Khalsa. 519') // => always I live within the Khalsa.
stripEndings('without your reminiscence.(1) (3)') // => without your reminiscence.

Example (Spanish Translations)

stripEndings('ofrece su ser en sacrificio a Ti. (4-2-9)') // => ofrece su ser en sacrificio a Ti.

stripVishraams(text, options) ⇒ String#

Removes the specified vishraams from a string.

Returns: String - A vishraam-less Gurmukhi string.

ParamTypeDescription
textStringThe text to remove vishraams from.
optionsObjectThe vishraams to remove. Defaults to all.

Example (Text only, default options)

stripVishraams('ਸਬਦਿ ਮਰੈ. ਸੋ ਮਰਿ ਰਹੈ;') // => 'ਸਬਦਿ ਮਰੈ ਸੋ ਮਰਿ ਰਹੈ
stripVishraams('sbid mrY. so mir rhY; iPir.') // => sbid mrY so mir rhY iPir

Example (Heavy vishraams only)

stripVishraams('sbid mrY. so mir rhY; iPir.', { heavy: true }) // => sbid mrY. so mir rhY iPir.

Example (Medium vishrams only)

stripVishraams('Anhd sbd vjwey,', { medium: true }) // => Anhd sbd vjwey

Example (Light vishrams only)

stripVishraams('sbid mrY. so mir rhY; iPir.', { light: true }) // => sbid mrY so mir rhY; iPir

toAscii(text) ⇒ String#

Converts Gurmukhi unicode text to ASCII, used GurmukhiAkhar font.

Returns: String - An ASCII representation of the provided unicode Gurmukhi string.

ParamTypeDescription
textStringThe unicode text to convert.

Example

toAscii('ਹਮਾ ਸਾਇਲਿ ਲੁਤਫ਼ਿ ਹਕ ਪਰਵਰਸ਼ ॥') // => hmw swieil luqi& hk prvrS ]
toAscii('ਸੁ ਬੈਠਿ ਇਕੰਤ੍ਰ ॥੫੭੮॥') // => su bYiT iekMqR ]578]

toEnglish(line) ⇒ String#

Transliterates a line from Unicode Gurmukhi to english. Currently supports the ,, ;, . vishraam characters.

Returns: String - The English transliteration of the provided Gurmukhi line.

ParamTypeDescription
lineStringThe Gurmukhi Unicode line to transliterate.

Example

toEnglish('ਹੁਕਮੀ ਹੁਕਮੁ ਚਲਾਏ ਰਾਹੁ ॥') // => hukamee hukam chalaae raahu ||

Example

toEnglish('ਭਾਂਡਾ ਭਾਉ ਅੰਮ੍ਰਿਤੁ ਤਿਤੁ ਢਾਲਿ ॥') // => bhaa(n)ddaa bhaou anmrit tit dtaal ||

toHindi(text) ⇒ String#

Transliterates Unicode Gurmukhi text to Hindi (Devanagari script).

Returns: String - A Hindi transliteration of the provided Unicode Gurmukhi string.

ParamTypeDescription
textStringThe Unicode Gurmukhi text to convert.

Example

toHindi('ਕੁਲ ਜਨ ਮਧੇ ਮਿਲੵੋਿ ਸਾਰਗ ਪਾਨ ਰੇ ॥') // => कुल जन मधे मिल्यो सारग पान रे ॥
toHindi('ਸੁ ਬੈਠਿ ਇਕੰਤ੍ਰ ॥੫੭੮॥') // => सु बैठ इकंत्र ॥५७८॥

toShahmukhi(text) ⇒ String#

Transliterates Unicode Gurmukhi text to the Shahmukhi script.

Returns: String - A Shahmukhi transliteration of the provided Unicode Gurmukhi string.

ParamTypeDescription
textStringThe Unicode Gurmukhi text to convert.

Example

toShahmukhi('ਹਮਾ ਸਾਇਲਿ ਲੁਤਫ਼ਿ ਹਕ ਪਰਵਰਸ਼ ॥') // => هما ساِال لُتف هک پرورش ۔۔
toShahmukhi('ਸੁ ਬੈਠਿ ਇਕੰਤ੍ਰ ॥੫੭੮॥') // => سُ بَےٹھ ِاکںتر ۔۔۵۷۸۔۔

toSyllabicSymbols(text) ⇒ String#

Represents text in syllables according to Sanskrit prosody, Pingala, Matra/Meter/Morae

Returns: String - A syllabic representation of 1's (laghu/light/short) and 2's (guru/heavy/long).

ParamTypeDescription
textStringThe string to convert

Example

toSyllabicSymbols('ਪ੍ਰਭੂ ਪ੍ਰੇਮੀ ਪੜ੍ਹ ਚੜ੍ਹ ਦ੍ਵੈਤ')
// expected output: '12 22 11 11 21'

toUnicode(text) ⇒ String#

Converts ASCII text used in the GurmukhiAkhar font to Unicode.

Returns: String - A unicode representation of the provided ASCII Gurmukhi string.

ParamTypeDescription
textStringThe ASCII text to convert.

Example

toUnicode('kul jn mDy imil´o swrg pwn ry ]') // => ਕੁਲ ਜਨ ਮਧੇ ਮਿਲੵੋਿ ਸਾਰਗ ਪਾਨ ਰੇ ॥
toUnicode('su bYiT iekMqR ]578]') // => ਸੁ ਬੈਠਿ ਇਕੰਤ੍ਰ ॥੫੭੮॥
Last updated on by Bhajneet S.K