Skip to content

Commit 173c577

Browse files
committed
feature: bindu: process: add
1 parent 0941b75 commit 173c577

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

lib/bindu.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
import putout from 'putout';
22
import Sanscript from '@indic-transliteration/sanscript';
33
import * as sandhi from './sandhi/index.js';
4-
import {danda, avagraha} from './symbols.js';
4+
import {postProcess, preProcess} from './process.js';
55

66
export const toSLP1 = (a) => Sanscript.t(a, 'devanagari', 'slp1');
77
export const toDevanagari = (a) => Sanscript.t(a, 'slp1', 'devanagari');
88

99
export const bindu = (text, overrides = {}) => {
1010
const {fix = true, type} = overrides;
11-
const source = toSLP1(text)
12-
.replaceAll(' ', ',')
13-
.replaceAll(avagraha.spl1, avagraha.code)
14-
.replaceAll(danda.spl1, danda.code);
11+
const source = preProcess(text);
1512

1613
const {code, places} = putout(source, {
1714
fix,
@@ -20,11 +17,7 @@ export const bindu = (text, overrides = {}) => {
2017
],
2118
});
2219

23-
const cleanText = code
24-
.replaceAll(/[,;()]/g, '')
25-
.replaceAll(avagraha.code, avagraha.spl1)
26-
.replaceAll(danda.code, danda.spl1)
27-
.slice(0, -1);
20+
const cleanText = postProcess(code);
2821

2922
if (type === 'slp1')
3023
return {

lib/process.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {toSLP1} from './bindu.js';
2+
import {avagraha, danda} from './symbols.js';
3+
4+
export const preProcess = (text) => {
5+
return toSLP1(text)
6+
.replaceAll(' ', ',')
7+
.replaceAll(avagraha.spl1, avagraha.code)
8+
.replaceAll(danda.spl1, danda.code);
9+
};
10+
11+
export const postProcess = (code) => {
12+
return code
13+
.replaceAll(/[,;()]/g, '')
14+
.replaceAll(avagraha.code, avagraha.spl1)
15+
.replaceAll(danda.code, danda.spl1)
16+
.slice(0, -1);
17+
};

0 commit comments

Comments
 (0)