@simplysm/core-common 13.0.75 → 13.0.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.
Files changed (135) hide show
  1. package/README.md +64 -21
  2. package/dist/extensions/arr-ext.d.ts +1 -1
  3. package/dist/extensions/arr-ext.d.ts.map +1 -1
  4. package/dist/extensions/arr-ext.helpers.d.ts +8 -0
  5. package/dist/extensions/arr-ext.helpers.d.ts.map +1 -1
  6. package/dist/extensions/arr-ext.helpers.js +65 -0
  7. package/dist/extensions/arr-ext.helpers.js.map +2 -2
  8. package/dist/extensions/arr-ext.js +16 -124
  9. package/dist/extensions/arr-ext.js.map +2 -2
  10. package/dist/extensions/arr-ext.types.d.ts +40 -32
  11. package/dist/extensions/arr-ext.types.d.ts.map +1 -1
  12. package/dist/extensions/map-ext.js.map +1 -1
  13. package/dist/extensions/set-ext.js.map +1 -1
  14. package/dist/features/event-emitter.d.ts +4 -4
  15. package/dist/features/event-emitter.d.ts.map +1 -1
  16. package/dist/features/event-emitter.js.map +1 -1
  17. package/dist/features/serial-queue.js +2 -2
  18. package/dist/features/serial-queue.js.map +1 -1
  19. package/dist/index.d.ts +13 -13
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +27 -13
  22. package/dist/index.js.map +1 -1
  23. package/dist/types/date-only.js +2 -2
  24. package/dist/types/date-only.js.map +1 -1
  25. package/dist/types/date-time.js +2 -2
  26. package/dist/types/date-time.js.map +1 -1
  27. package/dist/types/time.js +2 -2
  28. package/dist/types/time.js.map +1 -1
  29. package/dist/types/uuid.d.ts +2 -2
  30. package/dist/types/uuid.d.ts.map +1 -1
  31. package/dist/types/uuid.js +1 -1
  32. package/dist/types/uuid.js.map +1 -1
  33. package/dist/utils/bytes.d.ts +10 -10
  34. package/dist/utils/bytes.d.ts.map +1 -1
  35. package/dist/utils/bytes.js +10 -10
  36. package/dist/utils/bytes.js.map +1 -1
  37. package/dist/utils/date-format.d.ts +1 -1
  38. package/dist/utils/date-format.d.ts.map +1 -1
  39. package/dist/utils/date-format.js +2 -2
  40. package/dist/utils/date-format.js.map +1 -1
  41. package/dist/utils/error.d.ts +1 -1
  42. package/dist/utils/error.d.ts.map +1 -1
  43. package/dist/utils/error.js +2 -2
  44. package/dist/utils/error.js.map +1 -1
  45. package/dist/utils/json.d.ts +4 -2
  46. package/dist/utils/json.d.ts.map +1 -1
  47. package/dist/utils/json.js +9 -9
  48. package/dist/utils/json.js.map +1 -1
  49. package/dist/utils/num.d.ts +10 -10
  50. package/dist/utils/num.d.ts.map +1 -1
  51. package/dist/utils/num.js +11 -11
  52. package/dist/utils/num.js.map +1 -1
  53. package/dist/utils/obj.d.ts +40 -40
  54. package/dist/utils/obj.d.ts.map +1 -1
  55. package/dist/utils/obj.js +102 -99
  56. package/dist/utils/obj.js.map +1 -1
  57. package/dist/utils/path.d.ts +3 -3
  58. package/dist/utils/path.d.ts.map +1 -1
  59. package/dist/utils/path.js +6 -6
  60. package/dist/utils/path.js.map +1 -1
  61. package/dist/utils/primitive.d.ts +1 -1
  62. package/dist/utils/primitive.d.ts.map +1 -1
  63. package/dist/utils/primitive.js +2 -2
  64. package/dist/utils/primitive.js.map +1 -1
  65. package/dist/utils/str.d.ts +16 -16
  66. package/dist/utils/str.d.ts.map +1 -1
  67. package/dist/utils/str.js +16 -16
  68. package/dist/utils/str.js.map +1 -1
  69. package/dist/utils/transferable.d.ts +3 -3
  70. package/dist/utils/transferable.d.ts.map +1 -1
  71. package/dist/utils/transferable.js +10 -10
  72. package/dist/utils/transferable.js.map +1 -1
  73. package/dist/utils/wait.d.ts +2 -2
  74. package/dist/utils/wait.d.ts.map +1 -1
  75. package/dist/utils/wait.js +5 -5
  76. package/dist/utils/wait.js.map +1 -1
  77. package/dist/utils/xml.d.ts +2 -2
  78. package/dist/utils/xml.d.ts.map +1 -1
  79. package/dist/utils/xml.js +4 -4
  80. package/dist/utils/xml.js.map +1 -1
  81. package/dist/{zip/sd-zip.d.ts → utils/zip.d.ts} +1 -1
  82. package/dist/utils/zip.d.ts.map +1 -0
  83. package/dist/{zip/sd-zip.js → utils/zip.js} +1 -1
  84. package/dist/{zip/sd-zip.js.map → utils/zip.js.map} +1 -1
  85. package/package.json +3 -3
  86. package/src/extensions/arr-ext.helpers.ts +86 -0
  87. package/src/extensions/arr-ext.ts +22 -170
  88. package/src/extensions/arr-ext.types.ts +76 -48
  89. package/src/extensions/map-ext.ts +3 -3
  90. package/src/extensions/set-ext.ts +2 -2
  91. package/src/features/event-emitter.ts +6 -6
  92. package/src/features/serial-queue.ts +2 -2
  93. package/src/index.ts +16 -16
  94. package/src/types/date-only.ts +2 -2
  95. package/src/types/date-time.ts +2 -2
  96. package/src/types/time.ts +2 -2
  97. package/src/types/uuid.ts +2 -2
  98. package/src/utils/bytes.ts +15 -15
  99. package/src/utils/date-format.ts +1 -1
  100. package/src/utils/error.ts +1 -1
  101. package/src/utils/json.ts +9 -7
  102. package/src/utils/num.ts +15 -15
  103. package/src/utils/obj.ts +119 -116
  104. package/src/utils/path.ts +3 -3
  105. package/src/utils/primitive.ts +1 -1
  106. package/src/utils/str.ts +16 -16
  107. package/src/utils/transferable.ts +9 -9
  108. package/src/utils/wait.ts +3 -3
  109. package/src/utils/xml.ts +2 -2
  110. package/tests/extensions/array-extension.spec.ts +7 -149
  111. package/tests/extensions/map-extension.spec.ts +0 -30
  112. package/tests/extensions/set-extension.spec.ts +0 -7
  113. package/tests/types/date-only.spec.ts +0 -105
  114. package/tests/types/date-time.spec.ts +0 -145
  115. package/tests/types/lazy-gc-map.spec.ts +0 -86
  116. package/tests/types/time.spec.ts +0 -131
  117. package/tests/types/uuid.spec.ts +4 -4
  118. package/tests/utils/bytes-utils.spec.ts +42 -75
  119. package/tests/utils/date-format.spec.ts +89 -112
  120. package/tests/utils/debounce-queue.spec.ts +3 -49
  121. package/tests/utils/json.spec.ts +61 -147
  122. package/tests/utils/number.spec.ts +41 -62
  123. package/tests/utils/object.spec.ts +120 -139
  124. package/tests/utils/path.spec.ts +19 -27
  125. package/tests/utils/primitive.spec.ts +12 -12
  126. package/tests/utils/sd-event-emitter.spec.ts +0 -27
  127. package/tests/utils/serial-queue.spec.ts +0 -60
  128. package/tests/utils/string.spec.ts +66 -82
  129. package/tests/utils/template-strings.spec.ts +0 -9
  130. package/tests/utils/transferable.spec.ts +55 -119
  131. package/tests/utils/wait.spec.ts +10 -32
  132. package/tests/utils/xml.spec.ts +25 -25
  133. package/tests/{zip/sd-zip.spec.ts → utils/zip.spec.ts} +0 -17
  134. package/dist/zip/sd-zip.d.ts.map +0 -1
  135. /package/src/{zip/sd-zip.ts → utils/zip.ts} +0 -0
