@etsoo/shared 1.1.76 → 1.1.77

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,7 +1,6 @@
1
1
  import { NumberUtils } from '../src/NumberUtils';
2
2
 
3
3
  test('Tests for format', () => {
4
- expect(NumberUtils.format(undefined)).toBeUndefined();
5
4
  expect(NumberUtils.format(12.4, 'zh-CN', { style: 'percent' })).toBe(
6
5
  '1,240%'
7
6
  );
@@ -8,9 +8,23 @@ declare global {
8
8
  }
9
9
  }
10
10
  export declare namespace NumberUtils {
11
- function format(input: undefined | null, locale?: string | string[], options?: Intl.NumberFormatOptions): undefined;
11
+ /**
12
+ * Format number
13
+ * @param input Input
14
+ * @param locale Locale
15
+ * @param options Options
16
+ * @returns Result
17
+ */
12
18
  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;
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
+ */
14
28
  function formatMoney(input: number | bigint, currency?: string, locale?: string | string[], isInteger?: boolean, options?: Intl.NumberFormatOptions): string;
15
29
  /**
16
30
  * Parse float value
@@ -19,8 +19,6 @@ var NumberUtils;
19
19
  * @returns Result
20
20
  */
21
21
  function format(input, locale, options) {
22
- if (input == null)
23
- return undefined;
24
22
  // Formatter
25
23
  const intl = new Intl.NumberFormat(locale, options);
26
24
  return intl.format(input);
@@ -37,8 +35,6 @@ var NumberUtils;
37
35
  */
38
36
  function formatMoney(input, currency, locale, isInteger = false, options = {}) {
39
37
  var _a, _b, _c, _d;
40
- if (input == null)
41
- return format(input, locale, options);
42
38
  if (currency) {
43
39
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat
44
40
  options.style = 'currency';
@@ -8,9 +8,23 @@ declare global {
8
8
  }
9
9
  }
10
10
  export declare namespace NumberUtils {
11
- function format(input: undefined | null, locale?: string | string[], options?: Intl.NumberFormatOptions): undefined;
11
+ /**
12
+ * Format number
13
+ * @param input Input
14
+ * @param locale Locale
15
+ * @param options Options
16
+ * @returns Result
17
+ */
12
18
  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;
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
+ */
14
28
  function formatMoney(input: number | bigint, currency?: string, locale?: string | string[], isInteger?: boolean, options?: Intl.NumberFormatOptions): string;
15
29
  /**
16
30
  * Parse float value
@@ -16,8 +16,6 @@ export var NumberUtils;
16
16
  * @returns Result
17
17
  */
18
18
  function format(input, locale, options) {
19
- if (input == null)
20
- return undefined;
21
19
  // Formatter
22
20
  const intl = new Intl.NumberFormat(locale, options);
23
21
  return intl.format(input);
@@ -34,8 +32,6 @@ export var NumberUtils;
34
32
  */
35
33
  function formatMoney(input, currency, locale, isInteger = false, options = {}) {
36
34
  var _a, _b, _c, _d;
37
- if (input == null)
38
- return format(input, locale, options);
39
35
  if (currency) {
40
36
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat
41
37
  options.style = 'currency';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/shared",
3
- "version": "1.1.76",
3
+ "version": "1.1.77",
4
4
  "description": "TypeScript shared utilities and functions",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -18,16 +18,6 @@ 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;
31
21
  /**
32
22
  * Format number
33
23
  * @param input Input
@@ -36,32 +26,15 @@ export namespace NumberUtils {
36
26
  * @returns Result
37
27
  */
38
28
  export function format(
39
- input: number | bigint | undefined | null,
29
+ input: number | bigint,
40
30
  locale?: string | string[],
41
31
  options?: Intl.NumberFormatOptions
42
32
  ) {
43
- if (input == null) return undefined;
44
-
45
33
  // Formatter
46
34
  const intl = new Intl.NumberFormat(locale, options);
47
-
48
35
  return intl.format(input);
49
36
  }
50
37
 
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;
65
38
  /**
66
39
  * Format money
67
40
  * @param input Input
@@ -72,14 +45,12 @@ export namespace NumberUtils {
72
45
  * @returns Result
73
46
  */
74
47
  export function formatMoney(
75
- input: number | bigint | undefined | null,
48
+ input: number | bigint,
76
49
  currency?: string,
77
50
  locale?: string | string[],
78
51
  isInteger: boolean = false,
79
52
  options: Intl.NumberFormatOptions = {}
80
53
  ) {
81
- if (input == null) return format(input, locale, options);
82
-
83
54
  if (currency) {
84
55
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat
85
56
  options.style = 'currency';