@etsoo/shared 1.1.75 → 1.1.76

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.
@@ -8,29 +8,15 @@ declare global {
8
8
  }
9
9
  }
10
10
  export declare namespace NumberUtils {
11
- /**
12
- * Format number
13
- * @param input Input
14
- * @param locale Locale
15
- * @param options Options
16
- * @returns Result
17
- */
18
- function format(input?: number | bigint, locale?: string | string[], options?: Intl.NumberFormatOptions): string | undefined;
19
- /**
20
- * Format money
21
- * @param input Input
22
- * @param currency Currency, like USD for US dollar
23
- * @param locale Locale
24
- * @param isInteger Is integer value
25
- * @param options Options
26
- * @returns Result
27
- */
28
- function formatMoney(input?: number | bigint, currency?: string, locale?: string | string[], isInteger?: boolean, options?: Intl.NumberFormatOptions): string | undefined;
11
+ function format(input: undefined | null, locale?: string | string[], options?: Intl.NumberFormatOptions): undefined;
12
+ function format(input: number | bigint, locale?: string | string[], options?: Intl.NumberFormatOptions): string;
13
+ function formatMoney(input: undefined | null, currency?: string, locale?: string | string[], isInteger?: boolean, options?: Intl.NumberFormatOptions): undefined;
14
+ function formatMoney(input: number | bigint, currency?: string, locale?: string | string[], isInteger?: boolean, options?: Intl.NumberFormatOptions): string;
29
15
  /**
30
16
  * Parse float value
31
17
  * @param rawData Raw data
32
18
  */
33
- const parse: (rawData: string | number | undefined | object) => number;
19
+ const parse: (rawData: unknown) => number;
34
20
  /**
35
21
  * Parse float value and unit
36
22
  * @param input Input string
@@ -37,6 +37,8 @@ var NumberUtils;
37
37
  */
38
38
  function formatMoney(input, currency, locale, isInteger = false, options = {}) {
39
39
  var _a, _b, _c, _d;
40
+ if (input == null)
41
+ return format(input, locale, options);
40
42
  if (currency) {
41
43
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat
42
44
  options.style = 'currency';
@@ -8,29 +8,15 @@ declare global {
8
8
  }
9
9
  }
10
10
  export declare namespace NumberUtils {
11
- /**
12
- * Format number
13
- * @param input Input
14
- * @param locale Locale
15
- * @param options Options
16
- * @returns Result
17
- */
18
- function format(input?: number | bigint, locale?: string | string[], options?: Intl.NumberFormatOptions): string | undefined;
19
- /**
20
- * Format money
21
- * @param input Input
22
- * @param currency Currency, like USD for US dollar
23
- * @param locale Locale
24
- * @param isInteger Is integer value
25
- * @param options Options
26
- * @returns Result
27
- */
28
- function formatMoney(input?: number | bigint, currency?: string, locale?: string | string[], isInteger?: boolean, options?: Intl.NumberFormatOptions): string | undefined;
11
+ function format(input: undefined | null, locale?: string | string[], options?: Intl.NumberFormatOptions): undefined;
12
+ function format(input: number | bigint, locale?: string | string[], options?: Intl.NumberFormatOptions): string;
13
+ function formatMoney(input: undefined | null, currency?: string, locale?: string | string[], isInteger?: boolean, options?: Intl.NumberFormatOptions): undefined;
14
+ function formatMoney(input: number | bigint, currency?: string, locale?: string | string[], isInteger?: boolean, options?: Intl.NumberFormatOptions): string;
29
15
  /**
30
16
  * Parse float value
31
17
  * @param rawData Raw data
32
18
  */
33
- const parse: (rawData: string | number | undefined | object) => number;
19
+ const parse: (rawData: unknown) => number;
34
20
  /**
35
21
  * Parse float value and unit
36
22
  * @param input Input string
@@ -34,6 +34,8 @@ export var NumberUtils;
34
34
  */
35
35
  function formatMoney(input, currency, locale, isInteger = false, options = {}) {
36
36
  var _a, _b, _c, _d;
37
+ if (input == null)
38
+ return format(input, locale, options);
37
39
  if (currency) {
38
40
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat
39
41
  options.style = 'currency';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/shared",
3
- "version": "1.1.75",
3
+ "version": "1.1.76",
4
4
  "description": "TypeScript shared utilities and functions",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -18,6 +18,16 @@ Number.prototype.toExact = function (this: number, precision?: number) {
18
18
  };
19
19
 
20
20
  export namespace NumberUtils {
21
+ export function format(
22
+ input: undefined | null,
23
+ locale?: string | string[],
24
+ options?: Intl.NumberFormatOptions
25
+ ): undefined;
26
+ export function format(
27
+ input: number | bigint,
28
+ locale?: string | string[],
29
+ options?: Intl.NumberFormatOptions
30
+ ): string;
21
31
  /**
22
32
  * Format number
23
33
  * @param input Input
@@ -26,7 +36,7 @@ export namespace NumberUtils {
26
36
  * @returns Result
27
37
  */
28
38
  export function format(
29
- input?: number | bigint,
39
+ input: number | bigint | undefined | null,
30
40
  locale?: string | string[],
31
41
  options?: Intl.NumberFormatOptions
32
42
  ) {
@@ -38,6 +48,20 @@ export namespace NumberUtils {
38
48
  return intl.format(input);
39
49
  }
40
50
 
51
+ export function formatMoney(
52
+ input: undefined | null,
53
+ currency?: string,
54
+ locale?: string | string[],
55
+ isInteger?: boolean,
56
+ options?: Intl.NumberFormatOptions
57
+ ): undefined;
58
+ export function formatMoney(
59
+ input: number | bigint,
60
+ currency?: string,
61
+ locale?: string | string[],
62
+ isInteger?: boolean,
63
+ options?: Intl.NumberFormatOptions
64
+ ): string;
41
65
  /**
42
66
  * Format money
43
67
  * @param input Input
@@ -48,12 +72,14 @@ export namespace NumberUtils {
48
72
  * @returns Result
49
73
  */
50
74
  export function formatMoney(
51
- input?: number | bigint,
75
+ input: number | bigint | undefined | null,
52
76
  currency?: string,
53
77
  locale?: string | string[],
54
78
  isInteger: boolean = false,
55
79
  options: Intl.NumberFormatOptions = {}
56
80
  ) {
81
+ if (input == null) return format(input, locale, options);
82
+
57
83
  if (currency) {
58
84
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat
59
85
  options.style = 'currency';
@@ -73,9 +99,7 @@ export namespace NumberUtils {
73
99
  * Parse float value
74
100
  * @param rawData Raw data
75
101
  */
76
- export const parse = (
77
- rawData: string | number | undefined | object
78
- ): number => {
102
+ export const parse = (rawData: unknown): number => {
79
103
  if (rawData == null) {
80
104
  return Number.NaN;
81
105
  }