@@ -1,155 +1,134 @@
1
1
  import { describe, it, expect } from "vitest";
2
- import {
3
- numParseInt as parseInt,
4
- numParseRoundedInt as parseRoundedInt,
5
- numParseFloat as parseFloat,
6
- numFormat as format,
7
- } from "@simplysm/core-common";
2
+ import { num } from "@simplysm/core-common";
8
3
 
9
4
  describe("number utils", () => {
10
- //#region numParseInt
11
-
12
- describe("numParseInt()", () => {
13
- it("Parses numeric string to integer", () => {
14
- expect(parseInt("123")).toBe(123);
15
- });
5
+ //#region parseInt
16
6
 
7
+ describe("parseInt()", () => {
17
8
  it("Parses negative string", () => {
18
- expect(parseInt("-123")).toBe(-123);
9
+ expect(num.parseInt("-123")).toBe(-123);
19
10
  });
20
11
 
21
12
  it("Floating string returns only integer part", () => {
22
- expect(parseInt("123.45")).toBe(123);
13
+ expect(num.parseInt("123.45")).toBe(123);
23
14
  });
24
15
 
25
16
  it("Number type discards decimal places", () => {
26
- expect(parseInt(123.7)).toBe(123);
27
- expect(parseInt(123.3)).toBe(123);
17
+ expect(num.parseInt(123.7)).toBe(123);
18
+ expect(num.parseInt(123.3)).toBe(123);
28
19
  });
29
20
 
30
21
  it("Removes non-numeric characters then parses", () => {
31
- expect(parseInt("$1,234")).toBe(1234);
32
- expect(parseInt("abc123")).toBe(123);
22
+ expect(num.parseInt("$1,234")).toBe(1234);
23
+ expect(num.parseInt("abc123")).toBe(123);
33
24
  });
34
25
 
35
26
  it("Handles minus sign between characters", () => {
36
- expect(parseInt("abc-123def")).toBe(-123);
37
- expect(parseInt("abc-456def")).toBe(-456);
27
+ expect(num.parseInt("abc-123def")).toBe(-123);
28
+ expect(num.parseInt("abc-456def")).toBe(-456);
38
29
  });
39
30
 
40
31
  it("Empty string returns undefined", () => {
41
- expect(parseInt("")).toBe(undefined);
32
+ expect(num.parseInt("")).toBe(undefined);
42
33
  });
43
34
 
44
35
  it("String with no digits returns undefined", () => {
45
- expect(parseInt("abc")).toBe(undefined);
36
+ expect(num.parseInt("abc")).toBe(undefined);
46
37
  });
47
38
 
48
39
  it("Non-string type returns undefined", () => {
49
- expect(parseInt(null)).toBe(undefined);
50
- expect(parseInt(undefined)).toBe(undefined);
51
- expect(parseInt({})).toBe(undefined);
40
+ expect(num.parseInt(null)).toBe(undefined);
41
+ expect(num.parseInt(undefined)).toBe(undefined);
42
+ expect(num.parseInt({})).toBe(undefined);
52
43
  });
53
44
  });
54
45
 
55
46
  //#endregion
56
47
 
57
- //#region numParseRoundedInt
48
+ //#region parseRoundedInt
58
49
 
59
- describe("numParseRoundedInt()", () => {
50
+ describe("parseRoundedInt()", () => {
60
51
  it("Rounds floating string to integer", () => {
61
- expect(parseRoundedInt("123.5")).toBe(124);
62
- expect(parseRoundedInt("123.4")).toBe(123);
63
- });
64
-
65
- it("Integer string returned as-is", () => {
66
- expect(parseRoundedInt("123")).toBe(123);
52
+ expect(num.parseRoundedInt("123.5")).toBe(124);
53
+ expect(num.parseRoundedInt("123.4")).toBe(123);
67
54
  });
68
55
 
69
56
  it("Rounds number type", () => {
70
- expect(parseRoundedInt(123.7)).toBe(124);
57
+ expect(num.parseRoundedInt(123.7)).toBe(124);
71
58
  });
72
59
 
73
60
  it("Returns undefined if not parseable", () => {
74
- expect(parseRoundedInt("abc")).toBe(undefined);
61
+ expect(num.parseRoundedInt("abc")).toBe(undefined);
75
62
  });
76
63
  });
77
64
 
78
65
  //#endregion
79
66
 
80
- //#region numParseFloat
81
-
82
- describe("numParseFloat()", () => {
83
- it("Parses floating string", () => {
84
- expect(parseFloat("123.45")).toBe(123.45);
85
- });
86
-
87
- it("Parses integer string as float", () => {
88
- expect(parseFloat("123")).toBe(123);
89
- });
67
+ //#region parseFloat
90
68
 
69
+ describe("parseFloat()", () => {
91
70
  it("Parses negative floating string", () => {
92
- expect(parseFloat("-123.45")).toBe(-123.45);
71
+ expect(num.parseFloat("-123.45")).toBe(-123.45);
93
72
  });
94
73
 
95
74
  it("Number type returned as-is", () => {
96
- expect(parseFloat(123.45)).toBe(123.45);
75
+ expect(num.parseFloat(123.45)).toBe(123.45);
97
76
  });
98
77
 
99
78
  it("Removes non-numeric characters then parses", () => {
100
- expect(parseFloat("$1,234.56")).toBe(1234.56);
79
+ expect(num.parseFloat("$1,234.56")).toBe(1234.56);
101
80
  });
102
81
 
103
82
  it("Empty string returns undefined", () => {
104
- expect(parseFloat("")).toBe(undefined);
83
+ expect(num.parseFloat("")).toBe(undefined);
105
84
  });
106
85
 
107
86
  it("String with no digits returns undefined", () => {
108
- expect(parseFloat("abc")).toBe(undefined);
87
+ expect(num.parseFloat("abc")).toBe(undefined);
109
88
  });
110
89
 
111
90
  it("Non-string type returns undefined", () => {
112
- expect(parseFloat(null)).toBe(undefined);
113
- expect(parseFloat(undefined)).toBe(undefined);
91
+ expect(num.parseFloat(null)).toBe(undefined);
92
+ expect(num.parseFloat(undefined)).toBe(undefined);
114
93
  });
115
94
  });
116
95
 
117
96
  //#endregion
118
97
 
119
- //#region numFormat
98
+ //#region format
120
99
 
121
- describe("numFormat()", () => {
100
+ describe("format()", () => {
122
101
  it("Applies thousands separator", () => {
123
- expect(format(1234567)).toBe("1,234,567");
102
+ expect(num.format(1234567)).toBe("1,234,567");
124
103
  });
125
104
 
126
105
  it("Applies thousands separator to float", () => {
127
- const result = format(1234567.89);
106
+ const result = num.format(1234567.89);
128
107
  expect(result).toContain("1,234,567");
129
108
  });
130
109
 
131
110
  it("Specifies maximum decimal places", () => {
132
- expect(format(123.456, { max: 2 })).toBe("123.46");
111
+ expect(num.format(123.456, { max: 2 })).toBe("123.46");
133
112
  });
134
113
 
135
114
  it("Specifies minimum decimal places", () => {
136
- expect(format(123, { min: 2 })).toBe("123.00");
115
+ expect(num.format(123, { min: 2 })).toBe("123.00");
137
116
  });
138
117
 
139
118
  it("Specifies both max and min decimal places", () => {
140
- expect(format(123.4, { max: 3, min: 2 })).toBe("123.40");
119
+ expect(num.format(123.4, { max: 3, min: 2 })).toBe("123.40");
141
120
  });
142
121
 
143
122
  it("Undefined returns undefined", () => {
144
- expect(format(undefined)).toBe(undefined);
123
+ expect(num.format(undefined)).toBe(undefined);
145
124
  });
146
125
 
147
126
  it("Formats zero", () => {
148
- expect(format(0)).toBe("0");
127
+ expect(num.format(0)).toBe("0");
149
128
  });
150
129
 
151
130
  it("Formats negative number", () => {
152
- expect(format(-1234567)).toBe("-1,234,567");
131
+ expect(num.format(-1234567)).toBe("-1,234,567");
153
132
  });
154
133
  });
155
134