@sudobility/types 1.9.53 → 1.9.55
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.
- package/dist/types/blockchain/index.cjs +30 -0
- package/dist/types/blockchain/index.d.ts +14 -0
- package/dist/types/blockchain/index.d.ts.map +1 -0
- package/dist/types/blockchain/index.js +30 -0
- package/dist/types/blockchain/index.js.map +1 -0
- package/dist/types/blockchain/validation.cjs +57 -1
- package/dist/types/blockchain/validation.d.ts +57 -1
- package/dist/types/blockchain/validation.d.ts.map +1 -1
- package/dist/types/blockchain/validation.js +57 -1
- package/dist/types/blockchain/validation.js.map +1 -1
- package/dist/types/business/enums.cjs +110 -25
- package/dist/types/business/enums.d.ts +110 -2
- package/dist/types/business/enums.d.ts.map +1 -1
- package/dist/types/business/enums.js +110 -25
- package/dist/types/business/enums.js.map +1 -1
- package/dist/types/common.cjs +7 -1
- package/dist/types/common.d.ts +134 -20
- package/dist/types/common.d.ts.map +1 -1
- package/dist/types/common.js +7 -1
- package/dist/types/common.js.map +1 -1
- package/dist/utils/async-helpers.cjs +124 -10
- package/dist/utils/async-helpers.d.ts +129 -8
- package/dist/utils/async-helpers.d.ts.map +1 -1
- package/dist/utils/async-helpers.js +124 -10
- package/dist/utils/async-helpers.js.map +1 -1
- package/dist/utils/formatting/currency.cjs +5 -2
- package/dist/utils/formatting/currency.d.ts +5 -1
- package/dist/utils/formatting/currency.d.ts.map +1 -1
- package/dist/utils/formatting/currency.js +5 -2
- package/dist/utils/formatting/currency.js.map +1 -1
- package/dist/utils/formatting/date.cjs +67 -8
- package/dist/utils/formatting/date.d.ts +67 -8
- package/dist/utils/formatting/date.d.ts.map +1 -1
- package/dist/utils/formatting/date.js +67 -8
- package/dist/utils/formatting/date.js.map +1 -1
- package/dist/utils/formatting/string.cjs +150 -17
- package/dist/utils/formatting/string.d.ts +150 -17
- package/dist/utils/formatting/string.d.ts.map +1 -1
- package/dist/utils/formatting/string.js +150 -17
- package/dist/utils/formatting/string.js.map +1 -1
- package/dist/utils/validation/type-validation.cjs +94 -11
- package/dist/utils/validation/type-validation.d.ts +94 -11
- package/dist/utils/validation/type-validation.d.ts.map +1 -1
- package/dist/utils/validation/type-validation.js +94 -11
- package/dist/utils/validation/type-validation.js.map +1 -1
- package/package.json +6 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* String formatting and manipulation utilities
|
|
3
|
+
* String formatting and manipulation utilities.
|
|
4
|
+
*
|
|
5
|
+
* @since 1.0.0
|
|
4
6
|
*/
|
|
5
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
8
|
exports.truncate = truncate;
|
|
@@ -20,7 +22,18 @@ exports.randomString = randomString;
|
|
|
20
22
|
exports.pluralize = pluralize;
|
|
21
23
|
exports.formatNumber = formatNumber;
|
|
22
24
|
/**
|
|
23
|
-
* Truncate a string to a maximum length with
|
|
25
|
+
* Truncate a string to a maximum length with a suffix (default `...`).
|
|
26
|
+
*
|
|
27
|
+
* @param str - Input string
|
|
28
|
+
* @param maxLength - Maximum allowed length including suffix
|
|
29
|
+
* @param suffix - Truncation suffix (default: `'...'`)
|
|
30
|
+
* @returns Truncated string or original if within limit
|
|
31
|
+
* @since 1.0.0
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* truncate('Hello, World!', 8); // "Hello..."
|
|
36
|
+
* ```
|
|
24
37
|
*/
|
|
25
38
|
function truncate(str, maxLength, suffix = '...') {
|
|
26
39
|
if (!str || str.length <= maxLength) {
|
|
@@ -29,7 +42,16 @@ function truncate(str, maxLength, suffix = '...') {
|
|
|
29
42
|
return str.slice(0, maxLength - suffix.length) + suffix;
|
|
30
43
|
}
|
|
31
44
|
/**
|
|
32
|
-
* Capitalize the first letter of a string
|
|
45
|
+
* Capitalize the first letter of a string.
|
|
46
|
+
*
|
|
47
|
+
* @param str - Input string
|
|
48
|
+
* @returns String with first character uppercased
|
|
49
|
+
* @since 1.0.0
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* capitalize('hello'); // "Hello"
|
|
54
|
+
* ```
|
|
33
55
|
*/
|
|
34
56
|
function capitalize(str) {
|
|
35
57
|
if (!str)
|
|
@@ -37,7 +59,16 @@ function capitalize(str) {
|
|
|
37
59
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
38
60
|
}
|
|
39
61
|
/**
|
|
40
|
-
* Convert a string to title case
|
|
62
|
+
* Convert a string to title case (capitalize each word).
|
|
63
|
+
*
|
|
64
|
+
* @param str - Input string
|
|
65
|
+
* @returns Title-cased string
|
|
66
|
+
* @since 1.0.0
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* toTitleCase('hello world'); // "Hello World"
|
|
71
|
+
* ```
|
|
41
72
|
*/
|
|
42
73
|
function toTitleCase(str) {
|
|
43
74
|
if (!str)
|
|
@@ -49,7 +80,16 @@ function toTitleCase(str) {
|
|
|
49
80
|
.join(' ');
|
|
50
81
|
}
|
|
51
82
|
/**
|
|
52
|
-
* Convert a string to kebab
|
|
83
|
+
* Convert a string to kebab-case.
|
|
84
|
+
*
|
|
85
|
+
* @param str - Input string (camelCase, PascalCase, spaces, or underscores)
|
|
86
|
+
* @returns Kebab-cased string
|
|
87
|
+
* @since 1.0.0
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* toKebabCase('helloWorld'); // "hello-world"
|
|
92
|
+
* ```
|
|
53
93
|
*/
|
|
54
94
|
function toKebabCase(str) {
|
|
55
95
|
if (!str)
|
|
@@ -60,7 +100,16 @@ function toKebabCase(str) {
|
|
|
60
100
|
.toLowerCase();
|
|
61
101
|
}
|
|
62
102
|
/**
|
|
63
|
-
* Convert a string to
|
|
103
|
+
* Convert a string to camelCase.
|
|
104
|
+
*
|
|
105
|
+
* @param str - Input string (kebab-case, snake_case, or spaces)
|
|
106
|
+
* @returns camelCased string
|
|
107
|
+
* @since 1.0.0
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* toCamelCase('hello-world'); // "helloWorld"
|
|
112
|
+
* ```
|
|
64
113
|
*/
|
|
65
114
|
function toCamelCase(str) {
|
|
66
115
|
if (!str)
|
|
@@ -70,7 +119,16 @@ function toCamelCase(str) {
|
|
|
70
119
|
.replace(/^./, (char) => char.toLowerCase());
|
|
71
120
|
}
|
|
72
121
|
/**
|
|
73
|
-
* Convert a string to
|
|
122
|
+
* Convert a string to snake_case.
|
|
123
|
+
*
|
|
124
|
+
* @param str - Input string (camelCase, kebab-case, or spaces)
|
|
125
|
+
* @returns snake_cased string
|
|
126
|
+
* @since 1.0.0
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* toSnakeCase('helloWorld'); // "hello_world"
|
|
131
|
+
* ```
|
|
74
132
|
*/
|
|
75
133
|
function toSnakeCase(str) {
|
|
76
134
|
if (!str)
|
|
@@ -81,7 +139,11 @@ function toSnakeCase(str) {
|
|
|
81
139
|
.toLowerCase();
|
|
82
140
|
}
|
|
83
141
|
/**
|
|
84
|
-
*
|
|
142
|
+
* Collapse consecutive whitespace to a single space and trim.
|
|
143
|
+
*
|
|
144
|
+
* @param str - Input string
|
|
145
|
+
* @returns Normalized string
|
|
146
|
+
* @since 1.0.0
|
|
85
147
|
*/
|
|
86
148
|
function normalizeWhitespace(str) {
|
|
87
149
|
if (!str)
|
|
@@ -89,19 +151,36 @@ function normalizeWhitespace(str) {
|
|
|
89
151
|
return str.replace(/\s+/g, ' ').trim();
|
|
90
152
|
}
|
|
91
153
|
/**
|
|
92
|
-
* Check if a string is empty or only whitespace
|
|
154
|
+
* Check if a string is empty, undefined, null, or only whitespace.
|
|
155
|
+
*
|
|
156
|
+
* @param str - Input string (may be nullish)
|
|
157
|
+
* @returns True if blank
|
|
158
|
+
* @since 1.0.0
|
|
93
159
|
*/
|
|
94
160
|
function isBlank(str) {
|
|
95
161
|
return !str || str.trim().length === 0;
|
|
96
162
|
}
|
|
97
163
|
/**
|
|
98
|
-
*
|
|
164
|
+
* Type guard: check if a string is not empty and not only whitespace.
|
|
165
|
+
*
|
|
166
|
+
* @param str - Input string (may be nullish)
|
|
167
|
+
* @returns True (and narrows to `string`) if not blank
|
|
168
|
+
* @since 1.0.0
|
|
99
169
|
*/
|
|
100
170
|
function isNotBlank(str) {
|
|
101
171
|
return !isBlank(str);
|
|
102
172
|
}
|
|
103
173
|
/**
|
|
104
|
-
* Escape HTML special characters
|
|
174
|
+
* Escape HTML special characters (`&`, `<`, `>`, `"`, `'`).
|
|
175
|
+
*
|
|
176
|
+
* @param str - Input string
|
|
177
|
+
* @returns HTML-escaped string
|
|
178
|
+
* @since 1.0.0
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* escapeHtml('<b>Hi</b>'); // "<b>Hi</b>"
|
|
183
|
+
* ```
|
|
105
184
|
*/
|
|
106
185
|
function escapeHtml(str) {
|
|
107
186
|
if (!str)
|
|
@@ -116,7 +195,16 @@ function escapeHtml(str) {
|
|
|
116
195
|
return str.replace(/[&<>"']/g, (char) => htmlEscapes[char]);
|
|
117
196
|
}
|
|
118
197
|
/**
|
|
119
|
-
* Remove HTML tags from a string
|
|
198
|
+
* Remove all HTML tags from a string.
|
|
199
|
+
*
|
|
200
|
+
* @param str - Input string with HTML
|
|
201
|
+
* @returns Plain text with tags removed
|
|
202
|
+
* @since 1.0.0
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ```typescript
|
|
206
|
+
* stripHtml('<p>Hello <b>world</b></p>'); // "Hello world"
|
|
207
|
+
* ```
|
|
120
208
|
*/
|
|
121
209
|
function stripHtml(str) {
|
|
122
210
|
if (!str)
|
|
@@ -124,7 +212,12 @@ function stripHtml(str) {
|
|
|
124
212
|
return str.replace(/<[^>]*>/g, '');
|
|
125
213
|
}
|
|
126
214
|
/**
|
|
127
|
-
* Extract initials from a name
|
|
215
|
+
* Extract initials from a name (e.g., "John Doe" -> "JD").
|
|
216
|
+
*
|
|
217
|
+
* @param name - Full name
|
|
218
|
+
* @param maxInitials - Maximum number of initials (default: 2)
|
|
219
|
+
* @returns Uppercase initials
|
|
220
|
+
* @since 1.0.0
|
|
128
221
|
*/
|
|
129
222
|
function getInitials(name, maxInitials = 2) {
|
|
130
223
|
if (!name)
|
|
@@ -137,7 +230,18 @@ function getInitials(name, maxInitials = 2) {
|
|
|
137
230
|
return initials;
|
|
138
231
|
}
|
|
139
232
|
/**
|
|
140
|
-
* Format bytes to human-readable size
|
|
233
|
+
* Format bytes to a human-readable size string (e.g., "1.5 MB").
|
|
234
|
+
*
|
|
235
|
+
* @param bytes - Size in bytes
|
|
236
|
+
* @param decimals - Decimal places (default: 2)
|
|
237
|
+
* @returns Formatted string like "1.5 MB"
|
|
238
|
+
* @since 1.0.0
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```typescript
|
|
242
|
+
* formatBytes(1536); // "1.5 KB"
|
|
243
|
+
* formatBytes(0); // "0 Bytes"
|
|
244
|
+
* ```
|
|
141
245
|
*/
|
|
142
246
|
function formatBytes(bytes, decimals = 2) {
|
|
143
247
|
if (bytes === 0)
|
|
@@ -149,7 +253,13 @@ function formatBytes(bytes, decimals = 2) {
|
|
|
149
253
|
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
|
|
150
254
|
}
|
|
151
255
|
/**
|
|
152
|
-
* Generate a random string
|
|
256
|
+
* Generate a random string of a given length.
|
|
257
|
+
*
|
|
258
|
+
* @param length - Desired string length
|
|
259
|
+
* @param charset - Character set: `'alpha'`, `'numeric'`,
|
|
260
|
+
* `'alphanumeric'` (default), `'hex'`, or a custom string
|
|
261
|
+
* @returns Random string
|
|
262
|
+
* @since 1.0.0
|
|
153
263
|
*/
|
|
154
264
|
function randomString(length, charset = 'alphanumeric') {
|
|
155
265
|
let chars;
|
|
@@ -176,7 +286,21 @@ function randomString(length, charset = 'alphanumeric') {
|
|
|
176
286
|
return result;
|
|
177
287
|
}
|
|
178
288
|
/**
|
|
179
|
-
* Pluralize a word based on count
|
|
289
|
+
* Pluralize a word based on count.
|
|
290
|
+
* Appends `'s'` by default when count is not 1.
|
|
291
|
+
*
|
|
292
|
+
* @param count - Item count
|
|
293
|
+
* @param singular - Singular form
|
|
294
|
+
* @param plural - Optional explicit plural form
|
|
295
|
+
* @returns Singular or plural form based on count
|
|
296
|
+
* @since 1.0.0
|
|
297
|
+
*
|
|
298
|
+
* @example
|
|
299
|
+
* ```typescript
|
|
300
|
+
* pluralize(1, 'item'); // "item"
|
|
301
|
+
* pluralize(3, 'item'); // "items"
|
|
302
|
+
* pluralize(2, 'child', 'children'); // "children"
|
|
303
|
+
* ```
|
|
180
304
|
*/
|
|
181
305
|
function pluralize(count, singular, plural) {
|
|
182
306
|
if (count === 1) {
|
|
@@ -185,7 +309,16 @@ function pluralize(count, singular, plural) {
|
|
|
185
309
|
return plural || `${singular}s`;
|
|
186
310
|
}
|
|
187
311
|
/**
|
|
188
|
-
* Format a number with commas as thousands separators
|
|
312
|
+
* Format a number with commas as thousands separators.
|
|
313
|
+
*
|
|
314
|
+
* @param num - Number to format
|
|
315
|
+
* @returns Formatted string (e.g., "1,234,567")
|
|
316
|
+
* @since 1.0.0
|
|
317
|
+
*
|
|
318
|
+
* @example
|
|
319
|
+
* ```typescript
|
|
320
|
+
* formatNumber(1234567); // "1,234,567"
|
|
321
|
+
* ```
|
|
189
322
|
*/
|
|
190
323
|
function formatNumber(num) {
|
|
191
324
|
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
@@ -1,69 +1,202 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* String formatting and manipulation utilities
|
|
2
|
+
* String formatting and manipulation utilities.
|
|
3
|
+
*
|
|
4
|
+
* @since 1.0.0
|
|
3
5
|
*/
|
|
4
6
|
import { Optional } from '../../types/common';
|
|
5
7
|
/**
|
|
6
|
-
* Truncate a string to a maximum length with
|
|
8
|
+
* Truncate a string to a maximum length with a suffix (default `...`).
|
|
9
|
+
*
|
|
10
|
+
* @param str - Input string
|
|
11
|
+
* @param maxLength - Maximum allowed length including suffix
|
|
12
|
+
* @param suffix - Truncation suffix (default: `'...'`)
|
|
13
|
+
* @returns Truncated string or original if within limit
|
|
14
|
+
* @since 1.0.0
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* truncate('Hello, World!', 8); // "Hello..."
|
|
19
|
+
* ```
|
|
7
20
|
*/
|
|
8
21
|
export declare function truncate(str: string, maxLength: number, suffix?: string): string;
|
|
9
22
|
/**
|
|
10
|
-
* Capitalize the first letter of a string
|
|
23
|
+
* Capitalize the first letter of a string.
|
|
24
|
+
*
|
|
25
|
+
* @param str - Input string
|
|
26
|
+
* @returns String with first character uppercased
|
|
27
|
+
* @since 1.0.0
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* capitalize('hello'); // "Hello"
|
|
32
|
+
* ```
|
|
11
33
|
*/
|
|
12
34
|
export declare function capitalize(str: string): string;
|
|
13
35
|
/**
|
|
14
|
-
* Convert a string to title case
|
|
36
|
+
* Convert a string to title case (capitalize each word).
|
|
37
|
+
*
|
|
38
|
+
* @param str - Input string
|
|
39
|
+
* @returns Title-cased string
|
|
40
|
+
* @since 1.0.0
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* toTitleCase('hello world'); // "Hello World"
|
|
45
|
+
* ```
|
|
15
46
|
*/
|
|
16
47
|
export declare function toTitleCase(str: string): string;
|
|
17
48
|
/**
|
|
18
|
-
* Convert a string to kebab
|
|
49
|
+
* Convert a string to kebab-case.
|
|
50
|
+
*
|
|
51
|
+
* @param str - Input string (camelCase, PascalCase, spaces, or underscores)
|
|
52
|
+
* @returns Kebab-cased string
|
|
53
|
+
* @since 1.0.0
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* toKebabCase('helloWorld'); // "hello-world"
|
|
58
|
+
* ```
|
|
19
59
|
*/
|
|
20
60
|
export declare function toKebabCase(str: string): string;
|
|
21
61
|
/**
|
|
22
|
-
* Convert a string to
|
|
62
|
+
* Convert a string to camelCase.
|
|
63
|
+
*
|
|
64
|
+
* @param str - Input string (kebab-case, snake_case, or spaces)
|
|
65
|
+
* @returns camelCased string
|
|
66
|
+
* @since 1.0.0
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* toCamelCase('hello-world'); // "helloWorld"
|
|
71
|
+
* ```
|
|
23
72
|
*/
|
|
24
73
|
export declare function toCamelCase(str: string): string;
|
|
25
74
|
/**
|
|
26
|
-
* Convert a string to
|
|
75
|
+
* Convert a string to snake_case.
|
|
76
|
+
*
|
|
77
|
+
* @param str - Input string (camelCase, kebab-case, or spaces)
|
|
78
|
+
* @returns snake_cased string
|
|
79
|
+
* @since 1.0.0
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* toSnakeCase('helloWorld'); // "hello_world"
|
|
84
|
+
* ```
|
|
27
85
|
*/
|
|
28
86
|
export declare function toSnakeCase(str: string): string;
|
|
29
87
|
/**
|
|
30
|
-
*
|
|
88
|
+
* Collapse consecutive whitespace to a single space and trim.
|
|
89
|
+
*
|
|
90
|
+
* @param str - Input string
|
|
91
|
+
* @returns Normalized string
|
|
92
|
+
* @since 1.0.0
|
|
31
93
|
*/
|
|
32
94
|
export declare function normalizeWhitespace(str: string): string;
|
|
33
95
|
/**
|
|
34
|
-
* Check if a string is empty or only whitespace
|
|
96
|
+
* Check if a string is empty, undefined, null, or only whitespace.
|
|
97
|
+
*
|
|
98
|
+
* @param str - Input string (may be nullish)
|
|
99
|
+
* @returns True if blank
|
|
100
|
+
* @since 1.0.0
|
|
35
101
|
*/
|
|
36
102
|
export declare function isBlank(str?: Optional<string>): boolean;
|
|
37
103
|
/**
|
|
38
|
-
*
|
|
104
|
+
* Type guard: check if a string is not empty and not only whitespace.
|
|
105
|
+
*
|
|
106
|
+
* @param str - Input string (may be nullish)
|
|
107
|
+
* @returns True (and narrows to `string`) if not blank
|
|
108
|
+
* @since 1.0.0
|
|
39
109
|
*/
|
|
40
110
|
export declare function isNotBlank(str?: Optional<string>): str is string;
|
|
41
111
|
/**
|
|
42
|
-
* Escape HTML special characters
|
|
112
|
+
* Escape HTML special characters (`&`, `<`, `>`, `"`, `'`).
|
|
113
|
+
*
|
|
114
|
+
* @param str - Input string
|
|
115
|
+
* @returns HTML-escaped string
|
|
116
|
+
* @since 1.0.0
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* escapeHtml('<b>Hi</b>'); // "<b>Hi</b>"
|
|
121
|
+
* ```
|
|
43
122
|
*/
|
|
44
123
|
export declare function escapeHtml(str: string): string;
|
|
45
124
|
/**
|
|
46
|
-
* Remove HTML tags from a string
|
|
125
|
+
* Remove all HTML tags from a string.
|
|
126
|
+
*
|
|
127
|
+
* @param str - Input string with HTML
|
|
128
|
+
* @returns Plain text with tags removed
|
|
129
|
+
* @since 1.0.0
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* stripHtml('<p>Hello <b>world</b></p>'); // "Hello world"
|
|
134
|
+
* ```
|
|
47
135
|
*/
|
|
48
136
|
export declare function stripHtml(str: string): string;
|
|
49
137
|
/**
|
|
50
|
-
* Extract initials from a name
|
|
138
|
+
* Extract initials from a name (e.g., "John Doe" -> "JD").
|
|
139
|
+
*
|
|
140
|
+
* @param name - Full name
|
|
141
|
+
* @param maxInitials - Maximum number of initials (default: 2)
|
|
142
|
+
* @returns Uppercase initials
|
|
143
|
+
* @since 1.0.0
|
|
51
144
|
*/
|
|
52
145
|
export declare function getInitials(name: string, maxInitials?: number): string;
|
|
53
146
|
/**
|
|
54
|
-
* Format bytes to human-readable size
|
|
147
|
+
* Format bytes to a human-readable size string (e.g., "1.5 MB").
|
|
148
|
+
*
|
|
149
|
+
* @param bytes - Size in bytes
|
|
150
|
+
* @param decimals - Decimal places (default: 2)
|
|
151
|
+
* @returns Formatted string like "1.5 MB"
|
|
152
|
+
* @since 1.0.0
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```typescript
|
|
156
|
+
* formatBytes(1536); // "1.5 KB"
|
|
157
|
+
* formatBytes(0); // "0 Bytes"
|
|
158
|
+
* ```
|
|
55
159
|
*/
|
|
56
160
|
export declare function formatBytes(bytes: number, decimals?: number): string;
|
|
57
161
|
/**
|
|
58
|
-
* Generate a random string
|
|
162
|
+
* Generate a random string of a given length.
|
|
163
|
+
*
|
|
164
|
+
* @param length - Desired string length
|
|
165
|
+
* @param charset - Character set: `'alpha'`, `'numeric'`,
|
|
166
|
+
* `'alphanumeric'` (default), `'hex'`, or a custom string
|
|
167
|
+
* @returns Random string
|
|
168
|
+
* @since 1.0.0
|
|
59
169
|
*/
|
|
60
170
|
export declare function randomString(length: number, charset?: string): string;
|
|
61
171
|
/**
|
|
62
|
-
* Pluralize a word based on count
|
|
172
|
+
* Pluralize a word based on count.
|
|
173
|
+
* Appends `'s'` by default when count is not 1.
|
|
174
|
+
*
|
|
175
|
+
* @param count - Item count
|
|
176
|
+
* @param singular - Singular form
|
|
177
|
+
* @param plural - Optional explicit plural form
|
|
178
|
+
* @returns Singular or plural form based on count
|
|
179
|
+
* @since 1.0.0
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* pluralize(1, 'item'); // "item"
|
|
184
|
+
* pluralize(3, 'item'); // "items"
|
|
185
|
+
* pluralize(2, 'child', 'children'); // "children"
|
|
186
|
+
* ```
|
|
63
187
|
*/
|
|
64
188
|
export declare function pluralize(count: number, singular: string, plural?: Optional<string>): string;
|
|
65
189
|
/**
|
|
66
|
-
* Format a number with commas as thousands separators
|
|
190
|
+
* Format a number with commas as thousands separators.
|
|
191
|
+
*
|
|
192
|
+
* @param num - Number to format
|
|
193
|
+
* @returns Formatted string (e.g., "1,234,567")
|
|
194
|
+
* @since 1.0.0
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```typescript
|
|
198
|
+
* formatNumber(1234567); // "1,234,567"
|
|
199
|
+
* ```
|
|
67
200
|
*/
|
|
68
201
|
export declare function formatNumber(num: number): string;
|
|
69
202
|
//# sourceMappingURL=string.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../../src/utils/formatting/string.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../../src/utils/formatting/string.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C;;;;;;;;;;;;;GAaG;AACH,wBAAgB,QAAQ,CACtB,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,MAAM,EACjB,MAAM,SAAQ,GACb,MAAM,CAKR;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAG9C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAO/C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAM/C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAK/C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAM/C;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAGvD;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,OAAO,CAEvD;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,GAAG,IAAI,MAAM,CAEhE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAU9C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAG7C;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,SAAI,GAAG,MAAM,CAUjE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,SAAI,GAAG,MAAM,CAU/D;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,SAAiB,GAAG,MAAM,CA0B7E;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,SAAS,CACvB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,GACxB,MAAM,CAKR;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEhD"}
|