npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gurmukhi-utils

v3.2.2

Published

General functions for working with lines of Gurmukhi.

Downloads

247

Readme

General utilities for working with Gurmukhi text data. Try gurmukhi-utils in your browser.

NPM Version NPM Downloads Release Next Release Test Coverage

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

Gurmukhi Utils is a library for converting, analyzing, and testing gurmukhi strings.

Usage

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>

3rd Party Ports

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).

| Param | Type | Description | | --- | --- | --- | | text | String | The 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.

| 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|

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.

| 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

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.

| Param | Type | Description | | --- | --- | --- | | text | String | The 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.

| 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.

stripVishraams(text, options) ⇒ String

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

toAscii(text) ⇒ String

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]

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.

| 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 ||

toHindi(text) ⇒ String

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('ਸੁ ਬੈਠਿ ਇਕੰਤ੍ਰ ॥੫੭੮॥') // => सु बैठ इकंत्र ॥५७८॥

toShahmukhi(text) ⇒ String

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('ਸੁ ਬੈਠਿ ਇਕੰਤ੍ਰ ॥੫੭੮॥') // => سُ بَےٹھ ِاکںتر ۔۔۵۷۸۔۔

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).

| Param | Type | Description | | --- | --- | --- | | text | String | The 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.

| 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]') // => ਸੁ ਬੈਠਿ ਇਕੰਤ੍ਰ ॥੫੭੮॥

Community

Get updates on Shabad OS and chat with the project maintainers and community members.

  • Instagram Follow Shabad OS on Instagram
  • Twitter Follow Shabad OS on Twitter.
  • Chat Join the official Slack channel.

Contributing

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.

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

Feedback

Related Projects

Projects in the Shabad OS ecosystem of free and open source software which use the gurmukhi-utils package include:

Code of Conduct

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 Contributor Covenant

License

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/.