@catbee/utils 1.1.0 → 2.0.0-next.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 (121) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +27 -27
  3. package/array/array.utils.d.ts +191 -0
  4. package/array/index.cjs +246 -0
  5. package/array/index.d.ts +25 -0
  6. package/array/index.mjs +228 -0
  7. package/async/async.utils.d.ts +296 -0
  8. package/async/index.cjs +428 -0
  9. package/async/index.d.ts +25 -0
  10. package/async/index.mjs +407 -0
  11. package/cache/cache.utils.d.ts +176 -0
  12. package/cache/index.cjs +292 -0
  13. package/cache/index.d.ts +25 -0
  14. package/cache/index.mjs +290 -0
  15. package/config/config.d.ts +57 -0
  16. package/config/index.cjs +136 -0
  17. package/config/index.d.ts +26 -0
  18. package/config/index.mjs +131 -0
  19. package/context-store/context-store.utils.d.ts +212 -0
  20. package/context-store/index.cjs +267 -0
  21. package/context-store/index.d.ts +25 -0
  22. package/context-store/index.mjs +261 -0
  23. package/crypto/crypto.utils.d.ts +183 -0
  24. package/crypto/index.cjs +182 -0
  25. package/crypto/index.d.ts +25 -0
  26. package/crypto/index.mjs +166 -0
  27. package/date/date.utils.d.ts +190 -0
  28. package/date/index.cjs +295 -0
  29. package/date/index.d.ts +25 -0
  30. package/date/index.mjs +283 -0
  31. package/decorators/decorators.utils.d.ts +705 -0
  32. package/decorators/index.cjs +913 -0
  33. package/decorators/index.d.ts +25 -0
  34. package/decorators/index.mjs +872 -0
  35. package/dir/dir.utils.d.ts +216 -0
  36. package/dir/index.cjs +416 -0
  37. package/dir/index.d.ts +25 -0
  38. package/dir/index.mjs +389 -0
  39. package/env/env.utils.d.ts +400 -0
  40. package/env/index.cjs +761 -0
  41. package/env/index.d.ts +25 -0
  42. package/env/index.mjs +758 -0
  43. package/exception/exception.utils.d.ts +253 -0
  44. package/exception/index.cjs +362 -0
  45. package/exception/index.d.ts +25 -0
  46. package/exception/index.mjs +338 -0
  47. package/fs/fs.utils.d.ts +196 -0
  48. package/fs/index.cjs +253 -0
  49. package/fs/index.d.ts +25 -0
  50. package/fs/index.mjs +228 -0
  51. package/http-status-codes/http-status-codes.d.ts +289 -0
  52. package/http-status-codes/index.cjs +96 -0
  53. package/http-status-codes/index.d.ts +25 -0
  54. package/http-status-codes/index.mjs +94 -0
  55. package/id/id.utils.d.ts +59 -0
  56. package/id/index.cjs +62 -0
  57. package/id/index.d.ts +25 -0
  58. package/id/index.mjs +56 -0
  59. package/index.cjs +218 -0
  60. package/index.d.ts +51 -0
  61. package/index.mjs +51 -0
  62. package/logger/index.cjs +334 -0
  63. package/logger/index.d.ts +25 -0
  64. package/logger/index.mjs +313 -0
  65. package/logger/logger.utils.d.ts +210 -0
  66. package/middleware/index.cjs +177 -0
  67. package/middleware/index.d.ts +25 -0
  68. package/middleware/index.mjs +170 -0
  69. package/middleware/middleware.utils.d.ts +123 -0
  70. package/obj/index.cjs +317 -0
  71. package/obj/index.d.ts +25 -0
  72. package/obj/index.mjs +301 -0
  73. package/obj/obj.utils.d.ts +156 -0
  74. package/package.json +171 -19
  75. package/performance/index.cjs +231 -0
  76. package/performance/index.d.ts +25 -0
  77. package/performance/index.mjs +225 -0
  78. package/performance/performance.utils.d.ts +159 -0
  79. package/request/index.cjs +202 -0
  80. package/request/index.d.ts +26 -0
  81. package/request/index.mjs +194 -0
  82. package/request/request.utils.d.ts +109 -0
  83. package/response/index.cjs +234 -0
  84. package/response/index.d.ts +26 -0
  85. package/response/index.mjs +222 -0
  86. package/response/response.utils.d.ts +186 -0
  87. package/server/index.cjs +1627 -0
  88. package/server/index.d.ts +28 -0
  89. package/server/index.mjs +1617 -0
  90. package/server/server.builder.d.ts +531 -0
  91. package/server/server.d.ts +303 -0
  92. package/stream/index.cjs +151 -0
  93. package/stream/index.d.ts +25 -0
  94. package/stream/index.mjs +144 -0
  95. package/stream/stream.utils.d.ts +111 -0
  96. package/string/index.cjs +109 -0
  97. package/string/index.d.ts +25 -0
  98. package/string/index.mjs +95 -0
  99. package/string/string.utils.d.ts +124 -0
  100. package/type/index.cjs +129 -0
  101. package/type/index.d.ts +25 -0
  102. package/type/index.mjs +119 -0
  103. package/type/type.utils.d.ts +129 -0
  104. package/types/api-response.d.ts +175 -0
  105. package/types/common.d.ts +148 -0
  106. package/types/config.d.ts +88 -0
  107. package/types/index.cjs +34 -0
  108. package/types/index.d.ts +28 -0
  109. package/types/index.mjs +32 -0
  110. package/types/server.d.ts +291 -0
  111. package/url/index.cjs +201 -0
  112. package/url/index.d.ts +25 -0
  113. package/url/index.mjs +189 -0
  114. package/url/url.utils.d.ts +164 -0
  115. package/validate/index.cjs +212 -0
  116. package/validate/index.d.ts +25 -0
  117. package/validate/index.mjs +188 -0
  118. package/validate/validate.utils.d.ts +200 -0
  119. package/build/index.cjs +0 -7694
  120. package/build/index.d.ts +0 -5792
  121. package/build/index.mjs +0 -7386
