diff --git a/README.hbs b/README.hbs index 6caf1ce..a471c3b 100644 --- a/README.hbs +++ b/README.hbs @@ -35,7 +35,6 @@ const { toUnicode('Koj') // => ਖੋਜ toAscii('ਖੋਜ') // => Koj -firstLetters('hir hir hir gunI') // => hhhg firstLetters('ਹਰਿ ਹਰਿ ਹਰਿ ਗੁਨੀ') // => ਹਹਹਗ toEnglish('hukmI hukmu clwey rwhu ]') // => hukamee hukam chalaae raahu || toHindi('ਕੁਲ ਜਨ ਮਧੇ ਮਿਲੵੋਿ ਸਾਰਗ ਪਾਨ ਰੇ ॥') // => कुल जन मधे मिल्यो सारग पान रे ॥ diff --git a/README.md b/README.md index 7e23ebb..2ccc4c6 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Want to speak with us?
[![Slack](https://slack.shabados.com/badge.svg)](https
- [Usage](#usage)
- [API](#api)
- * [firstLetters(line, [stripNukta], [withVishraams]) ⇒ String](#firstlettersline-stripnukta-withvishraams-%E2%87%92-string)
+ * [firstLetters(line) ⇒ String](#firstlettersline-%E2%87%92-string)
* [isGurmukhi(text, [exhaustive]) ⇒ boolean](#isgurmukhitext-exhaustive-%E2%87%92-boolean)
* [stripAccents(text) ⇒ String](#stripaccentstext-%E2%87%92-string)
* [stripEndings(text) ⇒ String](#stripendingstext-%E2%87%92-string)
@@ -52,7 +52,6 @@ const {
toUnicode('Koj') // => ਖੋਜ
toAscii('ਖੋਜ') // => Koj
-firstLetters('hir hir hir gunI') // => hhhg
firstLetters('ਹਰਿ ਹਰਿ ਹਰਿ ਗੁਨੀ') // => ਹਹਹਗ
toEnglish('hukmI hukmu clwey rwhu ]') // => hukamee hukam chalaae raahu ||
toHindi('ਕੁਲ ਜਨ ਮਧੇ ਮਿਲੵੋਿ ਸਾਰਗ ਪਾਨ ਰੇ ॥') // => कुल जन मधे मिल्यो सारग पान रे ॥
@@ -73,43 +72,28 @@ Want to play around? [![Try gurmukhi-utils on RunKit](https://badge.runkitcdn.co
## API
-### firstLetters(line, [stripNukta], [withVishraams]) ⇒ String
-Generates the first letters for a given ASCII or unicode Gurmukhi string.
-By default, the function will transform letters with bindi to their simple equivalent,
-for example, zaza to jaja (ਜ਼ => ਜ).
+### 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 | Default | Description |
-| --- | --- | --- | --- |
-| line | String
| | The line to generate the first letters for. |
-| [stripNukta] | Boolean
| true
| If `true`, replaces letters pair bindi (such as ਜ਼) with their equivalent without the bindi (ਜ). Also replaces open oora with closed oora. |
-| [withVishraams] | Boolean
| false
| Keeps the vishraam characters at the end of each word. |
+| Param | Type | Description |
+| --- | --- | --- |
+| line | String
| The line to generate the first letters for. |
-**Example** *(Unicode first letters no pair bindi/nukta)*
-```js
-firstLetters('ਗ਼ੈਰਿ ਹਮਦਿ ਹੱਕ ਨਿਆਇਦ ਬਰ ਜ਼ਬਾਨਮ ਹੀਚ ਗਾਹ') // => ਗਹਹਨਬਜਹਗ
-```
-**Example** *(Unicode first letters with pair bindi/nukta)*
-```js
-firstLetters('ਗ਼ੈਰਿ ਹਮਦਿ ਹੱਕ ਨਿਆਇਦ ਬਰ ਜ਼ਬਾਨਮ ਹੀਚ ਗਾਹ', false) // => ਗ਼ਹਹਨਬਜ਼ਹਗ
-```
-**Example** *(Unicode first letters with vishraams)*
-```js
-firstLetters('ਸਬਦਿ ਮਰੈ. ਸੋ ਮਰਿ ਰਹੈ; ਫਿਰਿ. ਮਰੈ ਨ, ਦੂਜੀ ਵਾਰ ॥', true, true) // => ਸਮ.ਸਮਰ;ਫ.ਮਨ,ਦਵ
-```
-**Example** *(ASCII first letters no pair bindi/nukta)*
+**Example** *(Gurmukhi first letters)*
```js
-firstLetters('ijs no ik®pw krih iqin nwmu rqnu pwieAw ]') // => jnkkqnrp
-firstLetters('iZir&qym sMdUk drIXw AmIk ]') // => gsdA
+firstLetters('ਸਬਦਿ ਮਰੈ. ਸੋ ਮਰਿ ਰਹੈ; ਫਿਰਿ. ਮਰੈ ਨ, ਦੂਜੀ ਵਾਰ ॥') // => ਸਮ.ਸਮਰ;ਫ.ਮਨ,ਦਵ॥
```
-**Example** *(ASCII first letters with pair bindi/nukta)*
+**Example** *(Hindi first letters)*
```js
-firstLetters('iZir&qym sMdUk* drIXw AmIk* ]', false) // => Zsda
+firstLetters('गुरमुखि लाधा मनमुखि गवाइआ ॥') // => गलमग॥
```
-**Example** *(ASCII first letters with vishraams)*
+**Example** *(English first letters)*
```js
-firstLetters('sbid mrY. so mir rhY; iPir. mrY n, dUjI vwr ]', true, true) // => sm.smr;P.mn,dv
+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.
diff --git a/docs/README.md b/docs/README.md
index 7e23ebb..2ccc4c6 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -19,7 +19,7 @@ Want to speak with us?
[![Slack](https://slack.shabados.com/badge.svg)](https
- [Usage](#usage)
- [API](#api)
- * [firstLetters(line, [stripNukta], [withVishraams]) ⇒ String](#firstlettersline-stripnukta-withvishraams-%E2%87%92-string)
+ * [firstLetters(line) ⇒ String](#firstlettersline-%E2%87%92-string)
* [isGurmukhi(text, [exhaustive]) ⇒ boolean](#isgurmukhitext-exhaustive-%E2%87%92-boolean)
* [stripAccents(text) ⇒ String](#stripaccentstext-%E2%87%92-string)
* [stripEndings(text) ⇒ String](#stripendingstext-%E2%87%92-string)
@@ -52,7 +52,6 @@ const {
toUnicode('Koj') // => ਖੋਜ
toAscii('ਖੋਜ') // => Koj
-firstLetters('hir hir hir gunI') // => hhhg
firstLetters('ਹਰਿ ਹਰਿ ਹਰਿ ਗੁਨੀ') // => ਹਹਹਗ
toEnglish('hukmI hukmu clwey rwhu ]') // => hukamee hukam chalaae raahu ||
toHindi('ਕੁਲ ਜਨ ਮਧੇ ਮਿਲੵੋਿ ਸਾਰਗ ਪਾਨ ਰੇ ॥') // => कुल जन मधे मिल्यो सारग पान रे ॥
@@ -73,43 +72,28 @@ Want to play around? [![Try gurmukhi-utils on RunKit](https://badge.runkitcdn.co
## API
-### firstLetters(line, [stripNukta], [withVishraams]) ⇒ String
-Generates the first letters for a given ASCII or unicode Gurmukhi string.
-By default, the function will transform letters with bindi to their simple equivalent,
-for example, zaza to jaja (ਜ਼ => ਜ).
+### 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 | Default | Description |
-| --- | --- | --- | --- |
-| line | String
| | The line to generate the first letters for. |
-| [stripNukta] | Boolean
| true
| If `true`, replaces letters pair bindi (such as ਜ਼) with their equivalent without the bindi (ਜ). Also replaces open oora with closed oora. |
-| [withVishraams] | Boolean
| false
| Keeps the vishraam characters at the end of each word. |
+| Param | Type | Description |
+| --- | --- | --- |
+| line | String
| The line to generate the first letters for. |
-**Example** *(Unicode first letters no pair bindi/nukta)*
-```js
-firstLetters('ਗ਼ੈਰਿ ਹਮਦਿ ਹੱਕ ਨਿਆਇਦ ਬਰ ਜ਼ਬਾਨਮ ਹੀਚ ਗਾਹ') // => ਗਹਹਨਬਜਹਗ
-```
-**Example** *(Unicode first letters with pair bindi/nukta)*
-```js
-firstLetters('ਗ਼ੈਰਿ ਹਮਦਿ ਹੱਕ ਨਿਆਇਦ ਬਰ ਜ਼ਬਾਨਮ ਹੀਚ ਗਾਹ', false) // => ਗ਼ਹਹਨਬਜ਼ਹਗ
-```
-**Example** *(Unicode first letters with vishraams)*
-```js
-firstLetters('ਸਬਦਿ ਮਰੈ. ਸੋ ਮਰਿ ਰਹੈ; ਫਿਰਿ. ਮਰੈ ਨ, ਦੂਜੀ ਵਾਰ ॥', true, true) // => ਸਮ.ਸਮਰ;ਫ.ਮਨ,ਦਵ
-```
-**Example** *(ASCII first letters no pair bindi/nukta)*
+**Example** *(Gurmukhi first letters)*
```js
-firstLetters('ijs no ik®pw krih iqin nwmu rqnu pwieAw ]') // => jnkkqnrp
-firstLetters('iZir&qym sMdUk drIXw AmIk ]') // => gsdA
+firstLetters('ਸਬਦਿ ਮਰੈ. ਸੋ ਮਰਿ ਰਹੈ; ਫਿਰਿ. ਮਰੈ ਨ, ਦੂਜੀ ਵਾਰ ॥') // => ਸਮ.ਸਮਰ;ਫ.ਮਨ,ਦਵ॥
```
-**Example** *(ASCII first letters with pair bindi/nukta)*
+**Example** *(Hindi first letters)*
```js
-firstLetters('iZir&qym sMdUk* drIXw AmIk* ]', false) // => Zsda
+firstLetters('गुरमुखि लाधा मनमुखि गवाइआ ॥') // => गलमग॥
```
-**Example** *(ASCII first letters with vishraams)*
+**Example** *(English first letters)*
```js
-firstLetters('sbid mrY. so mir rhY; iPir. mrY n, dUjI vwr ]', true, true) // => sm.smr;P.mn,dv
+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.
diff --git a/example.js b/example.js
index 2685da4..0150763 100644
--- a/example.js
+++ b/example.js
@@ -13,7 +13,6 @@ const {
console.log(toUnicode( 'Koj' ))
console.log(toAscii('ਖੋਜ'))
-console.log(firstLetters( 'hir hir hir gun gwvhu ]' ))
console.log(firstLetters( 'ਹਰਿ ਹਰਿ ਹਰਿ ਗੁਨੀ' ))
console.log(toEnglish( 'ਹੁਕਮੀ ਹੁਕਮੁ ਚਲਾਏ ਰਾਹੁ ॥' ))
console.log(toShahmukhi( 'ਹਰਿ ਹਰਿ ਹਰਿ ਗੁਨੀ' ))
diff --git a/index.d.ts b/index.d.ts
index 1874e52..8b2365d 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -8,7 +8,7 @@ export function toHindi(text: string): string
export function toShamukhi(text: string): string
-export function firstLetters(text: string, stripNukta?: boolean = true, withVishraams?: boolean): string
+export function firstLetters(text: string): string
export function isGurmukhi(text: string, exhaustive?: boolean): boolean
diff --git a/lib/firstLetters.js b/lib/firstLetters.js
index 0b9968d..03e69be 100644
--- a/lib/firstLetters.js
+++ b/lib/firstLetters.js
@@ -1,80 +1,35 @@
const vishraams = Object.values( require( './vishraams.json' ) )
-// The mappings from the letter-variations to simple Gurmukhi letters in ASCII.
-const asciiBaseLetterMap = {
- E: 'a', // Open oora -> oora
- S: 's', // Shasha -> sasa
- z: 'j', // zaza -> jaja
- Z: 'g', // gaga pair bindi -> gaga
- L: 'l', // lala pair bindi -> lala
- '^': 'K', // Khakha pair bindi -> khakha
- '&': 'P', // Fafa pair bindi -> Fafa
-}
-
-const unicodeBaseLetterMap = {
- ਓ: 'ੳ', // Open oora -> oora
- ਸ਼: 'ਸ', // Shasha -> sasa
- ਜ਼: 'ਜ', // zaza -> jaja
- ਗ਼: 'ਗ', // gaga pair bindi -> gaga
- ਲ਼: 'ਲ', // lala pair bindi -> lala
- ਖ਼: 'ਖ', // Khakha pair bindi -> khakha
- ਫ਼: 'ਫ', // Fafa pair bindi -> Fafa
-}
-
-// Specifies the line terminator characters for both ASCII and unicode Gurmukhi
-const lineTerminators = new Set( [ '।', '॥', ']', '[' ] )
-
-// Combine the base letter maps
-const combinedBaseLetterMap = { ...asciiBaseLetterMap, ...unicodeBaseLetterMap }
-
/**
- * Generates the first letters for a given ASCII or unicode Gurmukhi string.
- * By default, the function will transform letters with bindi to their simple equivalent,
- * for example, zaza to jaja (ਜ਼ => ਜ).
+ * Generates the first letters for a unicode Gurmukhi,
+ * Hindi transliteration, or English transliteration string.
+ * Includes any end-word vishraams, and line-end characters.
+ *
* @param {String} line The line to generate the first letters for.
- * @param {Boolean} [stripNukta=true] If `true`, replaces letters pair bindi (such as ਜ਼)
- * with their equivalent without the bindi (ਜ). Also replaces open oora with closed oora.
- * @param {Boolean} [withVishraams=false] Keeps the vishraam characters at the end of each word.
* @returns {String} The first letters of each word in the provided Gurmukhi line.
*
- * @example