@catbee/utils 1.1.0 → 2.0.0-next.1

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 (90) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +79 -43
  3. package/array/index.cjs +355 -0
  4. package/array/index.d.ts +317 -0
  5. package/array/index.mjs +327 -0
  6. package/async/index.cjs +484 -0
  7. package/async/index.d.ts +299 -0
  8. package/async/index.mjs +463 -0
  9. package/cache/index.cjs +292 -0
  10. package/cache/index.d.ts +179 -0
  11. package/cache/index.mjs +290 -0
  12. package/config/index.cjs +150 -0
  13. package/config/index.d.ts +88 -0
  14. package/config/index.mjs +143 -0
  15. package/context-store/index.cjs +267 -0
  16. package/context-store/index.d.ts +216 -0
  17. package/context-store/index.mjs +261 -0
  18. package/crypto/index.cjs +182 -0
  19. package/crypto/index.d.ts +187 -0
  20. package/crypto/index.mjs +166 -0
  21. package/date/index.cjs +340 -0
  22. package/date/index.d.ts +214 -0
  23. package/date/index.mjs +326 -0
  24. package/decorators/index.cjs +2051 -0
  25. package/decorators/index.d.ts +708 -0
  26. package/decorators/index.mjs +2010 -0
  27. package/dir/index.cjs +417 -0
  28. package/dir/index.d.ts +219 -0
  29. package/dir/index.mjs +390 -0
  30. package/env/index.cjs +745 -0
  31. package/env/index.d.ts +403 -0
  32. package/env/index.mjs +742 -0
  33. package/exception/index.cjs +362 -0
  34. package/exception/index.d.ts +256 -0
  35. package/exception/index.mjs +338 -0
  36. package/fs/index.cjs +287 -0
  37. package/fs/index.d.ts +229 -0
  38. package/fs/index.mjs +258 -0
  39. package/http-status-codes/index.cjs +96 -0
  40. package/http-status-codes/index.d.ts +291 -0
  41. package/http-status-codes/index.mjs +94 -0
  42. package/id/index.cjs +62 -0
  43. package/id/index.d.ts +61 -0
  44. package/id/index.mjs +56 -0
  45. package/index.cjs +218 -0
  46. package/index.d.ts +51 -0
  47. package/index.mjs +51 -0
  48. package/logger/index.cjs +334 -0
  49. package/logger/index.d.ts +213 -0
  50. package/logger/index.mjs +313 -0
  51. package/middleware/index.cjs +177 -0
  52. package/middleware/index.d.ts +127 -0
  53. package/middleware/index.mjs +170 -0
  54. package/obj/index.cjs +305 -0
  55. package/obj/index.d.ts +160 -0
  56. package/obj/index.mjs +289 -0
  57. package/package.json +172 -20
  58. package/performance/index.cjs +231 -0
  59. package/performance/index.d.ts +162 -0
  60. package/performance/index.mjs +225 -0
  61. package/request/index.cjs +202 -0
  62. package/request/index.d.ts +265 -0
  63. package/request/index.mjs +194 -0
  64. package/response/index.cjs +234 -0
  65. package/response/index.d.ts +342 -0
  66. package/response/index.mjs +222 -0
  67. package/server/index.cjs +1631 -0
  68. package/server/index.d.ts +809 -0
  69. package/server/index.mjs +1622 -0
  70. package/stream/index.cjs +151 -0
  71. package/stream/index.d.ts +114 -0
  72. package/stream/index.mjs +144 -0
  73. package/string/index.cjs +109 -0
  74. package/string/index.d.ts +126 -0
  75. package/string/index.mjs +95 -0
  76. package/type/index.cjs +129 -0
  77. package/type/index.d.ts +131 -0
  78. package/type/index.mjs +119 -0
  79. package/types/index.cjs +34 -0
  80. package/types/index.d.ts +798 -0
  81. package/types/index.mjs +32 -0
  82. package/url/index.cjs +199 -0
  83. package/url/index.d.ts +166 -0
  84. package/url/index.mjs +187 -0
  85. package/validation/index.cjs +259 -0
  86. package/validation/index.d.ts +209 -0
  87. package/validation/index.mjs +231 -0
  88. package/build/index.cjs +0 -7694
  89. package/build/index.d.ts +0 -5792
  90. package/build/index.mjs +0 -7386
