@dra2020/baseclient 1.0.138 → 1.0.139

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.
@@ -1,5 +1,5 @@
1
1
  export interface DetailOptions {
2
- numberFormat?: (n: number) => string;
2
+ numberFormat?: string;
3
3
  }
4
4
  interface DetailItem {
5
5
  expr?: string;
@@ -16,17 +16,25 @@ import * as Util from '../util/all';
16
16
  const reIdentifier = /\b[a-zA-Z_$][a-zA-Z0-9_$]*\b/g;
17
17
  const reParam = /^__\d+$/
18
18
 
19
- function defaultNumberFormat(n: number): string
19
+ // Number format: (locale|general|integer|currency).precision
20
+
21
+ function formatNumber(n: number, format: string): string
20
22
  {
21
- return Util.precisionRound(n, 0).toLocaleString();
23
+ if (!format) format = 'locale.0';
24
+ let parts = format.split('.');
25
+ let fmt = parts[0];
26
+ let precision = Number(parts[1] || '0');
27
+ n = Util.precisionRound(n, precision);
28
+ // Only have implementation for 'locale'
29
+ return n.toLocaleString();
22
30
  }
23
31
 
24
32
  export interface DetailOptions
25
33
  {
26
- numberFormat?: (n: number) => string,
34
+ numberFormat?: string,
27
35
  }
28
36
 
29
- const DefaultDetailOptions: DetailOptions = { numberFormat: defaultNumberFormat };
37
+ const DefaultDetailOptions: DetailOptions = { numberFormat: 'locale.0' };
30
38
 
31
39
  class Evaluator
32
40
  {
@@ -194,7 +202,7 @@ export class FormatDetail
194
202
  n = e.eval(o);
195
203
  if (! this._error)
196
204
  this._error = e.error;
197
- return this.options.numberFormat(n);
205
+ return formatNumber(n, this.options.numberFormat);
198
206
  }
199
207
  });
200
208
  return { n, v: av.join('') }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dra2020/baseclient",
3
- "version": "1.0.138",
3
+ "version": "1.0.139",
4
4
  "description": "Utility functions for Javascript projects.",
5
5
  "main": "dist/baseclient.js",
6
6
  "types": "./dist/all/all.d.ts",