@catbee/utils 0.0.8-rc.3 → 0.0.8-rc.4

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 (128) hide show
  1. package/build/index.cjs +6591 -0
  2. package/build/index.d.ts +5131 -0
  3. package/build/index.mjs +6321 -0
  4. package/package.json +13 -292
  5. package/build/cjs/config.d.ts +0 -121
  6. package/build/cjs/config.js +0 -137
  7. package/build/cjs/index.d.ts +0 -26
  8. package/build/cjs/index.js +0 -68
  9. package/build/cjs/servers/server.builder.d.ts +0 -507
  10. package/build/cjs/servers/server.builder.js +0 -658
  11. package/build/cjs/servers/server.d.ts +0 -255
  12. package/build/cjs/servers/server.js +0 -970
  13. package/build/cjs/types/api-response.d.ts +0 -151
  14. package/build/cjs/types/api-response.js +0 -36
  15. package/build/cjs/types/index.d.ts +0 -124
  16. package/build/cjs/types/index.js +0 -25
  17. package/build/cjs/types/server.d.ts +0 -267
  18. package/build/cjs/types/server.js +0 -25
  19. package/build/cjs/utils/array.utils.d.ts +0 -167
  20. package/build/cjs/utils/array.utils.js +0 -363
  21. package/build/cjs/utils/async.utils.d.ts +0 -264
  22. package/build/cjs/utils/async.utils.js +0 -640
  23. package/build/cjs/utils/cache.utils.d.ts +0 -152
  24. package/build/cjs/utils/cache.utils.js +0 -298
  25. package/build/cjs/utils/context-store.utils.d.ts +0 -188
  26. package/build/cjs/utils/context-store.utils.js +0 -297
  27. package/build/cjs/utils/crypto.utils.d.ts +0 -159
  28. package/build/cjs/utils/crypto.utils.js +0 -295
  29. package/build/cjs/utils/date.utils.d.ts +0 -158
  30. package/build/cjs/utils/date.utils.js +0 -395
  31. package/build/cjs/utils/decorators.utils.d.ts +0 -511
  32. package/build/cjs/utils/decorators.utils.js +0 -1035
  33. package/build/cjs/utils/dir.utils.d.ts +0 -195
  34. package/build/cjs/utils/dir.utils.js +0 -500
  35. package/build/cjs/utils/env.utils.d.ts +0 -376
  36. package/build/cjs/utils/env.utils.js +0 -786
  37. package/build/cjs/utils/exception.utils.d.ts +0 -229
  38. package/build/cjs/utils/exception.utils.js +0 -408
  39. package/build/cjs/utils/fs.utils.d.ts +0 -163
  40. package/build/cjs/utils/fs.utils.js +0 -371
  41. package/build/cjs/utils/http-status-codes.d.ts +0 -265
  42. package/build/cjs/utils/http-status-codes.js +0 -297
  43. package/build/cjs/utils/id.utils.d.ts +0 -35
  44. package/build/cjs/utils/id.utils.js +0 -90
  45. package/build/cjs/utils/logger.utils.d.ts +0 -159
  46. package/build/cjs/utils/logger.utils.js +0 -350
  47. package/build/cjs/utils/middleware.utils.d.ts +0 -99
  48. package/build/cjs/utils/middleware.utils.js +0 -243
  49. package/build/cjs/utils/obj.utils.d.ts +0 -123
  50. package/build/cjs/utils/obj.utils.js +0 -428
  51. package/build/cjs/utils/performance.utils.d.ts +0 -135
  52. package/build/cjs/utils/performance.utils.js +0 -280
  53. package/build/cjs/utils/request.utils.d.ts +0 -85
  54. package/build/cjs/utils/request.utils.js +0 -199
  55. package/build/cjs/utils/response.utils.d.ts +0 -162
  56. package/build/cjs/utils/response.utils.js +0 -274
  57. package/build/cjs/utils/stream.utils.d.ts +0 -87
  58. package/build/cjs/utils/stream.utils.js +0 -217
  59. package/build/cjs/utils/string.utils.d.ts +0 -92
  60. package/build/cjs/utils/string.utils.js +0 -178
  61. package/build/cjs/utils/type.utils.d.ts +0 -89
  62. package/build/cjs/utils/type.utils.js +0 -195
  63. package/build/cjs/utils/url.utils.d.ts +0 -140
  64. package/build/cjs/utils/url.utils.js +0 -316
  65. package/build/cjs/utils/validate.utils.d.ts +0 -176
  66. package/build/cjs/utils/validate.utils.js +0 -344
  67. package/build/esm/config.d.ts +0 -121
  68. package/build/esm/config.js +0 -132
  69. package/build/esm/index.d.ts +0 -26
  70. package/build/esm/index.js +0 -49
  71. package/build/esm/servers/server.builder.d.ts +0 -507
  72. package/build/esm/servers/server.builder.js +0 -654
  73. package/build/esm/servers/server.d.ts +0 -255
  74. package/build/esm/servers/server.js +0 -963
  75. package/build/esm/types/api-response.d.ts +0 -151
  76. package/build/esm/types/api-response.js +0 -33
  77. package/build/esm/types/index.d.ts +0 -124
  78. package/build/esm/types/index.js +0 -24
  79. package/build/esm/types/server.d.ts +0 -267
  80. package/build/esm/types/server.js +0 -24
  81. package/build/esm/utils/array.utils.d.ts +0 -167
  82. package/build/esm/utils/array.utils.js +0 -344
  83. package/build/esm/utils/async.utils.d.ts +0 -264
  84. package/build/esm/utils/async.utils.js +0 -619
  85. package/build/esm/utils/cache.utils.d.ts +0 -152
  86. package/build/esm/utils/cache.utils.js +0 -294
  87. package/build/esm/utils/context-store.utils.d.ts +0 -188
  88. package/build/esm/utils/context-store.utils.js +0 -290
  89. package/build/esm/utils/crypto.utils.d.ts +0 -159
  90. package/build/esm/utils/crypto.utils.js +0 -278
  91. package/build/esm/utils/date.utils.d.ts +0 -158
  92. package/build/esm/utils/date.utils.js +0 -383
  93. package/build/esm/utils/decorators.utils.d.ts +0 -511
  94. package/build/esm/utils/decorators.utils.js +0 -1013
  95. package/build/esm/utils/dir.utils.d.ts +0 -195
  96. package/build/esm/utils/dir.utils.js +0 -476
  97. package/build/esm/utils/env.utils.d.ts +0 -376
  98. package/build/esm/utils/env.utils.js +0 -782
  99. package/build/esm/utils/exception.utils.d.ts +0 -229
  100. package/build/esm/utils/exception.utils.js +0 -382
  101. package/build/esm/utils/fs.utils.d.ts +0 -163
  102. package/build/esm/utils/fs.utils.js +0 -348
  103. package/build/esm/utils/http-status-codes.d.ts +0 -265
  104. package/build/esm/utils/http-status-codes.js +0 -294
  105. package/build/esm/utils/id.utils.d.ts +0 -35
  106. package/build/esm/utils/id.utils.js +0 -83
  107. package/build/esm/utils/logger.utils.d.ts +0 -159
  108. package/build/esm/utils/logger.utils.js +0 -304
  109. package/build/esm/utils/middleware.utils.d.ts +0 -99
  110. package/build/esm/utils/middleware.utils.js +0 -235
  111. package/build/esm/utils/obj.utils.d.ts +0 -123
  112. package/build/esm/utils/obj.utils.js +0 -412
  113. package/build/esm/utils/performance.utils.d.ts +0 -135
  114. package/build/esm/utils/performance.utils.js +0 -273
  115. package/build/esm/utils/request.utils.d.ts +0 -85
  116. package/build/esm/utils/request.utils.js +0 -190
  117. package/build/esm/utils/response.utils.d.ts +0 -162
  118. package/build/esm/utils/response.utils.js +0 -261
  119. package/build/esm/utils/stream.utils.d.ts +0 -87
  120. package/build/esm/utils/stream.utils.js +0 -209
  121. package/build/esm/utils/string.utils.d.ts +0 -92
  122. package/build/esm/utils/string.utils.js +0 -164
  123. package/build/esm/utils/type.utils.d.ts +0 -89
  124. package/build/esm/utils/type.utils.js +0 -186
  125. package/build/esm/utils/url.utils.d.ts +0 -140
  126. package/build/esm/utils/url.utils.js +0 -303
  127. package/build/esm/utils/validate.utils.d.ts +0 -176
  128. package/build/esm/utils/validate.utils.js +0 -319