@@ -0,0 +1,151 @@
1
+ /*
2
+ * The MIT License
3
+ *
4
+ * Copyright (c) 2025 Catbee Technologies. https://catbee.in/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
+ 'use strict';
26
+
27
+ var stream = require('stream');
28
+
29
+ var __defProp = Object.defineProperty;
30
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
31
+ function bufferToStream(data) {
32
+ const readable = new stream.Readable();
33
+ readable.push(data);
34
+ readable.push(null);
35
+ return readable;
36
+ }
37
+ __name(bufferToStream, "bufferToStream");
38
+ async function streamToBuffer(stream) {
39
+ return new Promise((resolve, reject) => {
40
+ const chunks = [];
41
+ stream.on("data", (chunk) => chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)));
42
+ stream.on("end", () => resolve(Buffer.concat(chunks)));
43
+ stream.on("error", reject);
44
+ });
45
+ }
46
+ __name(streamToBuffer, "streamToBuffer");
47
+ async function streamToString(stream, encoding = "utf8") {
48
+ const buffer = await streamToBuffer(stream);
49
+ return buffer.toString(encoding);
50
+ }
51
+ __name(streamToString, "streamToString");
52
+ function createThrottleStream(bytesPerSecond) {
53
+ let bytesSent = 0;
54
+ let startTime = Date.now();
55
+ return new stream.Transform({
56
+ transform(chunk, _encoding, callback) {
57
+ const elapsedSeconds = (Date.now() - startTime) / 1e3;
58
+ const targetBytes = bytesPerSecond * elapsedSeconds;
59
+ const chunkSize = chunk.length;
60
+ if (bytesSent + chunkSize <= targetBytes) {
61
+ bytesSent += chunkSize;
62
+ callback(null, chunk);
63
+ return;
64
+ }
65
+ const delay = ((bytesSent + chunkSize) / bytesPerSecond - elapsedSeconds) * 1e3;
66
+ setTimeout(() => {
67
+ bytesSent += chunkSize;
68
+ callback(null, chunk);
69
+ }, delay);
70
+ }
71
+ });
72
+ }
73
+ __name(createThrottleStream, "createThrottleStream");
74
+ function createBatchStream(size, options = {}) {
75
+ const objectMode = options.objectMode !== false;
76
+ let batch = [];
77
+ let buffers = [];
78
+ let bufferSize = 0;
79
+ return new stream.Transform({
80
+ objectMode,
81
+ transform(chunk, _encoding, callback) {
82
+ if (objectMode) {
83
+ batch.push(chunk);
84
+ if (batch.length >= size) {
85
+ this.push(batch);
86
+ batch = [];
87
+ }
88
+ } else {
89
+ const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
90
+ buffers.push(buffer);
91
+ bufferSize += buffer.length;
92
+ let combined = Buffer.concat(buffers, bufferSize);
93
+ while (combined.length >= size) {
94
+ this.push(combined.slice(0, size));
95
+ combined = combined.slice(size);
96
+ }
97
+ buffers = combined.length > 0 ? [
98
+ combined
99
+ ] : [];
100
+ bufferSize = combined.length;
101
+ }
102
+ callback();
103
+ },
104
+ flush(callback) {
105
+ if (objectMode && batch.length > 0) {
106
+ this.push(batch);
107
+ } else if (!objectMode && buffers.length > 0 && bufferSize > 0) {
108
+ let combined = Buffer.concat(buffers, bufferSize);
109
+ while (combined.length >= size) {
110
+ this.push(combined.slice(0, size));
111
+ combined = combined.slice(size);
112
+ }
113
+ if (combined.length > 0) {
114
+ this.push(combined);
115
+ }
116
+ }
117
+ callback();
118
+ }
119
+ });
120
+ }
121
+ __name(createBatchStream, "createBatchStream");
122
+ function createLineStream(options = {}) {
123
+ const { encoding = "utf8", includeNewlines = false } = options;
124
+ let buffer = "";
125
+ return new stream.Transform({
126
+ objectMode: true,
127
+ transform(chunk, _encoding, callback) {
128
+ const str = buffer + (Buffer.isBuffer(chunk) ? chunk.toString(encoding) : chunk);
129
+ const lines = str.split(/\r?\n/);
130
+ buffer = lines.pop() || "";
131
+ for (const line of lines) {
132
+ this.push(includeNewlines ? line + "\n" : line);
133
+ }
134
+ callback();
135
+ },
136
+ flush(callback) {
137
+ if (buffer) {
138
+ this.push(buffer);
139
+ }
140
+ callback();
141
+ }
142
+ });
143
+ }
144
+ __name(createLineStream, "createLineStream");
145
+
146
+ exports.bufferToStream = bufferToStream;
147
+ exports.createBatchStream = createBatchStream;
148
+ exports.createLineStream = createLineStream;
149
+ exports.createThrottleStream = createThrottleStream;
150
+ exports.streamToBuffer = streamToBuffer;
151
+ exports.streamToString = streamToString;
@@ -0,0 +1,114 @@
1
+ /*
2
+ * The MIT License
3
+ *
4
+ * Copyright (c) 2025 Catbee Technologies. https://catbee.in/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
+ import { Readable, Transform } from 'node:stream';
26
+ import { BufferEncoding } from '@catbee/utils/crypto';
27
+
28
+ /**
29
+ * Convert a buffer or string to a readable stream.
30
+ *
31
+ * @param data - Buffer or string to convert
32
+ * @returns Readable stream containing the data
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * const stream = bufferToStream(Buffer.from('Hello world'));
37
+ * // or
38
+ * const stream = bufferToStream('Hello world');
39
+ * ```
40
+ */
41
+ declare function bufferToStream(data: Buffer | string): Readable;
42
+ /**
43
+ * Convert a readable stream to a buffer.
44
+ *
45
+ * @param stream - Readable stream to convert
46
+ * @returns Promise resolving to a buffer containing all stream data
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * const buffer = await streamToBuffer(fs.createReadStream('file.txt'));
51
+ * console.log(buffer.toString()); // Contents of file.txt
52
+ * ```
53
+ */
54
+ declare function streamToBuffer(stream: Readable): Promise<Buffer>;
55
+ /**
56
+ * Convert a readable stream to a string.
57
+ *
58
+ * @param stream - Readable stream to convert
59
+ * @param encoding - Character encoding (default: 'utf8')
60
+ * @returns Promise resolving to a string containing all stream data
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * const content = await streamToString(fs.createReadStream('file.txt'));
65
+ * console.log(content); // Contents of file.txt as string
66
+ * ```
67
+ */
68
+ declare function streamToString(stream: Readable, encoding?: BufferEncoding): Promise<string>;
69
+ /**
70
+ * Create a transform stream that limits the rate of data flow.
71
+ *
72
+ * @param bytesPerSecond - Maximum bytes per second
73
+ * @returns Transform stream that throttles data flow
74
+ */
75
+ declare function createThrottleStream(bytesPerSecond: number): Transform;
76
+ /**
77
+ * Create a transform stream that batches data into chunks of specified size.
78
+ *
79
+ * @param size - Size of each batch (items for object mode, bytes for binary mode)
80
+ * @param options - Stream options
81
+ * @returns Transform stream that batches data
82
+ *
83
+ * @example
84
+ * ```typescript
85
+ * // Batch lines from a file into arrays of 100 lines each
86
+ * createReadStream('large-file.txt')
87
+ * .pipe(createLineStream())
88
+ * .pipe(createBatchStream(100))
89
+ * .on('data', batch => console.log(`Processing batch of ${batch.length} lines`));
90
+ * ```
91
+ */
92
+ declare function createBatchStream(size: number, options?: {
93
+ objectMode?: boolean;
94
+ }): Transform;
95
+ /**
96
+ * Create a transform stream that splits text data by newlines.
97
+ *
98
+ * @param options - Options for the line stream
99
+ * @returns Transform stream that emits lines
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * // Process a file line by line
104
+ * createReadStream('file.txt')
105
+ * .pipe(createLineStream())
106
+ * .on('data', line => console.log(`Line: ${line}`));
107
+ * ```
108
+ */
109
+ declare function createLineStream(options?: {
110
+ encoding?: BufferEncoding;
111
+ includeNewlines?: boolean;
112
+ }): Transform;
113
+
114
+ export { bufferToStream, createBatchStream, createLineStream, createThrottleStream, streamToBuffer, streamToString };
@@ -0,0 +1,144 @@
1
+ /*
2
+ * The MIT License
3
+ *
4
+ * Copyright (c) 2025 Catbee Technologies. https://catbee.in/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
+ import { Readable, Transform } from 'stream';
26
+
27
+ var __defProp = Object.defineProperty;
28
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
29
+ function bufferToStream(data) {
30
+ const readable = new Readable();
31
+ readable.push(data);
32
+ readable.push(null);
33
+ return readable;
34
+ }
35
+ __name(bufferToStream, "bufferToStream");
36
+ async function streamToBuffer(stream) {
37
+ return new Promise((resolve, reject) => {
38
+ const chunks = [];
39
+ stream.on("data", (chunk) => chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)));
40
+ stream.on("end", () => resolve(Buffer.concat(chunks)));
41
+ stream.on("error", reject);
42
+ });
43
+ }
44
+ __name(streamToBuffer, "streamToBuffer");
45
+ async function streamToString(stream, encoding = "utf8") {
46
+ const buffer = await streamToBuffer(stream);
47
+ return buffer.toString(encoding);
48
+ }
49
+ __name(streamToString, "streamToString");
50
+ function createThrottleStream(bytesPerSecond) {
51
+ let bytesSent = 0;
52
+ let startTime = Date.now();
53
+ return new Transform({
54
+ transform(chunk, _encoding, callback) {
55
+ const elapsedSeconds = (Date.now() - startTime) / 1e3;
56
+ const targetBytes = bytesPerSecond * elapsedSeconds;
57
+ const chunkSize = chunk.length;
58
+ if (bytesSent + chunkSize <= targetBytes) {
59
+ bytesSent += chunkSize;
60
+ callback(null, chunk);
61
+ return;
62
+ }
63
+ const delay = ((bytesSent + chunkSize) / bytesPerSecond - elapsedSeconds) * 1e3;
64
+ setTimeout(() => {
65
+ bytesSent += chunkSize;
66
+ callback(null, chunk);
67
+ }, delay);
68
+ }
69
+ });
70
+ }
71
+ __name(createThrottleStream, "createThrottleStream");
72
+ function createBatchStream(size, options = {}) {
73
+ const objectMode = options.objectMode !== false;
74
+ let batch = [];
75
+ let buffers = [];
76
+ let bufferSize = 0;
77
+ return new Transform({
78
+ objectMode,
79
+ transform(chunk, _encoding, callback) {
80
+ if (objectMode) {
81
+ batch.push(chunk);
82
+ if (batch.length >= size) {
83
+ this.push(batch);
84
+ batch = [];
85
+ }
86
+ } else {
87
+ const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
88
+ buffers.push(buffer);
89
+ bufferSize += buffer.length;
90
+ let combined = Buffer.concat(buffers, bufferSize);
91
+ while (combined.length >= size) {
92
+ this.push(combined.slice(0, size));
93
+ combined = combined.slice(size);
94
+ }
95
+ buffers = combined.length > 0 ? [
96
+ combined
97
+ ] : [];
98
+ bufferSize = combined.length;
99
+ }
100
+ callback();
101
+ },
102
+ flush(callback) {
103
+ if (objectMode && batch.length > 0) {
104
+ this.push(batch);
105
+ } else if (!objectMode && buffers.length > 0 && bufferSize > 0) {
106
+ let combined = Buffer.concat(buffers, bufferSize);
107
+ while (combined.length >= size) {
108
+ this.push(combined.slice(0, size));
109
+ combined = combined.slice(size);
110
+ }
111
+ if (combined.length > 0) {
112
+ this.push(combined);
113
+ }
114
+ }
115
+ callback();
116
+ }
117
+ });
118
+ }
119
+ __name(createBatchStream, "createBatchStream");
120
+ function createLineStream(options = {}) {
121
+ const { encoding = "utf8", includeNewlines = false } = options;
122
+ let buffer = "";
123
+ return new Transform({
124
+ objectMode: true,
125
+ transform(chunk, _encoding, callback) {
126
+ const str = buffer + (Buffer.isBuffer(chunk) ? chunk.toString(encoding) : chunk);
127
+ const lines = str.split(/\r?\n/);
128
+ buffer = lines.pop() || "";
129
+ for (const line of lines) {
130
+ this.push(includeNewlines ? line + "\n" : line);
131
+ }
132
+ callback();
133
+ },
134
+ flush(callback) {
135
+ if (buffer) {
136
+ this.push(buffer);
137
+ }
138
+ callback();
139
+ }
140
+ });
141
+ }
142
+ __name(createLineStream, "createLineStream");
143
+
144
+ export { bufferToStream, createBatchStream, createLineStream, createThrottleStream, streamToBuffer, streamToString };
@@ -0,0 +1,109 @@
1
+ /*
2
+ * The MIT License
3
+ *
4
+ * Copyright (c) 2025 Catbee Technologies. https://catbee.in/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
+ 'use strict';
26
+
27
+ var __defProp = Object.defineProperty;
28
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
29
+
30
+ // src/string/string.utils.ts
31
+ function capitalize(str) {
32
+ if (typeof str !== "string") throw new TypeError("Expected a string");
33
+ return str.length === 0 ? "" : str.charAt(0).toUpperCase() + str.slice(1);
34
+ }
35
+ __name(capitalize, "capitalize");
36
+ function toKebabCase(str) {
37
+ if (typeof str !== "string") throw new TypeError("Expected a string");
38
+ return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/\s+/g, "-").replace(/_+/g, "-").toLowerCase();
39
+ }
40
+ __name(toKebabCase, "toKebabCase");
41
+ function toCamelCase(str) {
42
+ if (typeof str !== "string") throw new TypeError("Expected a string");
43
+ return str.replace(/[-_](.)/g, (_, c) => c.toUpperCase());
44
+ }
45
+ __name(toCamelCase, "toCamelCase");
46
+ function slugify(str) {
47
+ return str.toLowerCase().replace(/[^\w\s-]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-").replace(/^-+|-+$/g, "");
48
+ }
49
+ __name(slugify, "slugify");
50
+ function truncate(str, len) {
51
+ return str.length > len ? str.slice(0, len) + "..." : str;
52
+ }
53
+ __name(truncate, "truncate");
54
+ function toPascalCase(str) {
55
+ return capitalize(toCamelCase(str));
56
+ }
57
+ __name(toPascalCase, "toPascalCase");
58
+ function toSnakeCase(str) {
59
+ return str.trim().replace(/([a-z])([A-Z])/g, "$1_$2").replace(/\s+/g, "_").replace(/-+/g, "_").toLowerCase();
60
+ }
61
+ __name(toSnakeCase, "toSnakeCase");
62
+ function mask(str, visibleStart = 0, visibleEnd = 0, maskChar = "*") {
63
+ if (!str || str.length === 0) return "";
64
+ if (visibleStart >= str.length) return str;
65
+ const start = str.slice(0, visibleStart);
66
+ const end = visibleEnd > 0 ? str.slice(-visibleEnd) : "";
67
+ const masked = maskChar.repeat(Math.max(0, str.length - visibleStart - visibleEnd));
68
+ return start + masked + end;
69
+ }
70
+ __name(mask, "mask");
71
+ function stripHtml(str) {
72
+ return str.replace(/<[^>]*>/g, "");
73
+ }
74
+ __name(stripHtml, "stripHtml");
75
+ function equalsIgnoreCase(a, b) {
76
+ return a.toLowerCase() === b.toLowerCase();
77
+ }
78
+ __name(equalsIgnoreCase, "equalsIgnoreCase");
79
+ function reverse(str) {
80
+ return str.split("").reverse().join("");
81
+ }
82
+ __name(reverse, "reverse");
83
+ function countOccurrences(str, substring, caseSensitive = true) {
84
+ if (!caseSensitive) {
85
+ str = str.toLowerCase();
86
+ substring = substring.toLowerCase();
87
+ }
88
+ return str.split(substring).length - 1;
89
+ }
90
+ __name(countOccurrences, "countOccurrences");
91
+ function toTitleCase(str) {
92
+ if (typeof str !== "string") throw new TypeError("Expected a string");
93
+ return str.split(/(\s+)/).map((part) => part.trim().length === 0 ? part : part.charAt(0).toUpperCase() + part.slice(1).toLowerCase()).join("");
94
+ }
95
+ __name(toTitleCase, "toTitleCase");
96
+
97
+ exports.capitalize = capitalize;
98
+ exports.countOccurrences = countOccurrences;
99
+ exports.equalsIgnoreCase = equalsIgnoreCase;
100
+ exports.mask = mask;
101
+ exports.reverse = reverse;
102
+ exports.slugify = slugify;
103
+ exports.stripHtml = stripHtml;
104
+ exports.toCamelCase = toCamelCase;
105
+ exports.toKebabCase = toKebabCase;
106
+ exports.toPascalCase = toPascalCase;
107
+ exports.toSnakeCase = toSnakeCase;
108
+ exports.toTitleCase = toTitleCase;
109
+ exports.truncate = truncate;
@@ -0,0 +1,126 @@
1
+ /*
2
+ * The MIT License
3
+ *
4
+ * Copyright (c) 2025 Catbee Technologies. https://catbee.in/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
+ /**
26
+ * Capitalizes the first character of a string.
27
+ *
28
+ * @param {string} str - The input string.
29
+ * @returns {string} The string with the first character in uppercase.
30
+ */
31
+ declare function capitalize(str: string): string;
32
+ /**
33
+ * Converts a string to kebab-case (e.g., "FooBar test" -> "foo-bar-test").
34
+ *
35
+ * @param {string} str - The input string.
36
+ * @returns {string} The kebab-cased string.
37
+ */
38
+ declare function toKebabCase(str: string): string;
39
+ /**
40
+ * Converts a kebab-case or snake_case string to camelCase.
41
+ *
42
+ * @param {string} str - The input string.
43
+ * @returns {string} The camelCased string.
44
+ */
45
+ declare function toCamelCase(str: string): string;
46
+ /**
47
+ * Converts a string to a URL-friendly slug (lowercase, dashes, alphanumeric).
48
+ *
49
+ * @param {string} str - The input string.
50
+ * @returns {string} The slugified string.
51
+ */
52
+ declare function slugify(str: string): string;
53
+ /**
54
+ * Truncates a string to a specific length, appending '...' if truncated.
55
+ *
56
+ * @param {string} str - The input string.
57
+ * @param {number} len - The maximum length.
58
+ * @returns {string} The truncated string.
59
+ */
60
+ declare function truncate(str: string, len: number): string;
61
+ /**
62
+ * Converts a string to PascalCase (e.g., "foo-bar" -> "FooBar").
63
+ *
64
+ * @param {string} str - The input string.
65
+ * @returns {string} The PascalCased string.
66
+ */
67
+ declare function toPascalCase(str: string): string;
68
+ /**
69
+ * Converts a string to snake_case (e.g., "FooBar test" -> "foo_bar_test").
70
+ *
71
+ * @param {string} str - The input string.
72
+ * @returns {string} The snake_cased string.
73
+ */
74
+ declare function toSnakeCase(str: string): string;
75
+ /**
76
+ * Masks a string by replacing characters with a mask character.
77
+ * Useful for hiding sensitive information like credit cards or passwords.
78
+ *
79
+ * @param {string} str - The string to mask.
80
+ * @param {number} [visibleStart=0] - Number of characters to show at start.
81
+ * @param {number} [visibleEnd=0] - Number of characters to show at end.
82
+ * @param {string} [maskChar="*"] - Character to use for masking.
83
+ * @returns {string} The masked string.
84
+ */
85
+ declare function mask(str: string, visibleStart?: number, visibleEnd?: number, maskChar?: string): string;
86
+ /**
87
+ * Removes all HTML tags from a string.
88
+ *
89
+ * @param {string} str - The HTML string to process.
90
+ * @returns {string} The string with HTML tags removed.
91
+ */
92
+ declare function stripHtml(str: string): string;
93
+ /**
94
+ * Performs case-insensitive string comparison.
95
+ *
96
+ * @param {string} a - First string.
97
+ * @param {string} b - Second string.
98
+ * @returns {boolean} True if the strings are equal ignoring case.
99
+ */
100
+ declare function equalsIgnoreCase(a: string, b: string): boolean;
101
+ /**
102
+ * Reverses a string.
103
+ *
104
+ * @param {string} str - The string to reverse.
105
+ * @returns {string} The reversed string.
106
+ */
107
+ declare function reverse(str: string): string;
108
+ /**
109
+ * Counts occurrences of a substring within a string.
110
+ *
111
+ * @param {string} str - The source string.
112
+ * @param {string} substring - The substring to count.
113
+ * @param {boolean} [caseSensitive=true] - Whether to perform case-sensitive counting.
114
+ * @returns {number} Number of occurrences.
115
+ */
116
+ declare function countOccurrences(str: string, substring: string, caseSensitive?: boolean): number;
117
+ /**
118
+ * Convert a string to Title Case (each word capitalized).
119
+ * Preserves existing spacing and punctuation between words.
120
+ *
121
+ * @param str - Input string
122
+ * @returns Title-cased string
123
+ */
124
+ declare function toTitleCase(str: string): string;
125
+
126
+ export { capitalize, countOccurrences, equalsIgnoreCase, mask, reverse, slugify, stripHtml, toCamelCase, toKebabCase, toPascalCase, toSnakeCase, toTitleCase, truncate };