@@ -0,0 +1,111 @@
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
+ import type { BufferEncoding } from '@catbee/utils/crypto';
27
+ /**
28
+ * Convert a buffer or string to a readable stream.
29
+ *
30
+ * @param data - Buffer or string to convert
31
+ * @returns Readable stream containing the data
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * const stream = bufferToStream(Buffer.from('Hello world'));
36
+ * // or
37
+ * const stream = bufferToStream('Hello world');
38
+ * ```
39
+ */
40
+ export declare function bufferToStream(data: Buffer | string): Readable;
41
+ /**
42
+ * Convert a readable stream to a buffer.
43
+ *
44
+ * @param stream - Readable stream to convert
45
+ * @returns Promise resolving to a buffer containing all stream data
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * const buffer = await streamToBuffer(fs.createReadStream('file.txt'));
50
+ * console.log(buffer.toString()); // Contents of file.txt
51
+ * ```
52
+ */
53
+ export declare function streamToBuffer(stream: Readable): Promise<Buffer>;
54
+ /**
55
+ * Convert a readable stream to a string.
56
+ *
57
+ * @param stream - Readable stream to convert
58
+ * @param encoding - Character encoding (default: 'utf8')
59
+ * @returns Promise resolving to a string containing all stream data
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * const content = await streamToString(fs.createReadStream('file.txt'));
64
+ * console.log(content); // Contents of file.txt as string
65
+ * ```
66
+ */
67
+ export declare function streamToString(stream: Readable, encoding?: BufferEncoding): Promise<string>;
68
+ /**
69
+ * Create a transform stream that limits the rate of data flow.
70
+ *
71
+ * @param bytesPerSecond - Maximum bytes per second
72
+ * @returns Transform stream that throttles data flow
73
+ */
74
+ export declare function createThrottleStream(bytesPerSecond: number): Transform;
75
+ /**
76
+ * Create a transform stream that batches data into chunks of specified size.
77
+ *
78
+ * @param size - Size of each batch (items for object mode, bytes for binary mode)
79
+ * @param options - Stream options
80
+ * @returns Transform stream that batches data
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * // Batch lines from a file into arrays of 100 lines each
85
+ * createReadStream('large-file.txt')
86
+ * .pipe(createLineStream())
87
+ * .pipe(createBatchStream(100))
88
+ * .on('data', batch => console.log(`Processing batch of ${batch.length} lines`));
89
+ * ```
90
+ */
91
+ export declare function createBatchStream(size: number, options?: {
92
+ objectMode?: boolean;
93
+ }): Transform;
94
+ /**
95
+ * Create a transform stream that splits text data by newlines.
96
+ *
97
+ * @param options - Options for the line stream
98
+ * @returns Transform stream that emits lines
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * // Process a file line by line
103
+ * createReadStream('file.txt')
104
+ * .pipe(createLineStream())
105
+ * .on('data', line => console.log(`Line: ${line}`));
106
+ * ```
107
+ */
108
+ export declare function createLineStream(options?: {
109
+ encoding?: BufferEncoding;
110
+ includeNewlines?: boolean;
111
+ }): Transform;
@@ -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,25 @@
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
+ export * from './string.utils';
@@ -0,0 +1,95 @@
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
+ var __defProp = Object.defineProperty;
26
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
27
+
28
+ // src/string/string.utils.ts
29
+ function capitalize(str) {
30
+ if (typeof str !== "string") throw new TypeError("Expected a string");
31
+ return str.length === 0 ? "" : str.charAt(0).toUpperCase() + str.slice(1);
32
+ }
33
+ __name(capitalize, "capitalize");
34
+ function toKebabCase(str) {
35
+ if (typeof str !== "string") throw new TypeError("Expected a string");
36
+ return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/\s+/g, "-").replace(/_+/g, "-").toLowerCase();
37
+ }
38
+ __name(toKebabCase, "toKebabCase");
39
+ function toCamelCase(str) {
40
+ if (typeof str !== "string") throw new TypeError("Expected a string");
41
+ return str.replace(/[-_](.)/g, (_, c) => c.toUpperCase());
42
+ }
43
+ __name(toCamelCase, "toCamelCase");
44
+ function slugify(str) {
45
+ return str.toLowerCase().replace(/[^\w\s-]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-").replace(/^-+|-+$/g, "");
46
+ }
47
+ __name(slugify, "slugify");
48
+ function truncate(str, len) {
49
+ return str.length > len ? str.slice(0, len) + "..." : str;
50
+ }
51
+ __name(truncate, "truncate");
52
+ function toPascalCase(str) {
53
+ return capitalize(toCamelCase(str));
54
+ }
55
+ __name(toPascalCase, "toPascalCase");
56
+ function toSnakeCase(str) {
57
+ return str.trim().replace(/([a-z])([A-Z])/g, "$1_$2").replace(/\s+/g, "_").replace(/-+/g, "_").toLowerCase();
58
+ }
59
+ __name(toSnakeCase, "toSnakeCase");
60
+ function mask(str, visibleStart = 0, visibleEnd = 0, maskChar = "*") {
61
+ if (!str || str.length === 0) return "";
62
+ if (visibleStart >= str.length) return str;
63
+ const start = str.slice(0, visibleStart);
64
+ const end = visibleEnd > 0 ? str.slice(-visibleEnd) : "";
65
+ const masked = maskChar.repeat(Math.max(0, str.length - visibleStart - visibleEnd));
66
+ return start + masked + end;
67
+ }
68
+ __name(mask, "mask");
69
+ function stripHtml(str) {
70
+ return str.replace(/<[^>]*>/g, "");
71
+ }
72
+ __name(stripHtml, "stripHtml");
73
+ function equalsIgnoreCase(a, b) {
74
+ return a.toLowerCase() === b.toLowerCase();
75
+ }
76
+ __name(equalsIgnoreCase, "equalsIgnoreCase");
77
+ function reverse(str) {
78
+ return str.split("").reverse().join("");
79
+ }
80
+ __name(reverse, "reverse");
81
+ function countOccurrences(str, substring, caseSensitive = true) {
82
+ if (!caseSensitive) {
83
+ str = str.toLowerCase();
84
+ substring = substring.toLowerCase();
85
+ }
86
+ return str.split(substring).length - 1;
87
+ }
88
+ __name(countOccurrences, "countOccurrences");
89
+ function toTitleCase(str) {
90
+ if (typeof str !== "string") throw new TypeError("Expected a string");
91
+ return str.split(/(\s+)/).map((part) => part.trim().length === 0 ? part : part.charAt(0).toUpperCase() + part.slice(1).toLowerCase()).join("");
92
+ }
93
+ __name(toTitleCase, "toTitleCase");
94
+
95
+ export { capitalize, countOccurrences, equalsIgnoreCase, mask, reverse, slugify, stripHtml, toCamelCase, toKebabCase, toPascalCase, toSnakeCase, toTitleCase, truncate };
@@ -0,0 +1,124 @@
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
+ export 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
+ export 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
+ export 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
+ export 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
+ export 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
+ export 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
+ export 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
+ export 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
+ export 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
+ export 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
+ export 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
+ export 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
+ export declare function toTitleCase(str: string): string;
package/type/index.cjs ADDED
@@ -0,0 +1,129 @@
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/type/type.utils.ts
31
+ function isPrimitiveType(value, type) {
32
+ if (type === "array") {
33
+ return Array.isArray(value);
34
+ }
35
+ if (type === "null") {
36
+ return value === null;
37
+ }
38
+ if (type === "undefined") {
39
+ return value === void 0;
40
+ }
41
+ if (type === "object") {
42
+ return typeof value === "object" && value !== null && !Array.isArray(value);
43
+ }
44
+ return typeof value === type;
45
+ }
46
+ __name(isPrimitiveType, "isPrimitiveType");
47
+ function getTypeOf(value) {
48
+ if (value === null) return "null";
49
+ if (value === void 0) return "undefined";
50
+ if (Array.isArray(value)) return "array";
51
+ return typeof value;
52
+ }
53
+ __name(getTypeOf, "getTypeOf");
54
+ function isArrayOf(value, itemTypeGuard) {
55
+ if (!Array.isArray(value)) return false;
56
+ return value.every((item) => itemTypeGuard(item));
57
+ }
58
+ __name(isArrayOf, "isArrayOf");
59
+ function toStr(value, defaultValue = "") {
60
+ if (value === null || value === void 0) return defaultValue;
61
+ try {
62
+ if (typeof value === "object") {
63
+ return JSON.stringify(value);
64
+ }
65
+ return String(value);
66
+ } catch {
67
+ return defaultValue;
68
+ }
69
+ }
70
+ __name(toStr, "toStr");
71
+ function toNum(value, defaultValue = 0) {
72
+ if (value === null || value === void 0) return defaultValue;
73
+ if (typeof value === "number") return value;
74
+ try {
75
+ const num = Number(value);
76
+ return isNaN(num) ? defaultValue : num;
77
+ } catch {
78
+ return defaultValue;
79
+ }
80
+ }
81
+ __name(toNum, "toNum");
82
+ function toBool(value, defaultValue = false) {
83
+ if (value === null || value === void 0) return defaultValue;
84
+ if (typeof value === "boolean") return value;
85
+ if (typeof value === "string") {
86
+ const lowercased = value.toLowerCase();
87
+ if (lowercased === "true" || lowercased === "yes" || lowercased === "y" || lowercased === "1") {
88
+ return true;
89
+ }
90
+ if (lowercased === "false" || lowercased === "no" || lowercased === "n" || lowercased === "0") {
91
+ return false;
92
+ }
93
+ }
94
+ if (typeof value === "number") {
95
+ return value !== 0;
96
+ }
97
+ return defaultValue;
98
+ }
99
+ __name(toBool, "toBool");
100
+ function ensureType(value, expectedType, defaultValue) {
101
+ if (getTypeOf(value) === expectedType) {
102
+ return value;
103
+ }
104
+ return defaultValue;
105
+ }
106
+ __name(ensureType, "ensureType");
107
+ function isDefined(value) {
108
+ return value !== null && value !== void 0;
109
+ }
110
+ __name(isDefined, "isDefined");
111
+ function isEmpty(value) {
112
+ if (value == null) return true;
113
+ if (typeof value === "string") return value.trim().length === 0;
114
+ if (Array.isArray(value)) return value.length === 0;
115
+ if (value instanceof Map || value instanceof Set) return value.size === 0;
116
+ if (typeof value === "object") return Object.keys(value).length === 0;
117
+ return false;
118
+ }
119
+ __name(isEmpty, "isEmpty");
120
+
121
+ exports.ensureType = ensureType;
122
+ exports.getTypeOf = getTypeOf;
123
+ exports.isArrayOf = isArrayOf;
124
+ exports.isDefined = isDefined;
125
+ exports.isEmpty = isEmpty;
126
+ exports.isPrimitiveType = isPrimitiveType;
127
+ exports.toBool = toBool;
128
+ exports.toNum = toNum;
129
+ exports.toStr = toStr;
@@ -0,0 +1,25 @@
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
+ export * from './type.utils';