bindu 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ChangeLog CHANGED
@@ -1,3 +1,13 @@
1
+ 2025.12.07, v1.1.0
2
+
3
+ feature:
4
+ - 0623c50 bindu: add sandhi: dirgha, yan
5
+
6
+ 2025.12.07, v1.0.2
7
+
8
+ fix:
9
+ - 5293d7b readme: examples
10
+
1
11
  2025.12.07, v1.0.1
2
12
 
3
13
  fix:
package/README.md CHANGED
@@ -26,9 +26,9 @@ npm i bindu -g
26
26
  ```js
27
27
  import {bindu} from 'bindu';
28
28
 
29
- const {code} = bindu('प्रतिएक');
29
+ bindu('प्रतिएक');
30
+ // returns {code: 'प्रत्येक';A'}
30
31
 
31
- // 'प्रत्येक';
32
32
  const {places} = bindu('प्रतिएक', {
33
33
  fix: false,
34
34
  });
@@ -39,7 +39,8 @@ places[0].message;
39
39
 
40
40
  ## Rules
41
41
 
42
- - ✅ [`apply-vriddhi`](https://putout.cloudcmd.io/#/gist/59a1854deb359883a3a6e1eb60e82e21/23f7ee70713f9b32cce13774a9bef454bc0f2ce0`);
42
+ - ✅[`sandhi/apply-dirgha`](https://putout.cloudcmd.io/#/gist/0ad8154614be489ae50931109618100a/5ce86f7344b37fd40afeb229e6cb1f668d4f92fd);
43
+ - ✅[`sandhi/apply-yan`](https://putout.cloudcmd.io/#/gist/3091528d3d3eb095032fbec200599df0/c4dcefa2d29fd85f9d3d768b6eaf6934fd5a3fbb);
43
44
 
44
45
  ## License
45
46
 
package/lib/bindu.js CHANGED
@@ -1,16 +1,19 @@
1
1
  import putout from 'putout';
2
2
  import Sanscript from '@indic-transliteration/sanscript';
3
- import * as applyVriddhi from './plugins/apply-vriddhi/index.js';
3
+ import * as sandhi from './sandhi/index.js';
4
4
 
5
- const toIAST = (a) => Sanscript.t(a, 'devanagari', 'iast');
6
- const toDevanagari = (a) => Sanscript.t(a, 'iast', 'devanagari');
5
+ export const toSLP1 = (a) => Sanscript.t(a, 'devanagari', 'slp1');
6
+ export const toDevanagari = (a) => Sanscript.t(a, 'slp1', 'devanagari');
7
7
 
8
8
  export const bindu = (text, {fix = true} = {}) => {
9
- const source = toIAST(text).replaceAll(' ', ',');
9
+ const source = toSLP1(text)
10
+ .replaceAll(' ', ',')
11
+ .replaceAll('|', '_');
12
+
10
13
  const {code, places} = putout(source, {
11
14
  fix,
12
15
  plugins: [
13
- ['apply-vriddhi', applyVriddhi],
16
+ ['sandhi', sandhi],
14
17
  ],
15
18
  });
16
19
 
@@ -19,7 +22,7 @@ export const bindu = (text, {fix = true} = {}) => {
19
22
  .slice(0, -1);
20
23
 
21
24
  return {
22
- code: toDevanagari(cleanText),
25
+ code: toDevanagari(cleanText).replaceAll('_', '|'),
23
26
  places,
24
27
  };
25
28
  };
@@ -0,0 +1,43 @@
1
+ import {operator} from 'putout';
2
+
3
+ const {remove} = operator;
4
+
5
+ export const report = () => `akaḥ savarṇe dīrghaḥ`;
6
+
7
+ export const fix = ({path, next, name, nextName, dirgha}) => {
8
+ path.node.name = `${name.slice(0, -1)}${dirgha}${nextName.slice(-1)}`;
9
+ remove(next);
10
+ };
11
+
12
+ export const traverse = ({push}) => ({
13
+ Identifier(path) {
14
+ const next = path.getNextSibling();
15
+
16
+ if (!next.node)
17
+ return;
18
+
19
+ const {name} = path.node;
20
+ const nextName = next.node.name;
21
+
22
+ const last = name
23
+ .at(-1)
24
+ .toLowerCase();
25
+
26
+ const first = nextName
27
+ .at(0)
28
+ .toLowerCase();
29
+
30
+ if (last !== first)
31
+ return;
32
+
33
+ const dirgha = first.toUpperCase();
34
+
35
+ push({
36
+ path,
37
+ next,
38
+ dirgha,
39
+ name,
40
+ nextName,
41
+ });
42
+ },
43
+ });
@@ -0,0 +1,66 @@
1
+ import {operator} from 'putout';
2
+
3
+ const {remove} = operator;
4
+ const {keys} = Object;
5
+
6
+ const SANDHI = {
7
+ i: 'y',
8
+ u: 'v',
9
+ f: 'r',
10
+ x: 'l',
11
+ };
12
+
13
+ const YAN = keys(SANDHI);
14
+
15
+ const SVARA = [
16
+ 'a',
17
+ 'i',
18
+ 'u',
19
+ 'f',
20
+ 'x',
21
+ 'e',
22
+ 'o',
23
+ ];
24
+
25
+ export const report = () => `acvaṅgā ya va ra la`;
26
+
27
+ export const fix = ({path, next, name, nextName, yan}) => {
28
+ path.node.name = `${name.slice(0, -1)}${yan}${nextName}`;
29
+ remove(next);
30
+ };
31
+
32
+ export const traverse = ({push}) => ({
33
+ Identifier(path) {
34
+ const next = path.getNextSibling();
35
+
36
+ if (!next.node)
37
+ return;
38
+
39
+ const {name} = path.node;
40
+ const nextName = next.node.name;
41
+
42
+ const last = name
43
+ .at(-1)
44
+ .toLowerCase();
45
+
46
+ const first = nextName
47
+ .at(0)
48
+ .toLowerCase();
49
+
50
+ if (!SVARA.includes(first))
51
+ return;
52
+
53
+ if (!YAN.includes(last))
54
+ return;
55
+
56
+ const yan = SANDHI[last];
57
+
58
+ push({
59
+ path,
60
+ next,
61
+ name,
62
+ nextName,
63
+ yan,
64
+ });
65
+ },
66
+ });
@@ -0,0 +1,7 @@
1
+ import * as applyYan from './apply-yan/index.js';
2
+ import * as applyDirgha from './apply-dirgha/index.js';
3
+
4
+ export const rules = {
5
+ 'apply-dirgha': applyDirgha,
6
+ 'apply-yan': applyYan,
7
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bindu",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "description": "Pāṇini Aṣṭādhyāyī",
5
5
  "main": "lib/bindu.js",
6
6
  "bin": {
@@ -1,31 +0,0 @@
1
- const {entries} = Object;
2
-
3
- const VRIDDHI = {
4
- ie: 'ye',
5
- ai: 'e',
6
- ia: 'ya',
7
- };
8
-
9
- export const report = ({from, to}) => `vṛddhirādaic: ${from} -> ${to}`;
10
-
11
- export const traverse = ({push}) => ({
12
- Identifier(path) {
13
- const {name} = path.node;
14
-
15
- for (const [from, to] of entries(VRIDDHI)) {
16
- if (name.includes(from)) {
17
- push({
18
- path,
19
- from,
20
- to,
21
- });
22
- return;
23
- }
24
- }
25
- },
26
- });
27
-
28
- export function fix({path, from, to}) {
29
- const {name} = path.node;
30
- path.node.name = name.replace(from, to);
31
- }