General utilities for working with Gurmukhi text data. Try gurmukhi-utils
in your browser.
const {
toAscii,
toUnicode,
toEnglish,
stripEndings
} = require( 'gurmukhi-utils' )
const unicodeGurmukhi = 'ри╕рйЛ риШри░рйБ ри░ри╛риЦрйБ; ри╡рибри╛риИ ридрйЛриЗ реерйзрее ри░ри╣ри╛риЙ рее'
const asciiGurmukhi = 'so Gru rwKu; vfweI qoie ]1] rhwau ]'
toAscii( unicodeGurmukhi ) // => so Gru rwKu; vfweI qoie ]1] rhwau ]
toUnicode( asciiGurmukhi ) // => ри╕рйЛ риШри░рйБ ри░ри╛риЦрйБ; ри╡рибри╛риИ ридрйЛриЗ реерйзрее ри░ри╣ри╛риЙ рее
toEnglish( asciiGurmukhi ) // => so ghar raakh; vaddaaee toie |1| rahaau |
stripEndings( toEnglish( asciiGurmukhi ) ) // => so ghar raakh; vaddaaee toie
Table of Contents
- Introduction
- Usage
- 3rd Party Ports
- API
- countSyllables(text) тЗТ number
- firstLetters(line) тЗТ String
- isGurmukhi(text, [exhaustive]) тЗТ boolean
- stripAccents(text) тЗТ String
- stripEndings(text) тЗТ String
- stripVishraams(text, options) тЗТ String
- toAscii(text) тЗТ String
- toEnglish(line) тЗТ String
- toHindi(text) тЗТ String
- toShahmukhi(text) тЗТ String
- toSyllabicSymbols(text) тЗТ String
- toUnicode(text) тЗТ String
- Community
- Contributing
- People
- Feedback
- Related Projects
- Code of Conduct
- License
Gurmukhi Utils is a library for converting, analyzing, and testing gurmukhi strings.
Gurmukhi Utils is available as the gurmukhi-utils
package on npm. Want to play around? Try it out in your browser with RunKit!
Additionally, the package is available for web use via unpkg CDN:
<script src="https://unpkg.com/gurmukhi-utils"></script>
- onkarjit/GurmukhiUtils is a rewrite of Shabad OS's gurmukhi-utils to C# for .NET applications
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).
Param | Type | Description |
---|---|---|
text | String |
The string to analyze |
Example
countSyllables( 'рикрйНри░ринрйВ рикрйНри░рйЗриорйА рикрйЬрйНри╣ риЪрйЬрйНри╣ рижрйНри╡рйИрид' )
// expected output: 14
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.
Param | Type | Description |
---|---|---|
line | String |
The 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|
Checks if first char in string is part of the Gurmukhi Unicode block.
Returns: boolean
- True if Unicode Gurmukhi, false if other.
Param | Type | Description |
---|---|---|
text | String |
The text to check. |
[exhaustive] | boolean |
If true , checks if the whole string is Unicode Gurmukhi. |
Example
isGurmukhi('риЧрйБри░риорйБриЦрйА') // => true
isGurmukhi('gurmuKI') // => false
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.
Param | Type | Description |
---|---|---|
text | String |
The text to convert. |
Example
stripAccents('рйЫрйЮрйИри╢ри╕риУ') // => риЬрилрйИри╕ри╕рй│
stripAccents('Z^Svb') // => gKsvb
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.
Param | Type | Description |
---|---|---|
text | String |
The 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.
Removes the specified vishraams from a string.
Returns: String
- A vishraam-less Gurmukhi string.
Param | Type | Description |
---|---|---|
text | String |
The text to remove vishraams from. |
options | Object |
The 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
Converts Gurmukhi unicode text to ASCII, used GurmukhiAkhar font.
Returns: String
- An ASCII representation of the provided unicode Gurmukhi string.
Param | Type | Description |
---|---|---|
text | String |
The unicode text to convert. |
Example
toAscii('ри╣риори╛ ри╕ри╛риЗри▓ри┐ ри▓рйБридрйЮри┐ ри╣риХ рикри░ри╡ри░ри╢ рее') // => hmw swieil luqi& hk prvrS ]
toAscii('ри╕рйБ римрйИриари┐ риЗриХрй░ридрйНри░ реерйлрйнрйорее') // => su bYiT iekMqR ]578]
Transliterates a line from Unicode Gurmukhi to english.
Currently supports the ,
, ;
, .
vishraam characters.
Returns: String
- The English transliteration of the provided Gurmukhi line.
Param | Type | Description |
---|---|---|
line | String |
The Gurmukhi Unicode line to transliterate. |
Example
toEnglish('ри╣рйБриХриорйА ри╣рйБриХриорйБ риЪри▓ри╛риП ри░ри╛ри╣рйБ рее') // => hukamee hukam chalaae raahu ||
Example
toEnglish('ринри╛риВрибри╛ ринри╛риЙ риЕрй░риорйНри░ри┐ридрйБ ридри┐ридрйБ риври╛ри▓ри┐ рее') // => bhaa(n)ddaa bhaou anmrit tit dtaal ||
Transliterates Unicode Gurmukhi text to Hindi (Devanagari script).
Returns: String
- A Hindi transliteration of the provided Unicode Gurmukhi string.
Param | Type | Description |
---|---|---|
text | String |
The Unicode Gurmukhi text to convert. |
Example
toHindi('риХрйБри▓ риЬрии риоризрйЗ риори┐ри▓рй╡рйЛри┐ ри╕ри╛ри░риЧ рикри╛рии ри░рйЗ рее') // => рдХреБрд▓ рдЬрди рдордзреЗ рдорд┐рд▓реНрдпреЛ рд╕рд╛рд░рдЧ рдкрд╛рди рд░реЗ рее
toHindi('ри╕рйБ римрйИриари┐ риЗриХрй░ридрйНри░ реерйлрйнрйорее') // => рд╕реБ рдмреИрда рдЗрдХрдВрддреНрд░ реерелренреорее
Transliterates Unicode Gurmukhi text to the Shahmukhi script.
Returns: String
- A Shahmukhi transliteration of the provided Unicode Gurmukhi string.
Param | Type | Description |
---|---|---|
text | String |
The Unicode Gurmukhi text to convert. |
Example
toShahmukhi('ри╣риори╛ ри╕ри╛риЗри▓ри┐ ри▓рйБридрйЮри┐ ри╣риХ рикри░ри╡ри░ри╢ рее') // => ┘З┘Е╪з ╪│╪з┘Р╪з┘Д ┘Д┘П╪к┘Б ┘З┌й ┘╛╪▒┘И╪▒╪┤ █Ф█Ф
toShahmukhi('ри╕рйБ римрйИриари┐ риЗриХрй░ридрйНри░ реерйлрйнрйорее') // => ╪│┘П ╪и┘О█Т┘╣┌╛ ┘Р╪з┌й┌║╪к╪▒ █Ф█Ф█╡█╖█╕█Ф█Ф
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).
Param | Type | Description |
---|---|---|
text | String |
The string to convert |
Example
toSyllabicSymbols( 'рикрйНри░ринрйВ рикрйНри░рйЗриорйА рикрйЬрйНри╣ риЪрйЬрйНри╣ рижрйНри╡рйИрид' )
// expected output: '12 22 11 11 21'
Converts ASCII text used in the GurmukhiAkhar font to Unicode.
Returns: String
- A unicode representation of the provided ASCII Gurmukhi string.
Param | Type | Description |
---|---|---|
text | String |
The ASCII text to convert. |
Example
toUnicode('kul jn mDy imil┬┤o swrg pwn ry ]') // => риХрйБри▓ риЬрии риоризрйЗ риори┐ри▓рй╡рйЛри┐ ри╕ри╛ри░риЧ рикри╛рии ри░рйЗ рее
toUnicode('su bYiT iekMqR ]578]') // => ри╕рйБ римрйИриари┐ риЗриХрй░ридрйНри░ реерйлрйнрйорее
Get updates on Shabad OS and chat with the project maintainers and community members.
There are multiple ways to contribute whether you are a user or developer. For example:
- Submit bugs and feature requests.
- Review documentation and make pull requests for anything from typos to new content.
- Give feedback on the onboarding process to make it easier for others to join the project.
If you're interested in contributing to the source code of Gurmukhi Utils, then please see Contributing Guidelines.
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
- Ask a question via Slack
- Upvote popular feature requests using the thumbs-up/+1 reaction on the first post of a feature request
- Follow @shabad_os on Instagram and @shabad_os on Twitter and let us know what you think!
Projects in the Shabad OS ecosystem of free and open source software which use the gurmukhi-utils
package include:
Please note that this project is released under the Contributor Covenant. By participating in this project you agree to abide by its terms. Our intention is to signal a safe open-source community by welcoming all people to contribute, and pledging in return to value them as whole human beings and to foster an atmosphere of kindness, cooperation, and understanding.
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
The Shabad OS Gurmukhi Utils repo is under v3 of the GPL. It is similar to the Golden Rule: do unto others as you would have them do unto you. In exchange for benefitting from the work completed in this repo, others must share their derivative work under v3 of the GPL.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.