Skip to content

Commit b7438ad

Browse files
committed
flexible get() query
and get the result returned as Object if there is a sense in get query, otherwise Boolean (`false`) return.
1 parent 5685247 commit b7438ad

File tree

5 files changed

+57
-42
lines changed

5 files changed

+57
-42
lines changed

README.md

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,50 @@
11
# myanmar-notation
2-
...get Myanmar digital and notation
2+
...`get()` Myanmar digital and notation
33

44
Install `npm i myanmar-notation` then require...
55

66

77
```js
88
let notation = require('myanmar-notation');
99
```
10-
and get the results...
10+
... and get the result returned as Object if there is a sense in get query, otherwise Boolean (`false`) return.
11+
12+
- [x] Return formatted Numeric
13+
- [x] Decimals are rounded (floor)
14+
- [x] Query `get(2700)`, `get('၂၇ဝဝ')`, `get('2,700.00')` is flexible
15+
1116
```js
12-
let result = notation.get('2700');
13-
// the result returned as Object
17+
notation.get('2700');
18+
// return
1419
{
1520
"Numeric": "၂,၇ဝဝ",
16-
"Notation": [{
17-
"sense": "နှစ်ထောင်နှင့် ခုနစ်ရာ"
18-
}]
21+
"Notation": [
22+
{
23+
"sense": "နှစ်ထောင်နှင့် ခုနစ်ရာ"
24+
}
25+
]
1926
}
2027

21-
let result = notation.get('27000000');
28+
notation.get('27000000');
29+
// return
2230
{
2331
"Numeric": "၂၇,ဝဝဝ,ဝဝဝ",
24-
"Notation": [{
25-
"sense": "သိန်းပေါင်း နှစ်ရာ့ခုနစ်ဆယ်",
26-
"exam": {
27-
"1": 22
28-
}
32+
"Notation": [
33+
{
34+
"sense": "သိန်းပေါင်း နှစ်ရာ့ခုနစ်ဆယ်"
2935
},
3036
{
31-
"sense": "သန်းပေါင်း နှစ်ဆယ့်ခုနစ်",
32-
"exam": {
33-
"1": 22
34-
}
37+
"sense": "သန်းပေါင်း နှစ်ဆယ့်ခုနစ်"
3538
},
3639
{
3740
"sense": "နှစ်ကု​ဋေ​နှင့် ခုနစ်သန်း"
3841
}
3942
]
4043
}
44+
4145
// Reverse
42-
let result = notation.get('၈၆ဝ');
46+
notation.get('၈၆ဝ');
47+
// return
4348
{
4449
"Numeric": "860",
4550
"Notation": [

notation.js

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module.exports = class Notation {
2626
return this.config.conjunction;
2727
}
2828
get(query) {
29-
let q=Number(query).toString(),t=0;
29+
let q=Math.floor(Number(query.replace(/,\s?/g, ""))).toString(),t=0;
3030
if (isNaN(q)){
3131
q=this.getUni(query),t=1;
3232
if (q<1 || isNaN(q)) return false;
@@ -35,12 +35,12 @@ module.exports = class Notation {
3535
}
3636
getUni(query) {
3737
let n = query.toString().split('').map(k=> {
38-
if (this.config.digit.indexOf(k) >= 0) return this.config.digit.indexOf(k);
38+
return (this.config.digit.indexOf(k) >= 0)?this.config.digit.indexOf(k):k;
3939
}).filter(function(e){return e == 0 || e}).join('');
40-
return Number(n).toString();
40+
return Math.floor(Number(n.replace(/,\s?/g, ""))).toString();
4141
}
4242
getResult(q,t) {
43-
let n = this.requestFormat(q); // m = this.requestDigit(n);
43+
let n = this.requestFormat(q);
4444
return {
4545
Numeric:(t)?n:this.requestDigit(n),
4646
Notation:this.config.task.map(k=>{
@@ -54,7 +54,7 @@ module.exports = class Notation {
5454
this.config.task=[];
5555
return {
5656
// "sense":this.requestCreakyTone(q)
57-
"sense":this.requestNormalTone(q)
57+
"sense":this.requestWrittenTone(q)
5858
}
5959
}
6060
return false;
@@ -82,7 +82,7 @@ module.exports = class Notation {
8282
// prime, base, baseName, rest, restName, tail, tailName
8383
rawSense.push(this.requestPrime(rulePrime,s)+this.requestCreakyTone(q,0,ruleExtract));
8484
rawSense.push(this.requestCreakyTone(q,rulePrime, s+1));
85-
rawSense.push(this.requestNormalTone(q,s+1, q.length));
85+
rawSense.push(this.requestWrittenTone(q,s+1, q.length));
8686
examNotation={
8787
1:21
8888
};
@@ -96,11 +96,8 @@ module.exports = class Notation {
9696
rawSense.push(this.requestPrime(rulePrime,s,true)+this.requestCreakyTone(q,0,ruleExtract));
9797
rawSense.push(this.requestCreakyTone(q,ruleExtract, q.length));
9898

99-
examNotation={
100-
1:22
101-
};
99+
examNotation={1:22};
102100
}
103-
104101
} else {
105102
if (s == rawEndCount) {
106103
ruleExtract=rawCount;
@@ -111,10 +108,7 @@ module.exports = class Notation {
111108

112109
rawSense.push(this.requestPrime(rulePrime,s)+this.requestCreakyTone(q,0,ruleExtract)+rawOver);
113110

114-
examNotation={
115-
test:'??',
116-
1:31
117-
};
111+
examNotation={1:31};
118112
} else {
119113
let abc=false;
120114
ruleExtract=rawCount-1+rawEndCount;
@@ -169,7 +163,7 @@ module.exports = class Notation {
169163
return k.name+k.tone;
170164
}).join('')
171165
}
172-
requestNormalTone(num,from,to) {
166+
requestWrittenTone(num,from,to) {
173167
let str = this.strIntersect(num,from,to);
174168
return this.requestObject(str,(position,next,tone)=>{
175169
return tone;
@@ -217,7 +211,6 @@ module.exports = class Notation {
217211
return e;
218212
}
219213
strIntersect(str,from,to) {
220-
// str.toString()
221214
if (to){
222215
return str.substring(from, to).split('');
223216
} else{

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "myanmar-notation",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"description": "get Myanmar digital and notation",
55
"main": "index.js",
66
"scripts": {

test.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
11
const fs = require('fs');
22
let notation = require('./notation');
33
let query = process.argv.slice(2)[0];
4-
// query = '၁,၂ဝဝဝဝဝ';
5-
query = '၈၆ဝ';
4+
// query = '10,000';
5+
// query = '၁,၂ဝဝဝဝဝ.၂ဝ';
6+
// query = '၈၆ဝ';
67

78
let raw = new notation().get(query);
8-
// raw.Query=query;
9+
raw.Query=query;
910
fs.writeFile("./test.json", JSON.stringify(raw, null, 2), 'utf8', function (err) {
1011
if (err) {
1112
return console.log(err);
1213
}
1314
console.log(" ...done");
14-
});
15+
});
16+
/*
17+
100000
18+
000000
19+
->10
20+
21+
100000
22+
000000
23+
000000
24+
25+
100000
26+
000000
27+
000000
28+
000000
29+
30+
*/

test.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
2-
"Numeric": "860",
2+
"Numeric": "၄၅",
33
"Notation": [
44
{
5-
"sense": "ရှစ်ရာနှင့် ခြောက်ဆယ်"
5+
"sense": "လေးဆယ်နှင့် ငါး"
66
}
7-
]
7+
],
8+
"Query": "45"
89
}

0 commit comments

Comments
 (0)