@@ -1,209 +0,0 @@
1
- /*
2
- * The MIT License
3
- *
4
- * Copyright (c) 2025 Catbee Technologies. https://catbee-utils.npm.hprasath.com/license
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
- import { Readable, Transform } from 'stream';
25
- /**
26
- * Convert a buffer or string to a readable stream.
27
- *
28
- * @param data - Buffer or string to convert
29
- * @returns Readable stream containing the data
30
- *
31
- * @example
32
- * ```typescript
33
- * const stream = bufferToStream(Buffer.from('Hello world'));
34
- * // or
35
- * const stream = bufferToStream('Hello world');
36
- * ```
37
- */
38
- export function bufferToStream(data) {
39
- const readable = new Readable();
40
- readable.push(data);
41
- readable.push(null); // End of stream
42
- return readable;
43
- }
44
- /**
45
- * Convert a readable stream to a buffer.
46
- *
47
- * @param stream - Readable stream to convert
48
- * @returns Promise resolving to a buffer containing all stream data
49
- *
50
- * @example
51
- * ```typescript
52
- * const buffer = await streamToBuffer(fs.createReadStream('file.txt'));
53
- * console.log(buffer.toString()); // Contents of file.txt
54
- * ```
55
- */
56
- export async function streamToBuffer(stream) {
57
- return new Promise((resolve, reject) => {
58
- const chunks = [];
59
- stream.on('data', chunk => chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)));
60
- stream.on('end', () => resolve(Buffer.concat(chunks)));
61
- stream.on('error', reject);
62
- });
63
- }
64
- /**
65
- * Convert a readable stream to a string.
66
- *
67
- * @param stream - Readable stream to convert
68
- * @param encoding - Character encoding (default: 'utf8')
69
- * @returns Promise resolving to a string containing all stream data
70
- *
71
- * @example
72
- * ```typescript
73
- * const content = await streamToString(fs.createReadStream('file.txt'));
74
- * console.log(content); // Contents of file.txt as string
75
- * ```
76
- */
77
- export async function streamToString(stream, encoding = 'utf8') {
78
- const buffer = await streamToBuffer(stream);
79
- return buffer.toString(encoding);
80
- }
81
- /**
82
- * Create a transform stream that limits the rate of data flow.
83
- *
84
- * @param bytesPerSecond - Maximum bytes per second
85
- * @returns Transform stream that throttles data flow
86
- */
87
- export function createThrottleStream(bytesPerSecond) {
88
- let bytesSent = 0;
89
- let startTime = Date.now();
90
- return new Transform({
91
- transform(chunk, _encoding, callback) {
92
- const elapsedSeconds = (Date.now() - startTime) / 1000;
93
- const targetBytes = bytesPerSecond * elapsedSeconds;
94
- const chunkSize = chunk.length;
95
- // If we've sent fewer bytes than our target, just send the chunk
96
- if (bytesSent + chunkSize <= targetBytes) {
97
- bytesSent += chunkSize;
98
- callback(null, chunk);
99
- return;
100
- }
101
- // Otherwise we need to throttle
102
- const delay = ((bytesSent + chunkSize) / bytesPerSecond - elapsedSeconds) * 1000;
103
- setTimeout(() => {
104
- bytesSent += chunkSize;
105
- callback(null, chunk);
106
- }, delay);
107
- }
108
- });
109
- }
110
- /**
111
- * Create a transform stream that batches data into chunks of specified size.
112
- *
113
- * @param size - Size of each batch (items for object mode, bytes for binary mode)
114
- * @param options - Stream options
115
- * @returns Transform stream that batches data
116
- *
117
- * @example
118
- * ```typescript
119
- * // Batch lines from a file into arrays of 100 lines each
120
- * createReadStream('large-file.txt')
121
- * .pipe(createLineStream())
122
- * .pipe(createBatchStream(100))
123
- * .on('data', batch => console.log(`Processing batch of ${batch.length} lines`));
124
- * ```
125
- */
126
- export function createBatchStream(size, options = {}) {
127
- const objectMode = options.objectMode !== false;
128
- let batch = [];
129
- let buffers = [];
130
- let bufferSize = 0;
131
- return new Transform({
132
- objectMode,
133
- transform(chunk, _encoding, callback) {
134
- if (objectMode) {
135
- batch.push(chunk);
136
- if (batch.length >= size) {
137
- this.push(batch);
138
- batch = [];
139
- }
140
- }
141
- else {
142
- const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
143
- buffers.push(buffer);
144
- bufferSize += buffer.length;
145
- // Emit batches of exact size
146
- let combined = Buffer.concat(buffers, bufferSize);
147
- while (combined.length >= size) {
148
- this.push(combined.slice(0, size));
149
- combined = combined.slice(size);
150
- }
151
- buffers = combined.length > 0 ? [combined] : [];
152
- bufferSize = combined.length;
153
- }
154
- callback();
155
- },
156
- flush(callback) {
157
- if (objectMode && batch.length > 0) {
158
- this.push(batch);
159
- }
160
- else if (!objectMode && buffers.length > 0 && bufferSize > 0) {
161
- let combined = Buffer.concat(buffers, bufferSize);
162
- while (combined.length >= size) {
163
- this.push(combined.slice(0, size));
164
- combined = combined.slice(size);
165
- }
166
- if (combined.length > 0) {
167
- this.push(combined);
168
- }
169
- }
170
- callback();
171
- }
172
- });
173
- }
174
- /**
175
- * Create a transform stream that splits text data by newlines.
176
- *
177
- * @param options - Options for the line stream
178
- * @returns Transform stream that emits lines
179
- *
180
- * @example
181
- * ```typescript
182
- * // Process a file line by line
183
- * createReadStream('file.txt')
184
- * .pipe(createLineStream())
185
- * .on('data', line => console.log(`Line: ${line}`));
186
- * ```
187
- */
188
- export function createLineStream(options = {}) {
189
- const { encoding = 'utf8', includeNewlines = false } = options;
190
- let buffer = '';
191
- return new Transform({
192
- objectMode: true,
193
- transform(chunk, _encoding, callback) {
194
- const str = buffer + (Buffer.isBuffer(chunk) ? chunk.toString(encoding) : chunk);
195
- const lines = str.split(/\r?\n/);
196
- buffer = lines.pop() || '';
197
- for (const line of lines) {
198
- this.push(includeNewlines ? line + '\n' : line);
199
- }
200
- callback();
201
- },
202
- flush(callback) {
203
- if (buffer) {
204
- this.push(buffer);
205
- }
206
- callback();
207
- }
208
- });
209
- }
@@ -1,92 +0,0 @@
1
- /**
2
- * Capitalizes the first character of a string.
3
- *
4
- * @param {string} str - The input string.
5
- * @returns {string} The string with the first character in uppercase.
6
- */
7
- export declare function capitalize(str: string): string;
8
- /**
9
- * Converts a string to kebab-case (e.g., "FooBar test" → "foo-bar-test").
10
- *
11
- * @param {string} str - The input string.
12
- * @returns {string} The kebab-cased string.
13
- */
14
- export declare function toKebabCase(str: string): string;
15
- /**
16
- * Converts a kebab-case or snake_case string to camelCase.
17
- *
18
- * @param {string} str - The input string.
19
- * @returns {string} The camelCased string.
20
- */
21
- export declare function toCamelCase(str: string): string;
22
- /**
23
- * Converts a string to a URL-friendly slug (lowercase, dashes, alphanumeric).
24
- *
25
- * @param {string} str - The input string.
26
- * @returns {string} The slugified string.
27
- */
28
- export declare function slugify(str: string): string;
29
- /**
30
- * Truncates a string to a specific length, appending '...' if truncated.
31
- *
32
- * @param {string} str - The input string.
33
- * @param {number} len - The maximum length.
34
- * @returns {string} The truncated string.
35
- */
36
- export declare function truncate(str: string, len: number): string;
37
- /**
38
- * Converts a string to PascalCase (e.g., "foo-bar" → "FooBar").
39
- *
40
- * @param {string} str - The input string.
41
- * @returns {string} The PascalCased string.
42
- */
43
- export declare function toPascalCase(str: string): string;
44
- /**
45
- * Converts a string to snake_case (e.g., "FooBar test" → "foo_bar_test").
46
- *
47
- * @param {string} str - The input string.
48
- * @returns {string} The snake_cased string.
49
- */
50
- export declare function toSnakeCase(str: string): string;
51
- /**
52
- * Masks a string by replacing characters with a mask character.
53
- * Useful for hiding sensitive information like credit cards or passwords.
54
- *
55
- * @param {string} str - The string to mask.
56
- * @param {number} [visibleStart=0] - Number of characters to show at start.
57
- * @param {number} [visibleEnd=0] - Number of characters to show at end.
58
- * @param {string} [maskChar="*"] - Character to use for masking.
59
- * @returns {string} The masked string.
60
- */
61
- export declare function mask(str: string, visibleStart?: number, visibleEnd?: number, maskChar?: string): string;
62
- /**
63
- * Removes all HTML tags from a string.
64
- *
65
- * @param {string} str - The HTML string to process.
66
- * @returns {string} The string with HTML tags removed.
67
- */
68
- export declare function stripHtml(str: string): string;
69
- /**
70
- * Performs case-insensitive string comparison.
71
- *
72
- * @param {string} a - First string.
73
- * @param {string} b - Second string.
74
- * @returns {boolean} True if the strings are equal ignoring case.
75
- */
76
- export declare function equalsIgnoreCase(a: string, b: string): boolean;
77
- /**
78
- * Reverses a string.
79
- *
80
- * @param {string} str - The string to reverse.
81
- * @returns {string} The reversed string.
82
- */
83
- export declare function reverse(str: string): string;
84
- /**
85
- * Counts occurrences of a substring within a string.
86
- *
87
- * @param {string} str - The source string.
88
- * @param {string} substring - The substring to count.
89
- * @param {boolean} [caseSensitive=true] - Whether to perform case-sensitive counting.
90
- * @returns {number} Number of occurrences.
91
- */
92
- export declare function countOccurrences(str: string, substring: string, caseSensitive?: boolean): number;
@@ -1,164 +0,0 @@
1
- /*
2
- * The MIT License
3
- *
4
- * Copyright (c) 2025 Catbee Technologies. https://catbee-utils.npm.hprasath.com/license
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
- /**
25
- * Capitalizes the first character of a string.
26
- *
27
- * @param {string} str - The input string.
28
- * @returns {string} The string with the first character in uppercase.
29
- */
30
- export function capitalize(str) {
31
- return str.length === 0 ? '' : str.charAt(0).toUpperCase() + str.slice(1);
32
- }
33
- /**
34
- * Converts a string to kebab-case (e.g., "FooBar test" → "foo-bar-test").
35
- *
36
- * @param {string} str - The input string.
37
- * @returns {string} The kebab-cased string.
38
- */
39
- export function toKebabCase(str) {
40
- return str
41
- .replace(/([a-z])([A-Z])/g, '$1-$2') // camelCase -> camel-Case
42
- .replace(/\s+/g, '-') // spaces to dash
43
- .replace(/_+/g, '-') // underscores to dash
44
- .toLowerCase();
45
- }
46
- /**
47
- * Converts a kebab-case or snake_case string to camelCase.
48
- *
49
- * @param {string} str - The input string.
50
- * @returns {string} The camelCased string.
51
- */
52
- export function toCamelCase(str) {
53
- return str.replace(/[-_](.)/g, (_, c) => c.toUpperCase());
54
- }
55
- /**
56
- * Converts a string to a URL-friendly slug (lowercase, dashes, alphanumeric).
57
- *
58
- * @param {string} str - The input string.
59
- * @returns {string} The slugified string.
60
- */
61
- export function slugify(str) {
62
- return str
63
- .toLowerCase()
64
- .replace(/[^\w\s-]/g, '') // remove non-word
65
- .replace(/\s+/g, '-') // spaces to dash
66
- .replace(/-+/g, '-') // multiple dashes to one
67
- .replace(/^-+|-+$/g, ''); // trim leading/trailing dashes
68
- }
69
- /**
70
- * Truncates a string to a specific length, appending '...' if truncated.
71
- *
72
- * @param {string} str - The input string.
73
- * @param {number} len - The maximum length.
74
- * @returns {string} The truncated string.
75
- */
76
- export function truncate(str, len) {
77
- return str.length > len ? str.slice(0, len) + '...' : str;
78
- }
79
- /**
80
- * Converts a string to PascalCase (e.g., "foo-bar" → "FooBar").
81
- *
82
- * @param {string} str - The input string.
83
- * @returns {string} The PascalCased string.
84
- */
85
- export function toPascalCase(str) {
86
- return capitalize(toCamelCase(str));
87
- }
88
- /**
89
- * Converts a string to snake_case (e.g., "FooBar test" → "foo_bar_test").
90
- *
91
- * @param {string} str - The input string.
92
- * @returns {string} The snake_cased string.
93
- */
94
- export function toSnakeCase(str) {
95
- return str
96
- .trim()
97
- .replace(/([a-z])([A-Z])/g, '$1_$2') // camelCase -> camel_Case
98
- .replace(/\s+/g, '_') // spaces to underscore
99
- .replace(/-+/g, '_') // dashes to underscore
100
- .toLowerCase();
101
- }
102
- /**
103
- * Masks a string by replacing characters with a mask character.
104
- * Useful for hiding sensitive information like credit cards or passwords.
105
- *
106
- * @param {string} str - The string to mask.
107
- * @param {number} [visibleStart=0] - Number of characters to show at start.
108
- * @param {number} [visibleEnd=0] - Number of characters to show at end.
109
- * @param {string} [maskChar="*"] - Character to use for masking.
110
- * @returns {string} The masked string.
111
- */
112
- export function mask(str, visibleStart = 0, visibleEnd = 0, maskChar = '*') {
113
- if (!str || str.length === 0)
114
- return '';
115
- if (visibleStart >= str.length)
116
- return str;
117
- const start = str.slice(0, visibleStart);
118
- const end = visibleEnd > 0 ? str.slice(-visibleEnd) : '';
119
- const masked = maskChar.repeat(Math.max(0, str.length - visibleStart - visibleEnd));
120
- return start + masked + end;
121
- }
122
- /**
123
- * Removes all HTML tags from a string.
124
- *
125
- * @param {string} str - The HTML string to process.
126
- * @returns {string} The string with HTML tags removed.
127
- */
128
- export function stripHtml(str) {
129
- return str.replace(/<[^>]*>/g, '');
130
- }
131
- /**
132
- * Performs case-insensitive string comparison.
133
- *
134
- * @param {string} a - First string.
135
- * @param {string} b - Second string.
136
- * @returns {boolean} True if the strings are equal ignoring case.
137
- */
138
- export function equalsIgnoreCase(a, b) {
139
- return a.toLowerCase() === b.toLowerCase();
140
- }
141
- /**
142
- * Reverses a string.
143
- *
144
- * @param {string} str - The string to reverse.
145
- * @returns {string} The reversed string.
146
- */
147
- export function reverse(str) {
148
- return str.split('').reverse().join('');
149
- }
150
- /**
151
- * Counts occurrences of a substring within a string.
152
- *
153
- * @param {string} str - The source string.
154
- * @param {string} substring - The substring to count.
155
- * @param {boolean} [caseSensitive=true] - Whether to perform case-sensitive counting.
156
- * @returns {number} Number of occurrences.
157
- */
158
- export function countOccurrences(str, substring, caseSensitive = true) {
159
- if (!caseSensitive) {
160
- str = str.toLowerCase();
161
- substring = substring.toLowerCase();
162
- }
163
- return str.split(substring).length - 1;
164
- }
@@ -1,89 +0,0 @@
1
- /**
2
- * Check if a value is of a specific primitive type.
3
- *
4
- * @param value - Value to check
5
- * @param type - Type to check against
6
- * @returns Whether the value is of the specified type
7
- *
8
- * @example
9
- * ```typescript
10
- * isPrimitiveType('hello', 'string'); // true
11
- * isPrimitiveType(42, 'number'); // true
12
- * isPrimitiveType(true, 'boolean'); // true
13
- * isPrimitiveType(null, 'null'); // true
14
- * isPrimitiveType(undefined, 'undefined'); // true
15
- * isPrimitiveType({}, 'object'); // true
16
- * isPrimitiveType([], 'array'); // true
17
- * ```
18
- */
19
- export declare function isPrimitiveType(value: unknown, type: 'string' | 'number' | 'boolean' | 'symbol' | 'bigint' | 'function' | 'object' | 'array' | 'null' | 'undefined'): boolean;
20
- /**
21
- * Get the primitive type of a value as a string.
22
- *
23
- * @param value - Value to get the type of
24
- * @returns String representing the type
25
- *
26
- * @example
27
- * ```typescript
28
- * getTypeOf('hello'); // 'string'
29
- * getTypeOf(42); // 'number'
30
- * getTypeOf([]); // 'array'
31
- * getTypeOf(null); // 'null'
32
- * ```
33
- */
34
- export declare function getTypeOf(value: unknown): string;
35
- /**
36
- * Type guard for checking if a value is an array of a specific type.
37
- *
38
- * @param value - Value to check
39
- * @param itemTypeGuard - Function that checks if items are of the expected type
40
- * @returns True if the value is an array with items of the expected type
41
- *
42
- * @example
43
- * ```typescript
44
- * isArrayOf([1, 2, 3], (item): item is number => typeof item === 'number'); // true
45
- * isArrayOf(['a', 'b', 'c'], (item): item is string => typeof item === 'string'); // true
46
- * isArrayOf([1, '2', 3], (item): item is number => typeof item === 'number'); // false
47
- * ```
48
- */
49
- export declare function isArrayOf<T>(value: unknown, itemTypeGuard: (item: unknown) => item is T): value is T[];
50
- /**
51
- * Convert a value to a string.
52
- *
53
- * @param value - Value to convert
54
- * @param defaultValue - Default value if conversion fails
55
- * @returns String representation of the value
56
- */
57
- export declare function toStr(value: unknown, defaultValue?: string): string;
58
- /**
59
- * Convert a value to a number.
60
- *
61
- * @param value - Value to convert
62
- * @param defaultValue - Default value if conversion fails
63
- * @returns Numeric representation of the value
64
- */
65
- export declare function toNum(value: unknown, defaultValue?: number): number;
66
- /**
67
- * Convert a value to a boolean.
68
- *
69
- * @param value - Value to convert
70
- * @param defaultValue - Default value if conversion fails
71
- * @returns Boolean representation of the value
72
- */
73
- export declare function toBool(value: unknown, defaultValue?: boolean): boolean;
74
- /**
75
- * Ensure a value matches the expected type, or provide a default.
76
- *
77
- * @param value - Value to check
78
- * @param expectedType - Expected primitive type
79
- * @param defaultValue - Default value to use if type doesn't match
80
- * @returns The value if it matches the type, otherwise the default
81
- *
82
- * @example
83
- * ```typescript
84
- * ensureType(42, 'number', 0); // 42
85
- * ensureType('42', 'number', 0); // 0
86
- * ensureType(undefined, 'string', 'default'); // 'default'
87
- * ```
88
- */
89
- export declare function ensureType<T>(value: unknown, expectedType: string, defaultValue: T): T;