@dra2020/baseclient 1.0.138 → 1.0.140

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,24 @@ 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
+ // Only have implementation for 'locale'
28
+ return n.toLocaleString(undefined, { maximumFractionDigits: precision, minimumFractionDigits: precision } );
22
29
  }
23
30
 
24
31
  export interface DetailOptions
25
32
  {
26
- numberFormat?: (n: number) => string,
33
+ numberFormat?: string,
27
34
  }
28
35
 
29
- const DefaultDetailOptions: DetailOptions = { numberFormat: defaultNumberFormat };
36
+ const DefaultDetailOptions: DetailOptions = { numberFormat: 'locale.0' };
30
37
 
31
38
  class Evaluator
32
39
  {
@@ -194,7 +201,7 @@ export class FormatDetail
194
201
  n = e.eval(o);
195
202
  if (! this._error)
196
203
  this._error = e.error;
197
- return this.options.numberFormat(n);
204
+ return formatNumber(n, this.options.numberFormat);
198
205
  }
199
206
  });
200
207
  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.140",
4
4
  "description": "Utility functions for Javascript projects.",
5
5
  "main": "dist/baseclient.js",
6
6
  "types": "./dist/all/all.d.ts",