@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
package/fs/index.d.ts ADDED
@@ -0,0 +1,229 @@
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 { BufferEncoding } from '@catbee/utils/crypto';
26
+ import fs from 'node:fs';
27
+
28
+ /**
29
+ * Checks whether a file or directory exists at the given path.
30
+ *
31
+ * @param {string} path - The file or directory path to check.
32
+ * @returns {Promise<boolean>} Resolves to `true` if the path exists, `false` otherwise.
33
+ */
34
+ declare function fileExists(path: string): Promise<boolean>;
35
+ /**
36
+ * Reads and parses a JSON file from the specified path.
37
+ *
38
+ * @typeParam T - The expected type of the parsed JSON object.
39
+ * @param {string} path - The path to the JSON file.
40
+ * @returns {Promise<T | null>} The parsed object, or `null` if reading or parsing fails.
41
+ */
42
+ declare function readJsonFile<T = any>(path: string): Promise<T | null>;
43
+ /**
44
+ * Read and parse JSON file or return a provided default value on error.
45
+ *
46
+ * @typeParam T
47
+ * @param {string} path - Path to JSON file
48
+ * @param {T} defaultValue - Default value to return when read/parse fails
49
+ * @returns {Promise<T>} Parsed JSON or defaultValue
50
+ */
51
+ declare function readJsonOrDefault<T = any>(path: string, defaultValue: T): Promise<T>;
52
+ /**
53
+ * Writes a JavaScript object to a file as formatted JSON.
54
+ *
55
+ * @param {string} path - The destination file path.
56
+ * @param {any} data - The object to serialize and write.
57
+ * @param {number} [space=2] - Number of spaces for JSON formatting.
58
+ * @returns {Promise<void>} Resolves when writing is complete.
59
+ */
60
+ declare function writeJsonFile(path: string, data: any, space?: number): Promise<void>;
61
+ /**
62
+ * Deletes a file if it exists.
63
+ *
64
+ * @param {string} path - The file path to delete.
65
+ * @returns {Promise<boolean>} Resolves to `true` if the file was deleted or didn't exist, `false` if deletion failed.
66
+ */
67
+ declare function deleteFileIfExists(path: string): Promise<boolean>;
68
+ /**
69
+ * Reads a file from the specified path.
70
+ *
71
+ * @param {string} path - The path to the file.
72
+ * @param {BufferEncoding} [encoding="utf-8"] - The encoding to use.
73
+ * @returns {Promise<string | null>} The file contents, or `null` if reading fails.
74
+ */
75
+ declare function readFile(path: string, encoding?: BufferEncoding): Promise<string>;
76
+ /**
77
+ * Reads a file from the specified path synchronously.
78
+ *
79
+ * @param {string} path - The path to the file.
80
+ * @param {BufferEncoding} [encoding="utf-8"] - The encoding to use.
81
+ * @returns {string | null} The file contents, or `null` if reading fails.
82
+ */
83
+ declare function readFileSync(path: string, encoding?: BufferEncoding): string;
84
+ /**
85
+ * Safely reads a file and returns its content along with any error encountered.
86
+ *
87
+ * @param {string} path - The path to the file.
88
+ * @param {BufferEncoding} [encoding="utf-8"] - The encoding to use.
89
+ * @returns {Promise<{ data: string | null; error: Error | null }>} Object with data and error properties.
90
+ */
91
+ declare function safeReadFile(path: string, encoding?: BufferEncoding): Promise<{
92
+ data: string | null;
93
+ error: Error | null;
94
+ }>;
95
+ /**
96
+ * Safely reads a file synchronously and returns its content along with any error encountered.
97
+ *
98
+ * @param {string} path - The path to the file.
99
+ * @param {BufferEncoding} [encoding="utf-8"] - The encoding to use.
100
+ * @returns {{ data: string | null; error: Error | null }} Object with data and error properties.
101
+ */
102
+ declare function safeReadFileSync(path: string, encoding?: BufferEncoding): {
103
+ data: string | null;
104
+ error: Error | null;
105
+ };
106
+ /**
107
+ * Writes content to a file.
108
+ *
109
+ * @param {string} path - The destination file path.
110
+ * @param {string} content - The text content to write.
111
+ * @param {BufferEncoding} [encoding="utf-8"] - The encoding to use.
112
+ * @returns {Promise<boolean>} Resolves to `true` if successful, `false` otherwise.
113
+ */
114
+ declare function writeFile(path: string, content: string, encoding?: BufferEncoding): Promise<boolean>;
115
+ /**
116
+ * Appends text content to a file.
117
+ *
118
+ * @param {string} path - The file path to append to.
119
+ * @param {string} content - The text content to append.
120
+ * @param {BufferEncoding} [encoding="utf-8"] - The encoding to use.
121
+ * @returns {Promise<boolean>} Resolves to `true` if successful, `false` otherwise.
122
+ */
123
+ declare function appendFile(path: string, content: string, encoding?: BufferEncoding): Promise<boolean>;
124
+ /**
125
+ * Copies a file from source to destination.
126
+ *
127
+ * @param {string} source - Source file path.
128
+ * @param {string} destination - Destination file path.
129
+ * @param {boolean} [overwrite=false] - Whether to overwrite if destination exists.
130
+ * @returns {Promise<boolean>} Resolves to `true` if successful, `false` otherwise.
131
+ */
132
+ declare function copyFile(source: string, destination: string, overwrite?: boolean): Promise<boolean>;
133
+ /**
134
+ * Renames/moves a file.
135
+ *
136
+ * @param {string} oldPath - Current file path.
137
+ * @param {string} newPath - New file path.
138
+ * @returns {Promise<boolean>} Resolves to `true` if successful, `false` otherwise.
139
+ */
140
+ declare function moveFile(oldPath: string, newPath: string): Promise<boolean>;
141
+ /**
142
+ * Gets file stats if the file exists.
143
+ *
144
+ * @param {string} path - Path to the file.
145
+ * @returns {Promise<fsp.Stats | null>} File stats object or null if file doesn't exist.
146
+ */
147
+ declare function getFileStats(path: string): Promise<fs.Stats | null>;
148
+ /**
149
+ * Creates a temporary file with optional content.
150
+ *
151
+ * @param {object} [options] - Options for creating the temp file.
152
+ * @param {string} [options.prefix="tmp-"] - Filename prefix.
153
+ * @param {string} [options.extension=""] - File extension.
154
+ * @param {string} [options.dir] - Directory to create the file in (defaults to OS temp dir).
155
+ * @param {string | Buffer} [options.content] - Optional content to write to the file.
156
+ * @returns {Promise<string>} Path to the created temporary file.
157
+ */
158
+ declare function createTempFile({ prefix, extension, dir, content }?: {
159
+ prefix?: string;
160
+ extension?: string;
161
+ dir?: string;
162
+ content?: string | Buffer;
163
+ }): Promise<string>;
164
+ /**
165
+ * Streams a file from source to destination.
166
+ * Useful for large files to avoid loading the entire file into memory.
167
+ *
168
+ * @param {string} source - Source file path.
169
+ * @param {string} destination - Destination file path.
170
+ * @returns {Promise<void>} Resolves when streaming completes.
171
+ * @throws {Error} If streaming fails.
172
+ */
173
+ declare function streamFile(source: string, destination: string): Promise<void>;
174
+ /**
175
+ * Reads a directory and returns file names.
176
+ *
177
+ * @param {string} dirPath - Path to the directory.
178
+ * @param {object} [options] - Options for reading the directory.
179
+ * @param {boolean} [options.fullPaths=false] - Whether to return full paths.
180
+ * @param {RegExp} [options.filter] - Optional regex to filter files.
181
+ * @returns {Promise<string[]>} Array of file names or paths.
182
+ * @throws {Error} If directory cannot be read.
183
+ */
184
+ declare function readDirectory(dirPath: string, options?: {
185
+ fullPaths?: boolean;
186
+ filter?: RegExp;
187
+ }): Promise<string[]>;
188
+ /**
189
+ * Creates a directory if it doesn't exist.
190
+ *
191
+ * @param {string} dirPath - Path to the directory.
192
+ * @param {boolean} [recursive=true] - Whether to create parent directories.
193
+ * @returns {Promise<boolean>} Resolves to `true` if successful, `false` otherwise.
194
+ */
195
+ declare function createDirectory(dirPath: string, recursive?: boolean): Promise<boolean>;
196
+ /**
197
+ * Safely reads and parses a JSON file with error details.
198
+ *
199
+ * @typeParam T - The expected type of the parsed JSON object.
200
+ * @param {string} path - The path to the JSON file.
201
+ * @returns {Promise<{ data: T | null; error: Error | null }>} Object with data and error properties.
202
+ */
203
+ declare function safeReadJsonFile<T = any>(path: string): Promise<{
204
+ data: T | null;
205
+ error: Error | null;
206
+ }>;
207
+ /**
208
+ * Checks if a path points to a file (not a directory).
209
+ *
210
+ * @param {string} path - Path to check.
211
+ * @returns {Promise<boolean>} True if the path is a file, false otherwise.
212
+ */
213
+ declare function isFile(path: string): Promise<boolean>;
214
+ /**
215
+ * Gets the size of a file in bytes.
216
+ *
217
+ * @param {string} path - Path to the file.
218
+ * @returns {Promise<number>} Size in bytes or -1 if file doesn't exist.
219
+ */
220
+ declare function getFileSize(path: string): Promise<number>;
221
+ /**
222
+ * Reads a file as a Buffer.
223
+ *
224
+ * @param {string} path - Path to the file.
225
+ * @returns {Promise<Buffer | null>} File contents as Buffer or null if reading fails.
226
+ */
227
+ declare function readFileBuffer(path: string): Promise<Buffer | null>;
228
+
229
+ export { appendFile, copyFile, createDirectory, createTempFile, deleteFileIfExists, fileExists, getFileSize, getFileStats, isFile, moveFile, readDirectory, readFile, readFileBuffer, readFileSync, readJsonFile, readJsonOrDefault, safeReadFile, safeReadFileSync, safeReadJsonFile, streamFile, writeFile, writeJsonFile };
package/fs/index.mjs ADDED
@@ -0,0 +1,258 @@
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 fs from 'fs';
26
+ import fsp from 'fs/promises';
27
+ import { tmpdir } from 'os';
28
+ import path from 'path';
29
+ import { pipeline } from 'stream/promises';
30
+ import { randomUUID } from 'crypto';
31
+
32
+ var __defProp = Object.defineProperty;
33
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
34
+ async function fileExists(path2) {
35
+ try {
36
+ await fsp.access(path2);
37
+ return true;
38
+ } catch {
39
+ return false;
40
+ }
41
+ }
42
+ __name(fileExists, "fileExists");
43
+ async function readJsonFile(path2) {
44
+ try {
45
+ const data = await fsp.readFile(path2, "utf-8");
46
+ return JSON.parse(data);
47
+ } catch {
48
+ return null;
49
+ }
50
+ }
51
+ __name(readJsonFile, "readJsonFile");
52
+ async function readJsonOrDefault(path2, defaultValue) {
53
+ const res = await safeReadJsonFile(path2);
54
+ return res.data === null ? defaultValue : res.data;
55
+ }
56
+ __name(readJsonOrDefault, "readJsonOrDefault");
57
+ async function writeJsonFile(path2, data, space = 2) {
58
+ const json = JSON.stringify(data, null, space);
59
+ await fsp.writeFile(path2, json, "utf-8");
60
+ }
61
+ __name(writeJsonFile, "writeJsonFile");
62
+ async function deleteFileIfExists(path2) {
63
+ try {
64
+ await fsp.unlink(path2);
65
+ return true;
66
+ } catch (err) {
67
+ if (err.code === "ENOENT") return true;
68
+ return false;
69
+ }
70
+ }
71
+ __name(deleteFileIfExists, "deleteFileIfExists");
72
+ async function readFile(path2, encoding = "utf-8") {
73
+ return await fsp.readFile(path2, encoding);
74
+ }
75
+ __name(readFile, "readFile");
76
+ function readFileSync(path2, encoding = "utf-8") {
77
+ return fs.readFileSync(path2, encoding);
78
+ }
79
+ __name(readFileSync, "readFileSync");
80
+ async function safeReadFile(path2, encoding = "utf-8") {
81
+ try {
82
+ const data = await fsp.readFile(path2, encoding);
83
+ return {
84
+ data,
85
+ error: null
86
+ };
87
+ } catch (error) {
88
+ return {
89
+ data: null,
90
+ error: new Error(`Failed to read file ${path2}: ${error.message}`)
91
+ };
92
+ }
93
+ }
94
+ __name(safeReadFile, "safeReadFile");
95
+ function safeReadFileSync(path2, encoding = "utf-8") {
96
+ try {
97
+ const data = fs.readFileSync(path2, encoding);
98
+ return {
99
+ data,
100
+ error: null
101
+ };
102
+ } catch (error) {
103
+ return {
104
+ data: null,
105
+ error: new Error(`Failed to read file ${path2}: ${error.message}`)
106
+ };
107
+ }
108
+ }
109
+ __name(safeReadFileSync, "safeReadFileSync");
110
+ async function writeFile(path2, content, encoding = "utf-8") {
111
+ try {
112
+ await fsp.writeFile(path2, content, encoding);
113
+ return true;
114
+ } catch {
115
+ return false;
116
+ }
117
+ }
118
+ __name(writeFile, "writeFile");
119
+ async function appendFile(path2, content, encoding = "utf-8") {
120
+ try {
121
+ await fsp.appendFile(path2, content, encoding);
122
+ return true;
123
+ } catch {
124
+ return false;
125
+ }
126
+ }
127
+ __name(appendFile, "appendFile");
128
+ async function copyFile(source, destination, overwrite = false) {
129
+ try {
130
+ const flags = overwrite ? 0 : fsp.constants.COPYFILE_EXCL;
131
+ await fsp.copyFile(source, destination, flags);
132
+ return true;
133
+ } catch {
134
+ return false;
135
+ }
136
+ }
137
+ __name(copyFile, "copyFile");
138
+ async function moveFile(oldPath, newPath) {
139
+ try {
140
+ await fsp.rename(oldPath, newPath);
141
+ return true;
142
+ } catch {
143
+ try {
144
+ await fsp.copyFile(oldPath, newPath);
145
+ await fsp.unlink(oldPath);
146
+ return true;
147
+ } catch {
148
+ return false;
149
+ }
150
+ }
151
+ }
152
+ __name(moveFile, "moveFile");
153
+ async function getFileStats(path2) {
154
+ try {
155
+ return await fsp.stat(path2);
156
+ } catch {
157
+ return null;
158
+ }
159
+ }
160
+ __name(getFileStats, "getFileStats");
161
+ async function createTempFile({ prefix = "tmp-", extension = "", dir = tmpdir(), content } = {}) {
162
+ const ext = extension ? extension.startsWith(".") ? extension : `.${extension}` : "";
163
+ const filename = `${prefix}${randomUUID()}${ext}`;
164
+ const filepath = path.join(dir, filename);
165
+ if (content) {
166
+ await fsp.writeFile(filepath, content);
167
+ } else {
168
+ await fsp.writeFile(filepath, "");
169
+ }
170
+ return filepath;
171
+ }
172
+ __name(createTempFile, "createTempFile");
173
+ async function streamFile(source, destination) {
174
+ const readStream = fs.createReadStream(source);
175
+ const writeStream = fs.createWriteStream(destination);
176
+ try {
177
+ await pipeline(readStream, writeStream);
178
+ } catch (error) {
179
+ readStream.destroy();
180
+ writeStream.destroy();
181
+ throw error;
182
+ }
183
+ }
184
+ __name(streamFile, "streamFile");
185
+ async function readDirectory(dirPath, options = {}) {
186
+ const files = await fsp.readdir(dirPath);
187
+ let result = files;
188
+ if (options.filter) {
189
+ result = result.filter((file) => options.filter.test(file));
190
+ }
191
+ if (options.fullPaths) {
192
+ result = result.map((file) => path.join(dirPath, file));
193
+ }
194
+ return result;
195
+ }
196
+ __name(readDirectory, "readDirectory");
197
+ async function createDirectory(dirPath, recursive = true) {
198
+ try {
199
+ await fsp.mkdir(dirPath, {
200
+ recursive
201
+ });
202
+ return true;
203
+ } catch (err) {
204
+ return err.code === "EEXIST";
205
+ }
206
+ }
207
+ __name(createDirectory, "createDirectory");
208
+ async function safeReadJsonFile(path2) {
209
+ try {
210
+ const content = await fsp.readFile(path2, "utf-8");
211
+ try {
212
+ const data = JSON.parse(content);
213
+ return {
214
+ data,
215
+ error: null
216
+ };
217
+ } catch (error) {
218
+ return {
219
+ data: null,
220
+ error: new Error(`Invalid JSON in file ${path2}: ${error.message}`)
221
+ };
222
+ }
223
+ } catch (error) {
224
+ return {
225
+ data: null,
226
+ error: new Error(`Failed to read file ${path2}: ${error.message}`)
227
+ };
228
+ }
229
+ }
230
+ __name(safeReadJsonFile, "safeReadJsonFile");
231
+ async function isFile(path2) {
232
+ try {
233
+ const stat = await fsp.stat(path2);
234
+ return stat.isFile();
235
+ } catch {
236
+ return false;
237
+ }
238
+ }
239
+ __name(isFile, "isFile");
240
+ async function getFileSize(path2) {
241
+ try {
242
+ const stat = await fsp.stat(path2);
243
+ return stat.size;
244
+ } catch {
245
+ return -1;
246
+ }
247
+ }
248
+ __name(getFileSize, "getFileSize");
249
+ async function readFileBuffer(path2) {
250
+ try {
251
+ return await fsp.readFile(path2);
252
+ } catch {
253
+ return null;
254
+ }
255
+ }
256
+ __name(readFileBuffer, "readFileBuffer");
257
+
258
+ export { appendFile, copyFile, createDirectory, createTempFile, deleteFileIfExists, fileExists, getFileSize, getFileStats, isFile, moveFile, readDirectory, readFile, readFileBuffer, readFileSync, readJsonFile, readJsonOrDefault, safeReadFile, safeReadFileSync, safeReadJsonFile, streamFile, writeFile, writeJsonFile };
@@ -0,0 +1,96 @@
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
+ // src/http-status-codes/http-status-codes.ts
28
+ var HttpStatusCodes = /* @__PURE__ */ (function(HttpStatusCodes2) {
29
+ HttpStatusCodes2[HttpStatusCodes2["CONTINUE"] = 100] = "CONTINUE";
30
+ HttpStatusCodes2[HttpStatusCodes2["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
31
+ HttpStatusCodes2[HttpStatusCodes2["PROCESSING"] = 102] = "PROCESSING";
32
+ HttpStatusCodes2[HttpStatusCodes2["EARLY_HINTS"] = 103] = "EARLY_HINTS";
33
+ HttpStatusCodes2[HttpStatusCodes2["OK"] = 200] = "OK";
34
+ HttpStatusCodes2[HttpStatusCodes2["CREATED"] = 201] = "CREATED";
35
+ HttpStatusCodes2[HttpStatusCodes2["ACCEPTED"] = 202] = "ACCEPTED";
36
+ HttpStatusCodes2[HttpStatusCodes2["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
37
+ HttpStatusCodes2[HttpStatusCodes2["NO_CONTENT"] = 204] = "NO_CONTENT";
38
+ HttpStatusCodes2[HttpStatusCodes2["RESET_CONTENT"] = 205] = "RESET_CONTENT";
39
+ HttpStatusCodes2[HttpStatusCodes2["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
40
+ HttpStatusCodes2[HttpStatusCodes2["MULTI_STATUS"] = 207] = "MULTI_STATUS";
41
+ HttpStatusCodes2[HttpStatusCodes2["ALREADY_REPORTED"] = 208] = "ALREADY_REPORTED";
42
+ HttpStatusCodes2[HttpStatusCodes2["IM_USED"] = 226] = "IM_USED";
43
+ HttpStatusCodes2[HttpStatusCodes2["MULTIPLE_CHOICES"] = 300] = "MULTIPLE_CHOICES";
44
+ HttpStatusCodes2[HttpStatusCodes2["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
45
+ HttpStatusCodes2[HttpStatusCodes2["MOVED_TEMPORARILY"] = 302] = "MOVED_TEMPORARILY";
46
+ HttpStatusCodes2[HttpStatusCodes2["SEE_OTHER"] = 303] = "SEE_OTHER";
47
+ HttpStatusCodes2[HttpStatusCodes2["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
48
+ HttpStatusCodes2[HttpStatusCodes2["USE_PROXY"] = 305] = "USE_PROXY";
49
+ HttpStatusCodes2[HttpStatusCodes2["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
50
+ HttpStatusCodes2[HttpStatusCodes2["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
51
+ HttpStatusCodes2[HttpStatusCodes2["BAD_REQUEST"] = 400] = "BAD_REQUEST";
52
+ HttpStatusCodes2[HttpStatusCodes2["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
53
+ HttpStatusCodes2[HttpStatusCodes2["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
54
+ HttpStatusCodes2[HttpStatusCodes2["FORBIDDEN"] = 403] = "FORBIDDEN";
55
+ HttpStatusCodes2[HttpStatusCodes2["NOT_FOUND"] = 404] = "NOT_FOUND";
56
+ HttpStatusCodes2[HttpStatusCodes2["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
57
+ HttpStatusCodes2[HttpStatusCodes2["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
58
+ HttpStatusCodes2[HttpStatusCodes2["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
59
+ HttpStatusCodes2[HttpStatusCodes2["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
60
+ HttpStatusCodes2[HttpStatusCodes2["CONFLICT"] = 409] = "CONFLICT";
61
+ HttpStatusCodes2[HttpStatusCodes2["GONE"] = 410] = "GONE";
62
+ HttpStatusCodes2[HttpStatusCodes2["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
63
+ HttpStatusCodes2[HttpStatusCodes2["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
64
+ HttpStatusCodes2[HttpStatusCodes2["REQUEST_TOO_LONG"] = 413] = "REQUEST_TOO_LONG";
65
+ HttpStatusCodes2[HttpStatusCodes2["PAYLOAD_TOO_LARGE"] = 413] = "PAYLOAD_TOO_LARGE";
66
+ HttpStatusCodes2[HttpStatusCodes2["REQUEST_URI_TOO_LONG"] = 414] = "REQUEST_URI_TOO_LONG";
67
+ HttpStatusCodes2[HttpStatusCodes2["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
68
+ HttpStatusCodes2[HttpStatusCodes2["REQUESTED_RANGE_NOT_SATISFIABLE"] = 416] = "REQUESTED_RANGE_NOT_SATISFIABLE";
69
+ HttpStatusCodes2[HttpStatusCodes2["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
70
+ HttpStatusCodes2[HttpStatusCodes2["IM_A_TEAPOT"] = 418] = "IM_A_TEAPOT";
71
+ HttpStatusCodes2[HttpStatusCodes2["INSUFFICIENT_SPACE_ON_RESOURCE"] = 419] = "INSUFFICIENT_SPACE_ON_RESOURCE";
72
+ HttpStatusCodes2[HttpStatusCodes2["METHOD_FAILURE"] = 420] = "METHOD_FAILURE";
73
+ HttpStatusCodes2[HttpStatusCodes2["MISDIRECTED_REQUEST"] = 421] = "MISDIRECTED_REQUEST";
74
+ HttpStatusCodes2[HttpStatusCodes2["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
75
+ HttpStatusCodes2[HttpStatusCodes2["LOCKED"] = 423] = "LOCKED";
76
+ HttpStatusCodes2[HttpStatusCodes2["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY";
77
+ HttpStatusCodes2[HttpStatusCodes2["UPGRADE_REQUIRED"] = 426] = "UPGRADE_REQUIRED";
78
+ HttpStatusCodes2[HttpStatusCodes2["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
79
+ HttpStatusCodes2[HttpStatusCodes2["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
80
+ HttpStatusCodes2[HttpStatusCodes2["REQUEST_HEADER_FIELDS_TOO_LARGE"] = 431] = "REQUEST_HEADER_FIELDS_TOO_LARGE";
81
+ HttpStatusCodes2[HttpStatusCodes2["UNAVAILABLE_FOR_LEGAL_REASONS"] = 451] = "UNAVAILABLE_FOR_LEGAL_REASONS";
82
+ HttpStatusCodes2[HttpStatusCodes2["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
83
+ HttpStatusCodes2[HttpStatusCodes2["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
84
+ HttpStatusCodes2[HttpStatusCodes2["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
85
+ HttpStatusCodes2[HttpStatusCodes2["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
86
+ HttpStatusCodes2[HttpStatusCodes2["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
87
+ HttpStatusCodes2[HttpStatusCodes2["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
88
+ HttpStatusCodes2[HttpStatusCodes2["VARIANT_ALSO_NEGOTIATES"] = 506] = "VARIANT_ALSO_NEGOTIATES";
89
+ HttpStatusCodes2[HttpStatusCodes2["INSUFFICIENT_STORAGE"] = 507] = "INSUFFICIENT_STORAGE";
90
+ HttpStatusCodes2[HttpStatusCodes2["LOOP_DETECTED"] = 508] = "LOOP_DETECTED";
91
+ HttpStatusCodes2[HttpStatusCodes2["NOT_EXTENDED"] = 510] = "NOT_EXTENDED";
92
+ HttpStatusCodes2[HttpStatusCodes2["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
93
+ return HttpStatusCodes2;
94
+ })({});
95
+
96
+ exports.HttpStatusCodes = HttpStatusCodes;