1+ module . exports = class Notation {
2+ constructor ( ) {
3+ this . config = {
4+ name :[ "သုည" , "တစ်" , "နှစ်" , "သုံး" , "လေး" , "ငါး" , "ခြောက်" , "ခုနစ်" , "ရှစ်" , "ကိုး" ] ,
5+ digit :[ "ဝ" , "၁" , "၂" , "၃" , "၄" , "၅" , "၆" , "၇" , "၈" , "၉" ] ,
6+ // 1:"ခု",
7+ tone :{ 1 :"" , 2 :"ဆယ်" , 3 :"ရာ" , 4 :"ထောင်" , 5 :"သောင်း" , 6 :"သိန်း" , 7 :"သန်း" , 8 :"ကုဋေ" } ,
8+ creaky :{ 2 :"ဆယ့်" , 3 :"ရာ့" , 4 :"ထောင့်" } ,
9+ conjunction :{ space :" " , comma :"၊ " , and :"နှင့်" , plus :"ပေါင်း" , over :"ကျော်" , times :"ကြိမ်" } ,
10+ task :[ 6 , 7 , 8 ]
11+ }
12+ }
13+ configName ( ) {
14+ return this . config . name ;
15+ }
16+ configDigit ( ) {
17+ return this . config . digit ;
18+ }
19+ configTone ( ) {
20+ return this . config . tone ;
21+ }
22+ configCreaky ( ) {
23+ return this . config . creaky ;
24+ }
25+ configConjunction ( ) {
26+ return this . config . conjunction ;
27+ }
28+ get ( query ) {
29+ let q = Math . floor ( Number ( query . toString ( ) . replace ( / , \s ? / g, "" ) ) ) . toString ( ) , t = 0 ;
30+ if ( isNaN ( q ) ) {
31+ q = this . getUni ( query ) , t = 1 ;
32+ if ( q < 1 || isNaN ( q ) ) return false ;
33+ }
34+ return this . getResult ( q , t ) ;
35+ }
36+ getUni ( query ) {
37+ let n = query . toString ( ) . split ( '' ) . map ( k => {
38+ return ( this . config . digit . indexOf ( k ) >= 0 ) ?this . config . digit . indexOf ( k ) :k ;
39+ } ) . filter ( function ( e ) { return e == 0 || e } ) . join ( '' ) ;
40+ return Math . floor ( Number ( n . replace ( / , \s ? / g, "" ) ) ) . toString ( ) ;
41+ }
42+ getResult ( q , t ) {
43+ let n = this . requestFormat ( q ) ;
44+ return {
45+ Numeric :( t ) ?n :this . requestDigit ( n ) ,
46+ Notation :this . config . task . map ( k => {
47+ return this . requestTask ( q , k ) ;
48+ } ) . filter ( function ( e ) { return e } )
49+ } ;
50+ }
51+ requestTask ( q , s ) {
52+ if ( q . length <= s ) {
53+ if ( this . config . task . length ) {
54+ this . config . task = [ ] ;
55+ return {
56+ // sense:this.requestCreakyTone(q)
57+ sense :this . requestWrittenTone ( q )
58+ }
59+ }
60+ return false ;
61+ }
62+ let raw = this . strSeparate ( q , s ) ;
63+ let rawCount = raw . length ;
64+ let rawEnd = raw . slice ( - 1 ) [ 0 ] ;
65+ let rawEndCount = rawEnd . length ;
66+
67+ let ruleExtract = rawEndCount ;
68+ let rulePrime = rawCount ;
69+ let ruleMax = Object . keys ( this . config . tone ) . length ;
70+ let rawSense = [ ] ;
71+
72+ // let Measure=this.config.tone[s];
73+ // let ConjunctionPlus=this.config.conjunction.plus;
74+ // let PrefixeTimes='';
75+ // let SuffixeMeasure='';
76+
77+ let examNotation = false ;
78+
79+ if ( rawCount < 3 ) {
80+ if ( s == rawEndCount ) {
81+ ruleExtract = rawCount ;
82+ // prime, base, baseName, rest, restName, tail, tailName
83+ rawSense . push ( this . requestPrime ( rulePrime , s ) + this . requestCreakyTone ( q , 0 , ruleExtract ) ) ;
84+ rawSense . push ( this . requestCreakyTone ( q , rulePrime , s + 1 ) ) ;
85+ rawSense . push ( this . requestWrittenTone ( q , s + 1 , q . length ) ) ;
86+ // examNotation={1:21};
87+ } else {
88+ if ( rawCount > rawEndCount ) {
89+ ruleExtract = rawCount ;
90+ } else {
91+ ruleExtract = rawEndCount + 1 ;
92+ }
93+ rulePrime = 1 ;
94+ rawSense . push ( this . requestPrime ( rulePrime , s , true ) + this . requestCreakyTone ( q , 0 , ruleExtract ) ) ;
95+ rawSense . push ( this . requestCreakyTone ( q , ruleExtract , q . length ) ) ;
96+ // examNotation={1:22};
97+ }
98+ } else {
99+ if ( s == rawEndCount ) {
100+ ruleExtract = rawCount ;
101+ let rawOver = '' ;
102+ if ( Number ( q . substring ( ruleExtract , q . length ) ) ) {
103+ rawOver = this . config . conjunction . over ;
104+ }
105+ rawSense . push ( this . requestPrime ( rulePrime , s ) + this . requestCreakyTone ( q , 0 , ruleExtract ) + rawOver ) ;
106+ // examNotation={1:31};
107+ } else {
108+ ruleExtract = rawCount - 1 + rawEndCount ;
109+ rulePrime = rawCount - 1 ;
110+ // ruleExtract=rawCount;
111+ if ( ruleExtract > ruleMax ) {
112+ ruleExtract = rawEndCount - 3 ;
113+ rulePrime = rawCount ;
114+ }
115+ let rawOver = '' ;
116+ // if (Number(q.substring(ruleExtract, q.length))){
117+ // rawOver=this.config.conjunction.over;
118+ // }
119+ let leftOver = q . substring ( ruleExtract , q . length ) ;
120+ if ( Number ( leftOver ) ) {
121+ rawOver = this . config . conjunction . over ;
122+ // leftOver = q.substring(ruleExtract, q.length-s);
123+ leftOver = q . substring ( ruleExtract , q . length - s ) ;
124+ }
125+ // 1234567000000==100000*12300000+4567000000
126+ // 1234567000000==100000*123 45670
127+ // 1234567000000000==100000*12345 600000+7000 000000
128+ rawSense . push ( this . requestPrime ( rulePrime , s ) + this . requestCreakyTone ( q , 0 , ruleExtract ) + rawOver ) ;
129+ examNotation = {
130+ working :true ,
131+ a1 :q ,
132+ raw :raw ,
133+ b11 :q . substring ( 0 , ruleExtract ) ,
134+ b12 :q . substring ( ruleExtract , s + 2 ) ,
135+ b13 :q . substring ( ruleExtract , q . length ) ,
136+ // sample:q.substring(ruleExtract,8),
137+ a3 :leftOver ,
138+ s :s ,
139+ ruleExtract :ruleExtract ,
140+ cut :s + ruleExtract ,
141+ a4 :leftOver . length ,
142+ a5 :this . strSeparate ( q . substring ( ruleExtract , q . length ) , ruleExtract )
143+ } ;
144+ }
145+ }
146+
147+ return {
148+ sense :this . createString ( rawSense ) ,
149+ exam : examNotation
150+ } ;
151+ }
152+ requestObject ( str , callback ) {
153+ let strCount = str . length , e = [ ] ;
154+ // let testing = this.config.tone.reverse()
155+ // let strReverse = str.reverse(); index += to, ++index
156+ for ( let index = 0 ; index < strCount ; ++ index ) {
157+ let position = strCount - index ;
158+ let digit = str [ index ] , next = index + 1 ;
159+ let tone = this . config . tone . hasOwnProperty ( position ) ?this . config . tone [ position ] :'' ;
160+
161+ if ( digit > 0 ) e . push ( {
162+ name :this . config . name [ digit ] ,
163+ tone :callback ( position , next , tone )
164+ } ) ;
165+ }
166+ return e ;
167+ }
168+ requestCreakyTone ( num , from , to ) {
169+ let str = this . strIntersect ( num , from , to ) ;
170+ return this . requestObject ( str , ( position , next , tone ) => {
171+ if ( str . hasOwnProperty ( next ) && str [ next ] > 0 ) {
172+ return this . config . creaky . hasOwnProperty ( position ) ?this . config . creaky [ position ] :tone ;
173+ }
174+ return tone ;
175+ } ) . map ( ( k , index ) => {
176+ return k . name + k . tone ;
177+ } ) . join ( ' ' )
178+ }
179+ requestWrittenTone ( num , from , to ) {
180+ let str = this . strIntersect ( num , from , to ) ;
181+ return this . requestObject ( str , ( position , next , tone ) => {
182+ return tone ;
183+ } ) . map ( ( k , index , e ) => {
184+ if ( ( e . length - 2 ) == index ) {
185+ return k . name + k . tone + this . config . conjunction . and ;
186+ }
187+ return k . name + k . tone ;
188+ } ) . join ( ' ' ) ;
189+ }
190+ requestCreakyTail ( num , from , to ) {
191+ let str = this . strIntersect ( num , from , to ) ;
192+ return this . requestObject ( str , ( position , next , tone ) => {
193+ if ( str . hasOwnProperty ( next ) && this . config . creaky . hasOwnProperty ( position ) && str [ next ] > 0 ) {
194+ return { normal :tone , creaky :this . config . creaky [ position ] } ;
195+ }
196+ return { normal :tone }
197+ } ) . map ( ( k , index , e ) => {
198+ if ( ( e . length - 2 ) == index ) {
199+ return k . name + k . tone . hasOwnProperty ( 'creaky' ) ?k . name + k . tone . creaky :k . name + k . tone . normal ;
200+ }
201+ return k . name + k . tone . normal ;
202+ } ) . join ( ' ' ) ;
203+ }
204+ requestDigit ( n ) {
205+ return n . split ( '' ) . map ( k => {
206+ return this . config . digit . hasOwnProperty ( k ) ?this . config . digit [ k ] :k ;
207+ } ) . join ( '' ) ;
208+ }
209+ requestFormat ( n ) {
210+ return n . replace ( / ( \d ) (? = ( \d { 3 } ) + (? ! \d ) ) / g, "$1," ) ;
211+ }
212+ requestPrime ( l , k , s ) {
213+ let i = 0 , e = [ ] ;
214+ while ( i < l ) { e . push ( this . config . tone [ k ] ) ; i ++ ; }
215+ if ( s ) e . push ( '' ) ;
216+ return e . join ( this . config . conjunction . plus + this . config . conjunction . space ) ;
217+ }
218+ createString ( n ) {
219+ return n . filter ( function ( e ) { return e } ) . join ( this . config . conjunction . and + this . config . conjunction . space )
220+ }
221+ strSeparate ( str , n ) {
222+ let e = new Array ;
223+ for ( let index = 0 ; index < str . length ; index += n ) e . push ( str . substr ( index , n ) ) ;
224+ return e ;
225+ }
226+ strIntersect ( str , from , to ) {
227+ if ( to ) {
228+ return str . substring ( from , to ) . split ( '' ) ;
229+ } else {
230+ return str . split ( '' ) ;
231+ }
232+ }
233+ }
0 commit comments