@zairakai/js-utils 1.0.0

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 (93) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +270 -0
  3. package/dist/arrays.cjs +210 -0
  4. package/dist/arrays.d.cts +119 -0
  5. package/dist/arrays.d.ts +119 -0
  6. package/dist/arrays.js +32 -0
  7. package/dist/chunk-27YHP2CK.js +407 -0
  8. package/dist/chunk-3WNRYKPG.js +37 -0
  9. package/dist/chunk-42CHLXT7.js +214 -0
  10. package/dist/chunk-6F4PWJZI.js +0 -0
  11. package/dist/chunk-7SXRFZBB.js +173 -0
  12. package/dist/chunk-F6RSTW65.js +156 -0
  13. package/dist/chunk-G7ZJ23DW.js +253 -0
  14. package/dist/chunk-IPP7PA6H.js +136 -0
  15. package/dist/chunk-LDSWHSRX.js +96 -0
  16. package/dist/chunk-TY75OOIQ.js +700 -0
  17. package/dist/chunk-W6JEMFAF.js +54 -0
  18. package/dist/chunk-XEJLBAXE.js +164 -0
  19. package/dist/chunk-Z7G3SIQH.js +270 -0
  20. package/dist/chunk-ZJPKS2MQ.js +101 -0
  21. package/dist/collections.cjs +797 -0
  22. package/dist/collections.d.cts +353 -0
  23. package/dist/collections.d.ts +353 -0
  24. package/dist/collections.js +17 -0
  25. package/dist/datetime.cjs +80 -0
  26. package/dist/datetime.d.cts +75 -0
  27. package/dist/datetime.d.ts +75 -0
  28. package/dist/datetime.js +24 -0
  29. package/dist/equals.cjs +121 -0
  30. package/dist/equals.d.cts +24 -0
  31. package/dist/equals.d.ts +24 -0
  32. package/dist/equals.js +8 -0
  33. package/dist/formatters.cjs +201 -0
  34. package/dist/formatters.d.cts +180 -0
  35. package/dist/formatters.d.ts +180 -0
  36. package/dist/formatters.js +48 -0
  37. package/dist/index.cjs +2906 -0
  38. package/dist/index.d.cts +120 -0
  39. package/dist/index.d.ts +120 -0
  40. package/dist/index.js +348 -0
  41. package/dist/number.cjs +279 -0
  42. package/dist/number.d.cts +177 -0
  43. package/dist/number.d.ts +177 -0
  44. package/dist/number.js +10 -0
  45. package/dist/obj.cjs +427 -0
  46. package/dist/obj.d.cts +177 -0
  47. package/dist/obj.d.ts +177 -0
  48. package/dist/obj.js +12 -0
  49. package/dist/php-arrays.cjs +954 -0
  50. package/dist/php-arrays.d.cts +256 -0
  51. package/dist/php-arrays.d.ts +256 -0
  52. package/dist/php-arrays.js +70 -0
  53. package/dist/runtime.cjs +134 -0
  54. package/dist/runtime.d.cts +90 -0
  55. package/dist/runtime.d.ts +90 -0
  56. package/dist/runtime.js +24 -0
  57. package/dist/schemas.cjs +86 -0
  58. package/dist/schemas.d.cts +108 -0
  59. package/dist/schemas.d.ts +108 -0
  60. package/dist/schemas.js +22 -0
  61. package/dist/str.cjs +499 -0
  62. package/dist/str.d.cts +282 -0
  63. package/dist/str.d.ts +282 -0
  64. package/dist/str.js +11 -0
  65. package/dist/types.cjs +18 -0
  66. package/dist/types.d.cts +13 -0
  67. package/dist/types.d.ts +13 -0
  68. package/dist/types.js +1 -0
  69. package/dist/validator.cjs +251 -0
  70. package/dist/validator.d.cts +99 -0
  71. package/dist/validator.d.ts +99 -0
  72. package/dist/validator.js +11 -0
  73. package/dist/validators.cjs +217 -0
  74. package/dist/validators.d.cts +216 -0
  75. package/dist/validators.d.ts +216 -0
  76. package/dist/validators.js +64 -0
  77. package/package.json +180 -0
  78. package/src/arrays.ts +316 -0
  79. package/src/collections.ts +866 -0
  80. package/src/datetime.ts +103 -0
  81. package/src/equals.ts +134 -0
  82. package/src/formatters.ts +342 -0
  83. package/src/index.ts +36 -0
  84. package/src/number.ts +281 -0
  85. package/src/obj.ts +303 -0
  86. package/src/php-arrays.ts +445 -0
  87. package/src/pipe.ts +29 -0
  88. package/src/runtime.ts +194 -0
  89. package/src/schemas.ts +136 -0
  90. package/src/str.ts +438 -0
  91. package/src/types.ts +13 -0
  92. package/src/validator.ts +157 -0
  93. package/src/validators.ts +359 -0
