reduce-precision 1.0.2 → 1.0.3
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/README.md +28 -19
- package/lib/bundle.min.js +1 -0
- package/lib/format/index.d.ts +15 -14
- package/lib/format/index.js +52 -20
- package/package.json +11 -3
package/README.md
CHANGED
|
@@ -59,20 +59,26 @@ console.log(formatter.toJson(123456789));
|
|
|
59
59
|
console.log(formatter.toString(123456789));
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
+
### Browser
|
|
63
|
+
|
|
64
|
+
```html
|
|
65
|
+
<script src="https://cdn.jsdelivr.net/npm/reduce-precision/lib/bundle.min.js"></script>
|
|
66
|
+
```
|
|
67
|
+
|
|
62
68
|
## Options
|
|
63
69
|
|
|
64
70
|
The `format` function accepts an optional `options` object with the following properties:
|
|
65
71
|
|
|
66
|
-
| Option
|
|
67
|
-
|
|
|
68
|
-
| `precision`
|
|
69
|
-
| `template`
|
|
70
|
-
| `language`
|
|
71
|
-
| `outputFormat`
|
|
72
|
-
| `prefixMarker`
|
|
73
|
-
| `postfixMarker` | `string`
|
|
74
|
-
| `prefix`
|
|
75
|
-
| `postfix`
|
|
72
|
+
| Option | Type | Default | Description |
|
|
73
|
+
| --------------- | ---------------------------------------------------------- | ---------- | ----------------------------------------------------- |
|
|
74
|
+
| `precision` | `'auto'` \| `'high'` \| `'medium'` \| `'low'` | `'high'` | Precision level for formatting |
|
|
75
|
+
| `template` | `'number'` \| `'usd'` \| `'irt'` \| `'irr'` \| `'percent'` | `'number'` | Template for formatting |
|
|
76
|
+
| `language` | `'en'` \| `'fa'` | `'en'` | Language for formatting (English or Persian) |
|
|
77
|
+
| `outputFormat` | `'plain'` \| `'html'` \| `'markdown'` | `'plain'` | Output format |
|
|
78
|
+
| `prefixMarker` | `string` | `'i'` | Prefix marker for HTML and Markdown output |
|
|
79
|
+
| `postfixMarker` | `string` | `'i'` | Postfix marker for HTML and Markdown output |
|
|
80
|
+
| `prefix` | `string` | `''` | Prefix string to be added before the formatted number |
|
|
81
|
+
| `postfix` | `string` | `''` | Postfix string to be added after the formatted number |
|
|
76
82
|
|
|
77
83
|
## Examples
|
|
78
84
|
|
|
@@ -90,7 +96,7 @@ const formatterWithOptions = new NumberFormatter({
|
|
|
90
96
|
prefixMarker: 'strong',
|
|
91
97
|
postfixMarker: 'em',
|
|
92
98
|
prefix: 'مبلغ: ',
|
|
93
|
-
postfix: ' ریال'
|
|
99
|
+
postfix: ' ریال',
|
|
94
100
|
});
|
|
95
101
|
|
|
96
102
|
// Basic usage
|
|
@@ -114,12 +120,16 @@ formatter.setTemplate('percent', 'low').toJson(0.1234); // Output: { value: '0.1
|
|
|
114
120
|
|
|
115
121
|
// Formatting with HTML output and custom markers
|
|
116
122
|
|
|
117
|
-
formatter
|
|
123
|
+
formatter
|
|
124
|
+
.setLanguage('en', { prefixMarker: 'strong', prefix: 'USD ' })
|
|
125
|
+
.toHtmlString(1234.5678);
|
|
118
126
|
// Output: <strong>USD </strong>1,234.6
|
|
119
127
|
|
|
120
128
|
// Formatting with string input for small or big numbers
|
|
121
129
|
|
|
122
|
-
formatter
|
|
130
|
+
formatter
|
|
131
|
+
.setTemplate('usd', 'medium')
|
|
132
|
+
.toJson('0.00000000000000000000005678521');
|
|
123
133
|
// Output: { value: '$0.0₂₂5678', ... }
|
|
124
134
|
```
|
|
125
135
|
|
|
@@ -131,11 +141,11 @@ The `FormattedObject` interface represents the structure of the formatted number
|
|
|
131
141
|
|
|
132
142
|
```typescript
|
|
133
143
|
interface FormattedObject {
|
|
134
|
-
value: string;
|
|
135
|
-
prefix: string;
|
|
136
|
-
postfix: string;
|
|
137
|
-
sign: string;
|
|
138
|
-
wholeNumber: string;
|
|
144
|
+
value: string; // The formatted value as a string
|
|
145
|
+
prefix: string; // The prefix string
|
|
146
|
+
postfix: string; // The postfix string
|
|
147
|
+
sign: string; // The sign of the number (either an empty string or '-')
|
|
148
|
+
wholeNumber: string; // The whole number part of the value
|
|
139
149
|
}
|
|
140
150
|
```
|
|
141
151
|
|
|
@@ -196,4 +206,3 @@ Contributions are welcome! If you find a bug or have a feature request, please o
|
|
|
196
206
|
## License
|
|
197
207
|
|
|
198
208
|
This project is licensed under the [MIT License](LICENSE).
|
|
199
|
-
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.ReducePrecision=t():e.ReducePrecision=t()}(self,(()=>(()=>{"use strict";var e={898:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.default=class{constructor(e={}){this.languageBaseConfig={prefixMarker:"i",postfixMarker:"i",prefix:"",postfix:""},this.defaultLanguageConfig={en:Object.assign(Object.assign({},this.languageBaseConfig),{thousandSeparator:",",decimalSeparator:"."}),fa:Object.assign(Object.assign({},this.languageBaseConfig),{thousandSeparator:"٫",decimalSeparator:"٬"})},this.options=Object.assign({language:"en",template:"number",precision:"high",outputFormat:"plain"},this.defaultLanguageConfig.en),this.options=Object.assign(Object.assign({},this.options),e)}setLanguage(e,t={}){return this.options.language=e,this.options.prefixMarker=t.prefixMarker||this.defaultLanguageConfig[e].prefixMarker,this.options.postfixMarker=t.postfixMarker||this.defaultLanguageConfig[e].postfixMarker,this.options.prefix=t.prefix||this.defaultLanguageConfig[e].prefix,this.options.postfix=t.postfix||this.defaultLanguageConfig[e].postfix,this.options.thousandSeparator=t.thousandSeparator||this.defaultLanguageConfig[e].thousandSeparator,this.options.decimalSeparator=t.decimalSeparator||this.defaultLanguageConfig[e].decimalSeparator,this}setTemplate(e,t){return this.options.template=e,this.options.precision=t,this}toJson(e){const t=this.format(e);return delete t.value,t}toString(e){return this.format(e).value||""}toPlainString(e){return this.options.outputFormat="plain",this.format(e).value||""}toHtmlString(e){return this.options.outputFormat="html",this.format(e).value||""}toMdString(e){return this.options.outputFormat="markdown",this.format(e).value||""}isENotation(e){return/^[-+]?[0-9]*\.?[0-9]+([eE][-+][0-9]+)$/.test(e)}format(e){let{precision:t,template:r}=this.options;const{language:i,outputFormat:o,prefixMarker:n,postfixMarker:a,prefix:s,postfix:u,thousandSeparator:l,decimalSeparator:p}=this.options;if(!e)return{};(null==r?void 0:r.match(/^(number|usd|irt|irr|percent)$/g))||(r="number"),this.isENotation(e.toString())&&(e=this.convertENotationToRegularNumber(Number(e)));let g=e.toString().replace(/[\u0660-\u0669\u06F0-\u06F9]/g,(function(e){return String(15&e.charCodeAt(0))})).replace(/[^\d.-]/g,"");g=g.replace(/^0+(?=\d)/g,"").replace(/(?<=\.\d*)0+$|(?<=\.\d)0+\b/g,"");const f=Math.abs(Number(g));let c,d,h,m,x=0;if("auto"===t&&(r.match(/^(usd|irt|irr|number)$/g)?t=f>=1e-4&&f<1e11?"high":"medium":"percent"===r&&(t="low")),"medium"===t)if(f>=0&&f<1e-4)c=33,d=4,h=!1,m=!0;else if(f>=1e-4&&f<.001)c=7,d=4,h=!1,m=!1;else if(f>=.001&&f<.01)c=5,d=3,h=!1,m=!1;else if(f>=.001&&f<.1)c=3,d=2,h=!1,m=!1;else if(f>=.1&&f<1)c=1,d=1,h=!1,m=!1;else if(f>=1&&f<10)c=3,d=3,h=!1,m=!1;else if(f>=10&&f<100)c=2,d=2,h=!1,m=!1;else if(f>=100&&f<1e3)c=1,d=1,h=!1,m=!1;else if(f>=1e3){const e=Math.floor(Math.log10(f))%3;c=2-e,d=2-e,h=!0,m=!0}else c=0,d=0,h=!0,m=!0;else if("low"===t)if(f>=0&&f<.01)c=2,d=0,h=!0,m=!1,x=2;else if(f>=.01&&f<.1)c=2,d=1,h=!0,m=!1;else if(f>=.1&&f<1)c=2,d=2,h=!0,m=!1;else if(f>=1&&f<10)c=2,d=2,h=!0,m=!1,x=2;else if(f>=10&&f<100)c=1,d=1,h=!0,m=!1,x=1;else if(f>=100&&f<1e3)c=0,d=0,h=!0,m=!1;else if(f>=1e3){const e=Math.floor(Math.log10(f))%3;c=1-e,d=1-e,h=!0,m=!0}else c=0,d=0,h=!0,m=!0,x=2;else f>=0&&f<1?(c=33,d=4,h=!1,m=!1):f>=1&&f<10?(c=3,d=3,h=!0,m=!1):f>=10&&f<100||f>=100&&f<1e3?(c=2,d=2,h=!0,m=!1):f>=1e3&&f<1e4?(c=1,d=1,h=!0,m=!1):(c=0,d=0,h=!0,m=!1);return this.reducePrecision(g,c,d,h,m,x,r,i,o,n,a,s,u,l,p)}convertENotationToRegularNumber(e){const[t,r]=e.toString().split("e"),i=t.replace(".","").replace("-","").length,o=parseFloat(r),n=Math.max(i-o,1);return e.toFixed(n)}reducePrecision(e,t=30,r=4,i=!1,o=!1,n=0,a="number",s="en",u="plain",l="span",p="span",g="",f="",c=",",d="."){var h,m;if(!e)return{};e=e.toString();const x=a.match(/^(number|percent)$/g)?{"":"",K:" هزار",M:" میلیون",B:" میلیارد",T:" تریلیون",Qd:" کادریلیون",Qt:" کنتیلیون"}:{"":"",K:" هزار ت",M:" میلیون ت",B:" میلیارد ت",T:" همت",Qd:" هزار همت",Qt:" میلیون همت"},b=a.match(/^(number|percent)$/g)?{"":"",K:" هزار",M:" میلیون",B:" میلیارد",T:" تریلیون",Qd:" کادریلیون",Qt:" کنتیلیون"}:{"":"",K:" هزار تومان",M:" میلیون تومان",B:" میلیارد تومان",T:" هزار میلیارد تومان",Qd:" کادریلیون تومان",Qt:" کنتیلیون تومان"};let S=/^(-)?(\d+)\.?([0]*)(\d*)$/g.exec(e);if(!S)return{};const $=S[1]||"";let M=S[2],v=S[3],C=S[4],Q="",N="";if(v.length>=30?(v="0".padEnd(29,"0"),C="1"):v.length+r>t?(r=t-v.length)<1&&(r=1):M.length>21&&(M="0",v="",C=""),o&&M.length>=4){const e=Object.keys(x);let t=M,r=0;for(;+t>999&&r<e.length-1;)t=(+t/1e3).toFixed(2),r++;if(N=e[r],S=/^(-)?(\d+)\.?([0]*)(\d*)$/g.exec(t.toString()),!S)return{};M=S[2],v=S[3],C=S[4]}C.length>r&&(i?parseInt(C[r])<5?C=C.substring(0,r):(C=(parseInt(C.substring(0,r))+1).toString(),C.length>r&&(v.length>0?v=v.substring(0,v.length-1):(M=(Number(M)+1).toString(),C=C.substring(1)))):C=C.substring(0,r)),o&&""!==v&&""===N&&(v="0"+v.length.toString().replace(/\d/g,(function(e){return["₀","₁","₂","₃","₄","₅","₆","₇","₈","₉"][parseInt(e,10)]})));let j=`${v}${C}`;j=j.substring(0,t),j=j.replace(/^(\d*[1-9])0+$/g,"$1"),"usd"===a?(Q="en"===s?"$":"",N||(N="fa"===s?" دلار":"")):"irr"===a?N||(N="fa"===s?" ر":" R"):"irt"===a?N||(N="fa"===s?" ت":" T"):"percent"===a&&(N+="en"===s?"%":N?" درصد":"٪"),Q=g+Q,N+=f,"html"===u?(Q&&(Q=`<${l}>${Q}</${l}>`),N&&(N=`<${p}>${N}</${p}>`)):"markdown"===u&&(Q&&(Q=`${l}${Q}${l}`),N&&(N=`${p}${N}${p}`));const k=/\B(?=(\d{3})+(?!\d))/g,B=n?".".padEnd(n+1,"0"):"";let F,T="";F=t<=0||r<=0||!C?`${M.replace(k,",")}${B}`:`${M.replace(k,",")}.${j}`,T=`${$}${Q}${F}${N}`;const O={value:T,prefix:Q,postfix:N,sign:$,wholeNumber:F};return O.value=(null!==(h=null==O?void 0:O.value)&&void 0!==h?h:"").replace(/,/g,c).replace(/\./g,d),"fa"===s&&(O.value=(null!==(m=null==O?void 0:O.value)&&void 0!==m?m:"").replace(/[0-9]/g,(e=>String.fromCharCode(e.charCodeAt(0)+1728))).replace(/(K|M|B|T|Qt|Qd)/g,(function(e){return String(x[e])})),O.fullPostfix=N.replace(/[0-9]/g,(e=>String.fromCharCode(e.charCodeAt(0)+1728))).replace(/(K|M|B|T|Qt|Qd)/g,(function(e){return String(b[e])})),O.postfix=O.postfix.replace(/[0-9]/g,(e=>String.fromCharCode(e.charCodeAt(0)+1728))).replace(/(K|M|B|T|Qt|Qd)/g,(function(e){return String(x[e])})),O.wholeNumber=O.wholeNumber.replace(/[0-9]/g,(e=>String.fromCharCode(e.charCodeAt(0)+1728))).replace(/(K|M|B|T|Qt|Qd)/g,(function(e){return String(x[e])}))),O}}},156:function(e,t,r){var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.NumberFormatter=void 0;const o=i(r(898));t.NumberFormatter=o.default}},t={};return function r(i){var o=t[i];if(void 0!==o)return o.exports;var n=t[i]={exports:{}};return e[i].call(n.exports,n,n.exports,r),n.exports}(156)})()));
|
package/lib/format/index.d.ts
CHANGED
|
@@ -1,21 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
interface Options {
|
|
6
|
-
precision?: Precision;
|
|
7
|
-
template?: Template;
|
|
8
|
-
language?: Language;
|
|
9
|
-
outputFormat?: OutputFormat;
|
|
10
|
-
prefixMarker?: string;
|
|
11
|
-
postfixMarker?: string;
|
|
12
|
-
prefix?: string;
|
|
13
|
-
postfix?: string;
|
|
14
|
-
}
|
|
1
|
+
type Template = 'number' | 'usd' | 'irt' | 'irr' | 'percent';
|
|
2
|
+
type Precision = 'auto' | 'high' | 'medium' | 'low';
|
|
3
|
+
type Language = 'en' | 'fa';
|
|
4
|
+
type OutputFormat = 'plain' | 'html' | 'markdown';
|
|
15
5
|
interface FormattedObject {
|
|
16
6
|
value?: string;
|
|
17
7
|
prefix: string;
|
|
18
8
|
postfix: string;
|
|
9
|
+
fullPostfix?: string;
|
|
19
10
|
sign: string;
|
|
20
11
|
wholeNumber: string;
|
|
21
12
|
}
|
|
@@ -24,8 +15,18 @@ interface LanguageConfig {
|
|
|
24
15
|
postfixMarker?: string;
|
|
25
16
|
prefix?: string;
|
|
26
17
|
postfix?: string;
|
|
18
|
+
thousandSeparator?: string;
|
|
19
|
+
decimalSeparator?: string;
|
|
20
|
+
}
|
|
21
|
+
interface Options extends LanguageConfig {
|
|
22
|
+
precision?: Precision;
|
|
23
|
+
template?: Template;
|
|
24
|
+
language?: Language;
|
|
25
|
+
outputFormat?: OutputFormat;
|
|
27
26
|
}
|
|
28
27
|
declare class NumberFormatter {
|
|
28
|
+
private readonly languageBaseConfig;
|
|
29
|
+
private defaultLanguageConfig;
|
|
29
30
|
private options;
|
|
30
31
|
constructor(options?: Options);
|
|
31
32
|
setLanguage(lang: Language, config?: LanguageConfig): NumberFormatter;
|
package/lib/format/index.js
CHANGED
|
@@ -2,26 +2,35 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
class NumberFormatter {
|
|
4
4
|
constructor(options = {}) {
|
|
5
|
-
this.
|
|
6
|
-
language: 'en',
|
|
7
|
-
template: 'number',
|
|
8
|
-
precision: 'high',
|
|
9
|
-
outputFormat: 'plain',
|
|
5
|
+
this.languageBaseConfig = {
|
|
10
6
|
prefixMarker: 'i',
|
|
11
7
|
postfixMarker: 'i',
|
|
12
8
|
prefix: '',
|
|
13
9
|
postfix: '',
|
|
14
10
|
};
|
|
11
|
+
this.defaultLanguageConfig = {
|
|
12
|
+
en: Object.assign(Object.assign({}, this.languageBaseConfig), { thousandSeparator: ',', decimalSeparator: '.' }),
|
|
13
|
+
fa: Object.assign(Object.assign({}, this.languageBaseConfig), { thousandSeparator: '٫', decimalSeparator: '٬' }),
|
|
14
|
+
};
|
|
15
|
+
this.options = Object.assign({ language: 'en', template: 'number', precision: 'high', outputFormat: 'plain' }, this.defaultLanguageConfig['en']);
|
|
15
16
|
this.options = Object.assign(Object.assign({}, this.options), options);
|
|
16
17
|
}
|
|
17
18
|
setLanguage(lang, config = {}) {
|
|
18
19
|
this.options.language = lang;
|
|
19
20
|
this.options.prefixMarker =
|
|
20
|
-
config.prefixMarker || this.
|
|
21
|
+
config.prefixMarker || this.defaultLanguageConfig[lang].prefixMarker;
|
|
21
22
|
this.options.postfixMarker =
|
|
22
|
-
config.postfixMarker || this.
|
|
23
|
-
this.options.prefix =
|
|
24
|
-
|
|
23
|
+
config.postfixMarker || this.defaultLanguageConfig[lang].postfixMarker;
|
|
24
|
+
this.options.prefix =
|
|
25
|
+
config.prefix || this.defaultLanguageConfig[lang].prefix;
|
|
26
|
+
this.options.postfix =
|
|
27
|
+
config.postfix || this.defaultLanguageConfig[lang].postfix;
|
|
28
|
+
this.options.thousandSeparator =
|
|
29
|
+
config.thousandSeparator ||
|
|
30
|
+
this.defaultLanguageConfig[lang].thousandSeparator;
|
|
31
|
+
this.options.decimalSeparator =
|
|
32
|
+
config.decimalSeparator ||
|
|
33
|
+
this.defaultLanguageConfig[lang].decimalSeparator;
|
|
25
34
|
return this;
|
|
26
35
|
}
|
|
27
36
|
setTemplate(template, precision) {
|
|
@@ -59,7 +68,7 @@ class NumberFormatter {
|
|
|
59
68
|
}
|
|
60
69
|
format(input) {
|
|
61
70
|
let { precision, template } = this.options;
|
|
62
|
-
const { language, outputFormat, prefixMarker, postfixMarker, prefix, postfix, } = this.options;
|
|
71
|
+
const { language, outputFormat, prefixMarker, postfixMarker, prefix, postfix, thousandSeparator, decimalSeparator, } = this.options;
|
|
63
72
|
if (!input)
|
|
64
73
|
return {};
|
|
65
74
|
if (!(template === null || template === void 0 ? void 0 : template.match(/^(number|usd|irt|irr|percent)$/g)))
|
|
@@ -83,7 +92,7 @@ class NumberFormatter {
|
|
|
83
92
|
let f = 0;
|
|
84
93
|
// Auto precision selection
|
|
85
94
|
if (precision === 'auto') {
|
|
86
|
-
if (template.match(/^(usd|irt|irr)$/g)) {
|
|
95
|
+
if (template.match(/^(usd|irt|irr|number)$/g)) {
|
|
87
96
|
if (number >= 0.0001 && number < 100000000000) {
|
|
88
97
|
precision = 'high';
|
|
89
98
|
}
|
|
@@ -91,9 +100,6 @@ class NumberFormatter {
|
|
|
91
100
|
precision = 'medium';
|
|
92
101
|
}
|
|
93
102
|
}
|
|
94
|
-
else if (template === 'number') {
|
|
95
|
-
precision = 'medium';
|
|
96
|
-
}
|
|
97
103
|
else if (template === 'percent') {
|
|
98
104
|
precision = 'low';
|
|
99
105
|
}
|
|
@@ -255,7 +261,7 @@ class NumberFormatter {
|
|
|
255
261
|
c = false;
|
|
256
262
|
}
|
|
257
263
|
}
|
|
258
|
-
return this.reducePrecision(numberString, p, d, r, c, f, template, language, outputFormat, prefixMarker, postfixMarker, prefix, postfix);
|
|
264
|
+
return this.reducePrecision(numberString, p, d, r, c, f, template, language, outputFormat, prefixMarker, postfixMarker, prefix, postfix, thousandSeparator, decimalSeparator);
|
|
259
265
|
}
|
|
260
266
|
convertENotationToRegularNumber(eNotation) {
|
|
261
267
|
const [coefficientStr, exponentStr] = eNotation.toString().split('e');
|
|
@@ -266,8 +272,8 @@ class NumberFormatter {
|
|
|
266
272
|
const precision = Math.max(coefficientLength - exponent, 1);
|
|
267
273
|
return eNotation.toFixed(precision);
|
|
268
274
|
}
|
|
269
|
-
reducePrecision(numberString, precision = 30, nonZeroDigits = 4, round = false, compress = false, fixedDecimalZeros = 0, template = 'number', language = 'en', outputFormat = 'plain', prefixMarker = 'span', postfixMarker = 'span', prefix = '', postfix = '') {
|
|
270
|
-
var _a;
|
|
275
|
+
reducePrecision(numberString, precision = 30, nonZeroDigits = 4, round = false, compress = false, fixedDecimalZeros = 0, template = 'number', language = 'en', outputFormat = 'plain', prefixMarker = 'span', postfixMarker = 'span', prefix = '', postfix = '', thousandSeparator = ',', decimalSeparator = '.') {
|
|
276
|
+
var _a, _b;
|
|
271
277
|
if (!numberString) {
|
|
272
278
|
return {};
|
|
273
279
|
}
|
|
@@ -293,6 +299,25 @@ class NumberFormatter {
|
|
|
293
299
|
Qd: ' هزار همت',
|
|
294
300
|
Qt: ' میلیون همت',
|
|
295
301
|
};
|
|
302
|
+
const fullScaleUnits = template.match(/^(number|percent)$/g)
|
|
303
|
+
? {
|
|
304
|
+
'': '',
|
|
305
|
+
K: ' هزار',
|
|
306
|
+
M: ' میلیون',
|
|
307
|
+
B: ' میلیارد',
|
|
308
|
+
T: ' تریلیون',
|
|
309
|
+
Qd: ' کادریلیون',
|
|
310
|
+
Qt: ' کنتیلیون',
|
|
311
|
+
}
|
|
312
|
+
: {
|
|
313
|
+
'': '',
|
|
314
|
+
K: ' هزار تومان',
|
|
315
|
+
M: ' میلیون تومان',
|
|
316
|
+
B: ' میلیارد تومان',
|
|
317
|
+
T: ' هزار میلیارد تومان',
|
|
318
|
+
Qd: ' کادریلیون تومان',
|
|
319
|
+
Qt: ' کنتیلیون تومان',
|
|
320
|
+
};
|
|
296
321
|
let parts = /^(-)?(\d+)\.?([0]*)(\d*)$/g.exec(numberString);
|
|
297
322
|
if (!parts) {
|
|
298
323
|
return {};
|
|
@@ -441,15 +466,22 @@ class NumberFormatter {
|
|
|
441
466
|
sign: sign,
|
|
442
467
|
wholeNumber: wholeNumberStr,
|
|
443
468
|
};
|
|
469
|
+
// replace custom config
|
|
470
|
+
formattedObject.value = ((_a = formattedObject === null || formattedObject === void 0 ? void 0 : formattedObject.value) !== null && _a !== void 0 ? _a : '')
|
|
471
|
+
.replace(/,/g, thousandSeparator)
|
|
472
|
+
.replace(/\./g, decimalSeparator);
|
|
444
473
|
// Convert output to Persian numerals if language is "fa"
|
|
445
474
|
if (language === 'fa') {
|
|
446
|
-
formattedObject.value = ((
|
|
475
|
+
formattedObject.value = ((_b = formattedObject === null || formattedObject === void 0 ? void 0 : formattedObject.value) !== null && _b !== void 0 ? _b : '')
|
|
447
476
|
.replace(/[0-9]/g, c => String.fromCharCode(c.charCodeAt(0) + 1728))
|
|
448
|
-
.replace(/,/g, '٬')
|
|
449
|
-
.replace(/\./g, '٫')
|
|
450
477
|
.replace(/(K|M|B|T|Qt|Qd)/g, function (c) {
|
|
451
478
|
return String(scaleUnits[c]);
|
|
452
479
|
});
|
|
480
|
+
formattedObject.fullPostfix = unitPostfix
|
|
481
|
+
.replace(/[0-9]/g, c => String.fromCharCode(c.charCodeAt(0) + 1728))
|
|
482
|
+
.replace(/(K|M|B|T|Qt|Qd)/g, function (c) {
|
|
483
|
+
return String(fullScaleUnits[c]);
|
|
484
|
+
});
|
|
453
485
|
formattedObject.postfix = formattedObject.postfix
|
|
454
486
|
.replace(/[0-9]/g, c => String.fromCharCode(c.charCodeAt(0) + 1728))
|
|
455
487
|
.replace(/(K|M|B|T|Qt|Qd)/g, function (c) {
|
package/package.json
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reduce-precision",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"lib/**/*"
|
|
8
8
|
],
|
|
9
9
|
"scripts": {
|
|
10
|
-
"build": "tsc
|
|
10
|
+
"build": "npm run build:tsc && npm run build:webpack",
|
|
11
|
+
"build:tsc": "tsc --project tsconfig.build.json",
|
|
12
|
+
"build:webpack": "webpack --config webpack.config.js",
|
|
11
13
|
"clean": "rm -rf ./lib/",
|
|
12
14
|
"lint": "eslint ./src/ --fix",
|
|
13
15
|
"test:watch": "jest --watch",
|
|
@@ -29,10 +31,13 @@
|
|
|
29
31
|
},
|
|
30
32
|
"homepage": "https://github.com/ArzDigitalLabs/reduce-precision#readme",
|
|
31
33
|
"devDependencies": {
|
|
34
|
+
"@babel/core": "^7.24.7",
|
|
35
|
+
"@babel/preset-env": "^7.24.7",
|
|
32
36
|
"@types/jest": "^27.5.2",
|
|
33
37
|
"@types/node": "^12.20.11",
|
|
34
38
|
"@typescript-eslint/eslint-plugin": "^4.22.0",
|
|
35
39
|
"@typescript-eslint/parser": "^4.22.0",
|
|
40
|
+
"babel-loader": "^9.1.3",
|
|
36
41
|
"eslint": "^7.25.0",
|
|
37
42
|
"eslint-config-prettier": "^8.3.0",
|
|
38
43
|
"eslint-plugin-node": "^11.1.0",
|
|
@@ -41,8 +46,11 @@
|
|
|
41
46
|
"lint-staged": "^13.2.1",
|
|
42
47
|
"prettier": "^2.2.1",
|
|
43
48
|
"ts-jest": "^27.0.5",
|
|
49
|
+
"ts-loader": "^9.5.1",
|
|
44
50
|
"ts-node": "^10.2.1",
|
|
45
|
-
"typescript": "^4.
|
|
51
|
+
"typescript": "^4.9.5",
|
|
52
|
+
"webpack": "^5.92.1",
|
|
53
|
+
"webpack-cli": "^5.1.4"
|
|
46
54
|
},
|
|
47
55
|
"lint-staged": {
|
|
48
56
|
"*.ts": "eslint --cache --cache-location .eslintcache --fix"
|