UNPKG

spell-vn-number

Version:
122 lines 9.71 kB
!function(e,t){ "object"===typeof exports&&"object"===typeof module?module.exports=t():"function"===typeof define&&define.amd?define("spellVnNumber",[],t):"object"===typeof exports?exports.spellVnNumber=t():e.spellVnNumber=t() }(this,(function(){return function(){"use strict";function e(i){var r,o=n[i] ;return void 0!==o?o.exports:(r=n[i]={exports:{}},t[i].call(r.exports,r,r.exports,e),r.exports)} var t={116:function(e,t,n){function i(e,t){return void 0===t&&(t={decimalPoint:".", thousandSign:"," }),e.replace(/[\s\u00A0]/g,"").replace(/[\u2013\u2014]/g,"-").replace(new RegExp(r(t.thousandSign||","),"g"),"") }function r(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function o(e,t){ void 0===t&&(t="0");for(var n=0;n<e.length&&e.charAt(n)===t;)n++ ;return n===e.length?t:e.substring(n)}function u(e,t,n){void 0===t&&(t="0"),void 0===n&&(n=!1) ;for(var i=e.length-1;i>=0&&e.charAt(i)===t;)i--;return i<0?n?t:"":e.substring(0,i+1)} Object.defineProperty(t,"__esModule",{value:!0}),t.cleanInputNumber=function(e,t){var n,o ;if(null===e||void 0===e||""===e)throw new a.InvalidFormatError("Input cannot be null or undefined") ;if("bigint"===typeof e)return e.toString();if("number"===typeof e){ if(!Number.isFinite(e)||Number.isNaN(e))throw new a.InvalidFormatError("Input must be a finite number") ;return n=e.toString(),/e/i.test(n)?function(e){var t,n,i,r,o,u,a,s=e.toString() ;return s.includes("e")||s.includes("E")?(n=(t=s.replace(/E/i,"e").split("e"))[0], 0===(i=parseInt(t[1],10))?n:(o=(r=n.includes("."))?n.replace(".",""):n, u=r?n.indexOf("."):n.length, a="",a=(u+=i)<=0?"0."+"0".repeat(-u)+o:u>=o.length?o+"0".repeat(u-o.length):o.substring(0,u)+"."+o.substring(u), n.startsWith("-")&&(a="-"+a.replace("-","")),a)):s}(e):n} if(o=i(e,t),!new RegExp("^-?\\d+("+r(t.decimalPoint||".")+"\\d+)?$").test(o))throw new a.InvalidNumberError("Invalid number format") ;return o },t.normalizeNumberString=i,t.trimLeft=o,t.trimRight=u,t.trimRedundantZeros=function(e,t){ var n,i,r ;return t.includes(e.decimalPoint)?(i=o((n=t.split(e.decimalPoint))[0],e.redundantZeroChar), r=u(n[1],e.redundantZeroChar,e.keepOneZeroWhenAllZeros), "".concat(i).concat(e.decimalPoint).concat(r)):o(t,e.redundantZeroChar)};var a=n(696)}, 696:function(e,t,n){var i,r,o,u,a,s=this&&this.__extends||function(){var e=function(t,n){ return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t }||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)} ;return function(t,n){function i(){this.constructor=t} if("function"!==typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null") ;e(t,n),t.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}}() ;Object.defineProperty(t,"__esModule",{value:!0 }),t.SpellerConfig=t.Idx=t.InvalidNumberError=t.InvalidFormatError=void 0,i=n(116), r=function(e){function t(n){var i=e.call(this,n)||this;return i.name="InvalidFormatError", Object.setPrototypeOf(i,t.prototype),i}return s(t,e),t}(Error),t.InvalidFormatError=r, o=function(e){function t(n){var i=e.call(this,n)||this;return i.name="InvalidNumberError", Object.setPrototypeOf(i,t.prototype),i}return s(t,e),t}(Error),t.InvalidNumberError=o, function(e){e[e.BIL=0]="BIL",e[e.MIL=1]="MIL",e[e.THO=2]="THO",e[e.HUN=3]="HUN", e[e.TEN=4]="TEN",e[e.UNI=5]="UNI"}(u||(t.Idx=u={})),a=function(){function e(e){var t,n,i ;if(void 0===e&&(e={}),this.separator=" ",this.negativeSign="-",this.decimalPoint=".", this.thousandSign=",", this.negativeText="\xe2m",this.pointText="ch\u1ea5m",this.capitalizeInitial=!0, this.currencyUnit="",this.redundantZeroChar="0",this.keepOneZeroWhenAllZeros=!1, this.digitNames={0:"kh\xf4ng",1:"m\u1ed9t",2:"hai",3:"ba",4:"b\u1ed1n",5:"n\u0103m",6:"s\xe1u", 7:"b\u1ea3y",8:"t\xe1m",9:"ch\xedn"},this.unitNames={0:"t\u1ef7",1:"tri\u1ec7u",2:"ngh\xecn", 3:"tr\u0103m",4:"m\u01b0\u01a1i",5:""},this.specificText={oddText:"l\u1ebb", tenText:"m\u01b0\u1eddi",oneToneText:"m\u1ed1t",fourToneText:"t\u01b0",fiveToneText:"l\u0103m"}, e)for(t=Object.keys(e), n=0;n<t.length;n++)"specificText"!==(i=t[n])&&"digitNames"!==i&&"unitNames"!==i&&(this[i]=e[i]) ;(null===e||void 0===e?void 0:e.specificText)&&(this.specificText={ oddText:e.specificText.oddText||this.specificText.oddText, tenText:e.specificText.tenText||this.specificText.tenText, oneToneText:e.specificText.oneToneText||this.specificText.oneToneText, fourToneText:e.specificText.fourToneText||this.specificText.fourToneText, fiveToneText:e.specificText.fiveToneText||this.specificText.fiveToneText }),(null===e||void 0===e?void 0:e.digitNames)&&(this.digitNames={ 0:e.digitNames[0]||this.digitNames[0],1:e.digitNames[1]||this.digitNames[1], 2:e.digitNames[2]||this.digitNames[2],3:e.digitNames[3]||this.digitNames[3], 4:e.digitNames[4]||this.digitNames[4],5:e.digitNames[5]||this.digitNames[5], 6:e.digitNames[6]||this.digitNames[6],7:e.digitNames[7]||this.digitNames[7], 8:e.digitNames[8]||this.digitNames[8],9:e.digitNames[9]||this.digitNames[9] }),(null===e||void 0===e?void 0:e.unitNames)&&(this.unitNames={ 0:e.unitNames[0]||this.unitNames[0],1:e.unitNames[1]||this.unitNames[1], 2:e.unitNames[2]||this.unitNames[2],3:e.unitNames[3]||this.unitNames[3], 4:e.unitNames[4]||this.unitNames[4],5:e.unitNames[5]||this.unitNames[5]})} return e.prototype.getDigit=function(e){return this.digitNames[e] },e.prototype.findUnit=function(e){return this.unitNames[e] },e.prototype.findMagUnit=function(e){ return e===u.BIL?this.unitNames[u.MIL]:e===u.MIL?this.unitNames[u.THO]:this.unitNames[u.UNI]}, Object.defineProperty(e.prototype,"oddText",{get:function(){return this.specificText.oddText}, enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"tenText",{get:function(){ return this.specificText.tenText},enumerable:!1,configurable:!0 }),Object.defineProperty(e.prototype,"oneToneText",{get:function(){ return this.specificText.oneToneText},enumerable:!1,configurable:!0 }),Object.defineProperty(e.prototype,"fourToneText",{get:function(){ return this.specificText.fourToneText},enumerable:!1,configurable:!0 }),Object.defineProperty(e.prototype,"fiveToneText",{get:function(){ return this.specificText.fiveToneText},enumerable:!1,configurable:!0 }),e.prototype.parseNumberData=function(e){ var t,n=(0,i.cleanInputNumber)(e,this),r=n.startsWith(this.negativeSign) ;return-1===(t=(n=r?n.substring(this.negativeSign.length):n).indexOf(this.decimalPoint))?{ isNegative:r,integralPart:n=(0,i.trimLeft)(n,this.redundantZeroChar),fractionalPart:""}:{ isNegative:r,integralPart:(0,i.trimLeft)(n.substring(0,t),this.redundantZeroChar), fractionalPart:(0, i.trimRight)(n.substring(t+1),this.redundantZeroChar,this.keepOneZeroWhenAllZeros)}},e}(), t.SpellerConfig=a},740:function(e,t,n){function i(e,t,n){var i,a,f,p,d,m,h,g,b,T,N ;if(""===n)return[] ;for(d=0===(p=(f=(a=0!==(i=n.length%l)?"0".repeat(l-i)+n:n).length/l)%c)?f/c:Math.floor(f/c)+1, m=0!==p?c-p:s.Idx.BIL,h=!0,g=0;d>0;){for(h||e.push(t.findUnit(m));m<c;m++)b=a[g],T=a[g+1], N=a[g+2],g+=3,h?("0"!==b&&(h=!1,u(e,t,b,T,N)),h&&"0"===T||(h=!1,o(e,t,T,N)),h&&"0"===N||(h=!1, r(e,t,b,T,N,m)),h&&(h=!1,e.push(t.getDigit("0")))):(u(e,t,b,T,N),o(e,t,T,N),r(e,t,b,T,N,m));d--, m=s.Idx.BIL}return e}function r(e,t,n,i,r,o){ "0"!==r?("1"===r?"0"!==i&&"1"!==i?e.push(t.oneToneText):e.push(t.getDigit(r)):"4"===r?"0"!==i&&"1"!==i?e.push(t.fourToneText):e.push(t.getDigit(r)):"5"===r&&"0"!==i?e.push(t.fiveToneText):e.push(t.getDigit(r)), o!==s.Idx.THO&&e.push(t.findMagUnit(o))):"0"===i&&"0"===n||o!==s.Idx.THO&&e.push(t.findMagUnit(o)) }function o(e,t,n,i){ "0"===n?"0"!==i&&e.push(t.oddText):"1"===n?e.push(t.tenText):(e.push(t.getDigit(n)), e.push(t.findUnit(s.Idx.TEN)))}function u(e,t,n,i,r){ "0"===n&&"0"===i&&"0"===r||(e.push(t.getDigit(n)),e.push(t.findUnit(s.Idx.HUN)))} function a(e,t){var n,r,o=e.parseNumberData(t),u=[];return o.isNegative&&u.push(e.negativeText), i(u,e,o.integralPart),o.fractionalPart.length>0&&(u.push(e.pointText),i(u,e,o.fractionalPart)), e.capitalizeInitial&&(n=u[0],u[0]=n.charAt(0).toUpperCase()+n.slice(1)),r=u.join(e.separator), e.currencyUnit&&(r+=" ".concat(e.currencyUnit)),r}var s,c,l ;Object.defineProperty(t,"__esModule",{value:!0}),t.spellVnNumber=a,t.spell=function(e){ return a(new s.SpellerConfig,e)},t.spellOrDefault=function(e,t,n){void 0===t&&(t={}) ;var i=new s.SpellerConfig(t);try{return a(i,e)}catch(r){if(void 0===n)throw r ;return r instanceof s.InvalidFormatError||s.InvalidNumberError,n}},s=n(696),c=3,l=3}},n={},i={} ;return function(){var t,n,r,o=i;Object.defineProperty(o,"__esModule",{value:!0}), o.normalizeNumberString=o.trimRedundantZeros=o.cleanInputNumber=o.spellOrDefault=o.spellVnNumber=o.spell=o.InvalidNumberError=o.InvalidFormatError=o.SpellerConfig=void 0, t=e(696),Object.defineProperty(o,"SpellerConfig",{enumerable:!0,get:function(){ return t.SpellerConfig}}),Object.defineProperty(o,"InvalidFormatError",{enumerable:!0, get:function(){return t.InvalidFormatError}}),Object.defineProperty(o,"InvalidNumberError",{ enumerable:!0,get:function(){return t.InvalidNumberError} }),n=e(740),Object.defineProperty(o,"spell",{enumerable:!0,get:function(){return n.spell}}), Object.defineProperty(o,"spellVnNumber",{enumerable:!0,get:function(){return n.spellVnNumber}}), Object.defineProperty(o,"spellOrDefault",{enumerable:!0,get:function(){return n.spellOrDefault} }),r=e(116),Object.defineProperty(o,"cleanInputNumber",{enumerable:!0,get:function(){ return r.cleanInputNumber}}),Object.defineProperty(o,"trimRedundantZeros",{enumerable:!0, get:function(){return r.trimRedundantZeros}}),Object.defineProperty(o,"normalizeNumberString",{ enumerable:!0,get:function(){return r.normalizeNumberString}})}(),i}()}));