@@ -0,0 +1,279 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/number.ts
21
+ var number_exports = {};
22
+ __export(number_exports, {
23
+ NumberHelper: () => NumberHelper,
24
+ Numberable: () => Numberable,
25
+ num: () => num
26
+ });
27
+ module.exports = __toCommonJS(number_exports);
28
+ var Numberable = class {
29
+ /**
30
+ * Create a new Numberable instance.
31
+ *
32
+ * @param {unknown} value The initial value
33
+ */
34
+ constructor(value) {
35
+ this.value = Number(value ?? 0);
36
+ if (isNaN(this.value)) {
37
+ this.value = 0;
38
+ }
39
+ }
40
+ /**
41
+ * Get the raw number value.
42
+ *
43
+ * @returns {number} The raw value
44
+ */
45
+ toNumber() {
46
+ return this.value;
47
+ }
48
+ /**
49
+ * Alias for toNumber().
50
+ *
51
+ * @returns {number} The raw value
52
+ */
53
+ get() {
54
+ return this.value;
55
+ }
56
+ /**
57
+ * Format the number with locale-specific formatting.
58
+ *
59
+ * @param {number} [decimals=0] The number of decimal points
60
+ * @param {string} [locale='en-US'] The locale to use for formatting
61
+ * @returns {string} The formatted number
62
+ */
63
+ format(decimals = 0, locale = "en-US") {
64
+ return new Intl.NumberFormat(locale, {
65
+ minimumFractionDigits: decimals,
66
+ maximumFractionDigits: decimals
67
+ }).format(this.value);
68
+ }
69
+ /**
70
+ * Format the number as currency.
71
+ *
72
+ * @param {string} [currency='USD'] The currency code (e.g., 'USD', 'EUR')
73
+ * @param {string} [locale='en-US'] The locale to use for formatting
74
+ * @returns {string} The formatted currency string
75
+ */
76
+ currency(currency = "USD", locale = "en-US") {
77
+ return new Intl.NumberFormat(locale, {
78
+ style: "currency",
79
+ currency
80
+ }).format(this.value);
81
+ }
82
+ /**
83
+ * Format the number as a percentage.
84
+ *
85
+ * @param {number} [decimals=0] The number of decimal points
86
+ * @param {string} [locale='en-US'] The locale to use for formatting
87
+ * @returns {string} The formatted percentage string
88
+ */
89
+ percentage(decimals = 0, locale = "en-US") {
90
+ return new Intl.NumberFormat(locale, {
91
+ style: "percent",
92
+ minimumFractionDigits: decimals,
93
+ maximumFractionDigits: decimals
94
+ }).format(this.value / 100);
95
+ }
96
+ /**
97
+ * Format the number as a human-readable file size.
98
+ *
99
+ * @param {number} [precision=2] The number of decimal points
100
+ * @returns {string} The formatted file size (e.g., "1.50 MB")
101
+ */
102
+ fileSize(precision = 2) {
103
+ if (0 === this.value) {
104
+ return "0 B";
105
+ }
106
+ const units = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
107
+ const i = Math.floor(Math.log(this.value) / Math.log(1024));
108
+ return `${parseFloat((this.value / Math.pow(1024, i)).toFixed(precision))} ${units[i]}`;
109
+ }
110
+ /**
111
+ * Abbreviate the number (e.g., 1K, 1M, 1B).
112
+ *
113
+ * @param {number} [precision=1] The number of decimal points
114
+ * @returns {string} The abbreviated number
115
+ */
116
+ abbreviate(precision = 1) {
117
+ if (1e3 > this.value) {
118
+ return String(this.value);
119
+ }
120
+ const units = ["", "K", "M", "B", "T"];
121
+ const i = Math.floor(Math.log10(this.value) / 3);
122
+ return `${parseFloat((this.value / Math.pow(1e3, i)).toFixed(precision))}${units[i]}`;
123
+ }
124
+ /**
125
+ * Add an ordinal suffix to the number (e.g., 1st, 2nd, 3rd).
126
+ *
127
+ * @returns {string} The number with its ordinal suffix
128
+ */
129
+ ordinal() {
130
+ const s = ["th", "st", "nd", "rd"];
131
+ const v = this.value % 100;
132
+ return this.value + (s[(v - 20) % 10] || s[v] || s[0]);
133
+ }
134
+ /**
135
+ * Clamp the number between a minimum and maximum value.
136
+ *
137
+ * @param {number} min The minimum value
138
+ * @param {number} max The maximum value
139
+ * @returns {this} The Numberable instance
140
+ */
141
+ clamp(min, max) {
142
+ this.value = Math.min(Math.max(this.value, min), max);
143
+ return this;
144
+ }
145
+ /**
146
+ * Check if the number is between a minimum and maximum value.
147
+ *
148
+ * @param {number} min The minimum value
149
+ * @param {number} max The maximum value
150
+ * @param {boolean} [inclusive=true] Whether to include the boundaries
151
+ * @returns {boolean} True if the number is between min and max
152
+ */
153
+ isBetween(min, max, inclusive = true) {
154
+ return inclusive ? this.value >= min && this.value <= max : this.value > min && this.value < max;
155
+ }
156
+ /**
157
+ * Add a value to the current number.
158
+ *
159
+ * @param {number} value The value to add
160
+ * @returns {this} The Numberable instance
161
+ */
162
+ add(value) {
163
+ this.value += value;
164
+ return this;
165
+ }
166
+ /**
167
+ * Subtract a value from the current number.
168
+ *
169
+ * @param {number} value The value to subtract
170
+ * @returns {this} The Numberable instance
171
+ */
172
+ sub(value) {
173
+ this.value -= value;
174
+ return this;
175
+ }
176
+ /**
177
+ * Multiply the current number by a value.
178
+ *
179
+ * @param {number} value The value to multiply by
180
+ * @returns {this} The Numberable instance
181
+ */
182
+ mul(value) {
183
+ this.value *= value;
184
+ return this;
185
+ }
186
+ /**
187
+ * Divide the current number by a value.
188
+ *
189
+ * @param {number} value The value to divide by
190
+ * @returns {this} The Numberable instance
191
+ */
192
+ div(value) {
193
+ if (0 !== value) {
194
+ this.value /= value;
195
+ }
196
+ return this;
197
+ }
198
+ /**
199
+ * Round the number to a specified precision.
200
+ *
201
+ * @param {number} [precision=0] The number of decimal points
202
+ * @returns {this} The Numberable instance
203
+ */
204
+ round(precision = 0) {
205
+ const factor = Math.pow(10, precision);
206
+ this.value = Math.round(this.value * factor) / factor;
207
+ return this;
208
+ }
209
+ /**
210
+ * Round the number up to a specified precision.
211
+ *
212
+ * @param {number} [precision=0] The number of decimal points
213
+ * @returns {this} The Numberable instance
214
+ */
215
+ ceil(precision = 0) {
216
+ const factor = Math.pow(10, precision);
217
+ this.value = Math.ceil(this.value * factor) / factor;
218
+ return this;
219
+ }
220
+ /**
221
+ * Round the number down to a specified precision.
222
+ *
223
+ * @param {number} [precision=0] The number of decimal points
224
+ * @returns {this} The Numberable instance
225
+ */
226
+ floor(precision = 0) {
227
+ const factor = Math.pow(10, precision);
228
+ this.value = Math.floor(this.value * factor) / factor;
229
+ return this;
230
+ }
231
+ /**
232
+ * Pipe the current Numberable instance to a callback.
233
+ *
234
+ * @param {Function} callback The callback to execute
235
+ * @returns {U} The result of the callback
236
+ */
237
+ pipe(callback) {
238
+ return callback(this);
239
+ }
240
+ /**
241
+ * Execute a callback if a condition is met.
242
+ *
243
+ * @param {boolean | Function} condition The condition to check
244
+ * @param {Function} callback The callback to execute if condition is true
245
+ * @returns {this} The Numberable instance
246
+ */
247
+ when(condition, callback) {
248
+ const shouldExecute = "function" === typeof condition ? condition() : condition;
249
+ if (shouldExecute) {
250
+ callback(this);
251
+ }
252
+ return this;
253
+ }
254
+ };
255
+ var num = (value) => {
256
+ return new Numberable(value);
257
+ };
258
+ var NumberHelper = {
259
+ /** Create a new Numberable instance */
260
+ of: (value) => new Numberable(value),
261
+ /** Format the number with locale-specific formatting */
262
+ format: (value, decimals = 0, locale = "en-US") => new Numberable(value).format(decimals, locale),
263
+ /** Format the number as currency */
264
+ currency: (value, currency = "USD", locale = "en-US") => new Numberable(value).currency(currency, locale),
265
+ /** Format the number as a percentage */
266
+ percentage: (value, decimals = 0, locale = "en-US") => new Numberable(value).percentage(decimals, locale),
267
+ /** Format the number as a human-readable file size */
268
+ fileSize: (value, precision = 2) => new Numberable(value).fileSize(precision),
269
+ /** Abbreviate the number */
270
+ abbreviate: (value, precision = 1) => new Numberable(value).abbreviate(precision),
271
+ /** Add an ordinal suffix to the number */
272
+ ordinal: (value) => new Numberable(value).ordinal()
273
+ };
274
+ // Annotate the CommonJS export names for ESM import in node:
275
+ 0 && (module.exports = {
276
+ NumberHelper,
277
+ Numberable,
278
+ num
279
+ });
@@ -0,0 +1,177 @@
1
+ /**
2
+ * Fluent number manipulation class inspired by Laravel's Number and modern utilities.
3
+ */
4
+ declare class Numberable {
5
+ protected value: number;
6
+ /**
7
+ * Create a new Numberable instance.
8
+ *
9
+ * @param {unknown} value The initial value
10
+ */
11
+ constructor(value: unknown);
12
+ /**
13
+ * Get the raw number value.
14
+ *
15
+ * @returns {number} The raw value
16
+ */
17
+ toNumber(): number;
18
+ /**
19
+ * Alias for toNumber().
20
+ *
21
+ * @returns {number} The raw value
22
+ */
23
+ get(): number;
24
+ /**
25
+ * Format the number with locale-specific formatting.
26
+ *
27
+ * @param {number} [decimals=0] The number of decimal points
28
+ * @param {string} [locale='en-US'] The locale to use for formatting
29
+ * @returns {string} The formatted number
30
+ */
31
+ format(decimals?: number, locale?: string): string;
32
+ /**
33
+ * Format the number as currency.
34
+ *
35
+ * @param {string} [currency='USD'] The currency code (e.g., 'USD', 'EUR')
36
+ * @param {string} [locale='en-US'] The locale to use for formatting
37
+ * @returns {string} The formatted currency string
38
+ */
39
+ currency(currency?: string, locale?: string): string;
40
+ /**
41
+ * Format the number as a percentage.
42
+ *
43
+ * @param {number} [decimals=0] The number of decimal points
44
+ * @param {string} [locale='en-US'] The locale to use for formatting
45
+ * @returns {string} The formatted percentage string
46
+ */
47
+ percentage(decimals?: number, locale?: string): string;
48
+ /**
49
+ * Format the number as a human-readable file size.
50
+ *
51
+ * @param {number} [precision=2] The number of decimal points
52
+ * @returns {string} The formatted file size (e.g., "1.50 MB")
53
+ */
54
+ fileSize(precision?: number): string;
55
+ /**
56
+ * Abbreviate the number (e.g., 1K, 1M, 1B).
57
+ *
58
+ * @param {number} [precision=1] The number of decimal points
59
+ * @returns {string} The abbreviated number
60
+ */
61
+ abbreviate(precision?: number): string;
62
+ /**
63
+ * Add an ordinal suffix to the number (e.g., 1st, 2nd, 3rd).
64
+ *
65
+ * @returns {string} The number with its ordinal suffix
66
+ */
67
+ ordinal(): string;
68
+ /**
69
+ * Clamp the number between a minimum and maximum value.
70
+ *
71
+ * @param {number} min The minimum value
72
+ * @param {number} max The maximum value
73
+ * @returns {this} The Numberable instance
74
+ */
75
+ clamp(min: number, max: number): this;
76
+ /**
77
+ * Check if the number is between a minimum and maximum value.
78
+ *
79
+ * @param {number} min The minimum value
80
+ * @param {number} max The maximum value
81
+ * @param {boolean} [inclusive=true] Whether to include the boundaries
82
+ * @returns {boolean} True if the number is between min and max
83
+ */
84
+ isBetween(min: number, max: number, inclusive?: boolean): boolean;
85
+ /**
86
+ * Add a value to the current number.
87
+ *
88
+ * @param {number} value The value to add
89
+ * @returns {this} The Numberable instance
90
+ */
91
+ add(value: number): this;
92
+ /**
93
+ * Subtract a value from the current number.
94
+ *
95
+ * @param {number} value The value to subtract
96
+ * @returns {this} The Numberable instance
97
+ */
98
+ sub(value: number): this;
99
+ /**
100
+ * Multiply the current number by a value.
101
+ *
102
+ * @param {number} value The value to multiply by
103
+ * @returns {this} The Numberable instance
104
+ */
105
+ mul(value: number): this;
106
+ /**
107
+ * Divide the current number by a value.
108
+ *
109
+ * @param {number} value The value to divide by
110
+ * @returns {this} The Numberable instance
111
+ */
112
+ div(value: number): this;
113
+ /**
114
+ * Round the number to a specified precision.
115
+ *
116
+ * @param {number} [precision=0] The number of decimal points
117
+ * @returns {this} The Numberable instance
118
+ */
119
+ round(precision?: number): this;
120
+ /**
121
+ * Round the number up to a specified precision.
122
+ *
123
+ * @param {number} [precision=0] The number of decimal points
124
+ * @returns {this} The Numberable instance
125
+ */
126
+ ceil(precision?: number): this;
127
+ /**
128
+ * Round the number down to a specified precision.
129
+ *
130
+ * @param {number} [precision=0] The number of decimal points
131
+ * @returns {this} The Numberable instance
132
+ */
133
+ floor(precision?: number): this;
134
+ /**
135
+ * Pipe the current Numberable instance to a callback.
136
+ *
137
+ * @param {Function} callback The callback to execute
138
+ * @returns {U} The result of the callback
139
+ */
140
+ pipe<U>(callback: (num: this) => U): U;
141
+ /**
142
+ * Execute a callback if a condition is met.
143
+ *
144
+ * @param {boolean | Function} condition The condition to check
145
+ * @param {Function} callback The callback to execute if condition is true
146
+ * @returns {this} The Numberable instance
147
+ */
148
+ when(condition: boolean | (() => boolean), callback: (num: this) => void): this;
149
+ }
150
+ /**
151
+ * Create a new fluent Numberable instance.
152
+ *
153
+ * @param {unknown} [value] The initial value
154
+ * @returns {Numberable} A new Numberable instance
155
+ */
156
+ declare const num: (value?: unknown) => Numberable;
157
+ /**
158
+ * Static methods for number manipulation.
159
+ */
160
+ declare const NumberHelper: {
161
+ /** Create a new Numberable instance */
162
+ of: (value: unknown) => Numberable;
163
+ /** Format the number with locale-specific formatting */
164
+ format: (value: number, decimals?: number, locale?: string) => string;
165
+ /** Format the number as currency */
166
+ currency: (value: number, currency?: string, locale?: string) => string;
167
+ /** Format the number as a percentage */
168
+ percentage: (value: number, decimals?: number, locale?: string) => string;
169
+ /** Format the number as a human-readable file size */
170
+ fileSize: (value: number, precision?: number) => string;
171
+ /** Abbreviate the number */
172
+ abbreviate: (value: number, precision?: number) => string;
173
+ /** Add an ordinal suffix to the number */
174
+ ordinal: (value: number) => string;
175
+ };
176
+
177
+ export { NumberHelper, Numberable, num };
@@ -0,0 +1,177 @@
1
+ /**
2
+ * Fluent number manipulation class inspired by Laravel's Number and modern utilities.
3
+ */
4
+ declare class Numberable {
5
+ protected value: number;
6
+ /**
7
+ * Create a new Numberable instance.
8
+ *
9
+ * @param {unknown} value The initial value
10
+ */
11
+ constructor(value: unknown);
12
+ /**
13
+ * Get the raw number value.
14
+ *
15
+ * @returns {number} The raw value
16
+ */
17
+ toNumber(): number;
18
+ /**
19
+ * Alias for toNumber().
20
+ *
21
+ * @returns {number} The raw value
22
+ */
23
+ get(): number;
24
+ /**
25
+ * Format the number with locale-specific formatting.
26
+ *
27
+ * @param {number} [decimals=0] The number of decimal points
28
+ * @param {string} [locale='en-US'] The locale to use for formatting
29
+ * @returns {string} The formatted number
30
+ */
31
+ format(decimals?: number, locale?: string): string;
32
+ /**
33
+ * Format the number as currency.
34
+ *
35
+ * @param {string} [currency='USD'] The currency code (e.g., 'USD', 'EUR')
36
+ * @param {string} [locale='en-US'] The locale to use for formatting
37
+ * @returns {string} The formatted currency string
38
+ */
39
+ currency(currency?: string, locale?: string): string;
40
+ /**
41
+ * Format the number as a percentage.
42
+ *
43
+ * @param {number} [decimals=0] The number of decimal points
44
+ * @param {string} [locale='en-US'] The locale to use for formatting
45
+ * @returns {string} The formatted percentage string
46
+ */
47
+ percentage(decimals?: number, locale?: string): string;
48
+ /**
49
+ * Format the number as a human-readable file size.
50
+ *
51
+ * @param {number} [precision=2] The number of decimal points
52
+ * @returns {string} The formatted file size (e.g., "1.50 MB")
53
+ */
54
+ fileSize(precision?: number): string;
55
+ /**
56
+ * Abbreviate the number (e.g., 1K, 1M, 1B).
57
+ *
58
+ * @param {number} [precision=1] The number of decimal points
59
+ * @returns {string} The abbreviated number
60
+ */
61
+ abbreviate(precision?: number): string;
62
+ /**
63
+ * Add an ordinal suffix to the number (e.g., 1st, 2nd, 3rd).
64
+ *
65
+ * @returns {string} The number with its ordinal suffix
66
+ */
67
+ ordinal(): string;
68
+ /**
69
+ * Clamp the number between a minimum and maximum value.
70
+ *
71
+ * @param {number} min The minimum value
72
+ * @param {number} max The maximum value
73
+ * @returns {this} The Numberable instance
74
+ */
75
+ clamp(min: number, max: number): this;
76
+ /**
77
+ * Check if the number is between a minimum and maximum value.
78
+ *
79
+ * @param {number} min The minimum value
80
+ * @param {number} max The maximum value
81
+ * @param {boolean} [inclusive=true] Whether to include the boundaries
82
+ * @returns {boolean} True if the number is between min and max
83
+ */
84
+ isBetween(min: number, max: number, inclusive?: boolean): boolean;
85
+ /**
86
+ * Add a value to the current number.
87
+ *
88
+ * @param {number} value The value to add
89
+ * @returns {this} The Numberable instance
90
+ */
91
+ add(value: number): this;
92
+ /**
93
+ * Subtract a value from the current number.
94
+ *
95
+ * @param {number} value The value to subtract
96
+ * @returns {this} The Numberable instance
97
+ */
98
+ sub(value: number): this;
99
+ /**
100
+ * Multiply the current number by a value.
101
+ *
102
+ * @param {number} value The value to multiply by
103
+ * @returns {this} The Numberable instance
104
+ */
105
+ mul(value: number): this;
106
+ /**
107
+ * Divide the current number by a value.
108
+ *
109
+ * @param {number} value The value to divide by
110
+ * @returns {this} The Numberable instance
111
+ */
112
+ div(value: number): this;
113
+ /**
114
+ * Round the number to a specified precision.
115
+ *
116
+ * @param {number} [precision=0] The number of decimal points
117
+ * @returns {this} The Numberable instance
118
+ */
119
+ round(precision?: number): this;
120
+ /**
121
+ * Round the number up to a specified precision.
122
+ *
123
+ * @param {number} [precision=0] The number of decimal points
124
+ * @returns {this} The Numberable instance
125
+ */
126
+ ceil(precision?: number): this;
127
+ /**
128
+ * Round the number down to a specified precision.
129
+ *
130
+ * @param {number} [precision=0] The number of decimal points
131
+ * @returns {this} The Numberable instance
132
+ */
133
+ floor(precision?: number): this;
134
+ /**
135
+ * Pipe the current Numberable instance to a callback.
136
+ *
137
+ * @param {Function} callback The callback to execute
138
+ * @returns {U} The result of the callback
139
+ */
140
+ pipe<U>(callback: (num: this) => U): U;
141
+ /**
142
+ * Execute a callback if a condition is met.
143
+ *
144
+ * @param {boolean | Function} condition The condition to check
145
+ * @param {Function} callback The callback to execute if condition is true
146
+ * @returns {this} The Numberable instance
147
+ */
148
+ when(condition: boolean | (() => boolean), callback: (num: this) => void): this;
149
+ }
150
+ /**
151
+ * Create a new fluent Numberable instance.
152
+ *
153
+ * @param {unknown} [value] The initial value
154
+ * @returns {Numberable} A new Numberable instance
155
+ */
156
+ declare const num: (value?: unknown) => Numberable;
157
+ /**
158
+ * Static methods for number manipulation.
159
+ */
160
+ declare const NumberHelper: {
161
+ /** Create a new Numberable instance */
162
+ of: (value: unknown) => Numberable;
163
+ /** Format the number with locale-specific formatting */
164
+ format: (value: number, decimals?: number, locale?: string) => string;
165
+ /** Format the number as currency */
166
+ currency: (value: number, currency?: string, locale?: string) => string;
167
+ /** Format the number as a percentage */
168
+ percentage: (value: number, decimals?: number, locale?: string) => string;
169
+ /** Format the number as a human-readable file size */
170
+ fileSize: (value: number, precision?: number) => string;
171
+ /** Abbreviate the number */
172
+ abbreviate: (value: number, precision?: number) => string;
173
+ /** Add an ordinal suffix to the number */
174
+ ordinal: (value: number) => string;
175
+ };
176
+
177
+ export { NumberHelper, Numberable, num };
package/dist/number.js ADDED
@@ -0,0 +1,10 @@
1
+ import {
2
+ NumberHelper,
3
+ Numberable,
4
+ num
5
+ } from "./chunk-G7ZJ23DW.js";
6
+ export {
7
+ NumberHelper,
8
+ Numberable,
9
+ num
10
+ };