@catbee/utils 0.0.8-rc.0 → 0.0.8-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -1
- package/build/esm/config.d.ts +0 -1
- package/build/esm/config.js +6 -7
- package/build/esm/index.d.ts +0 -1
- package/build/esm/index.js +0 -1
- package/build/esm/servers/server.builder.d.ts +0 -1
- package/build/esm/servers/server.builder.js +99 -147
- package/build/esm/servers/server.d.ts +0 -1
- package/build/esm/servers/server.js +591 -876
- package/build/esm/types/api-response.d.ts +0 -1
- package/build/esm/types/api-response.js +0 -1
- package/build/esm/types/index.d.ts +0 -1
- package/build/esm/types/index.js +0 -1
- package/build/esm/types/server.d.ts +0 -1
- package/build/esm/types/server.js +0 -1
- package/build/esm/utils/array.utils.d.ts +0 -1
- package/build/esm/utils/array.utils.js +48 -86
- package/build/esm/utils/async.utils.d.ts +0 -1
- package/build/esm/utils/async.utils.js +247 -524
- package/build/esm/utils/cache.utils.d.ts +0 -1
- package/build/esm/utils/cache.utils.js +96 -301
- package/build/esm/utils/context-store.utils.d.ts +0 -1
- package/build/esm/utils/context-store.utils.js +62 -79
- package/build/esm/utils/crypto.utils.d.ts +0 -1
- package/build/esm/utils/crypto.utils.js +78 -175
- package/build/esm/utils/date.utils.d.ts +0 -1
- package/build/esm/utils/date.utils.js +47 -53
- package/build/esm/utils/decorators.utils.d.ts +201 -5
- package/build/esm/utils/decorators.utils.js +632 -285
- package/build/esm/utils/dir.utils.d.ts +0 -1
- package/build/esm/utils/dir.utils.js +264 -786
- package/build/esm/utils/env.utils.d.ts +0 -1
- package/build/esm/utils/env.utils.js +180 -271
- package/build/esm/utils/exception.utils.d.ts +0 -1
- package/build/esm/utils/exception.utils.js +112 -289
- package/build/esm/utils/fs.utils.d.ts +0 -1
- package/build/esm/utils/fs.utils.js +169 -401
- package/build/esm/utils/http-status-codes.d.ts +0 -1
- package/build/esm/utils/http-status-codes.js +0 -1
- package/build/esm/utils/id.utils.d.ts +0 -1
- package/build/esm/utils/id.utils.js +5 -9
- package/build/esm/utils/logger.utils.d.ts +0 -1
- package/build/esm/utils/logger.utils.js +34 -71
- package/build/esm/utils/middleware.utils.d.ts +0 -1
- package/build/esm/utils/middleware.utils.js +65 -155
- package/build/esm/utils/obj.utils.d.ts +0 -1
- package/build/esm/utils/obj.utils.js +69 -176
- package/build/esm/utils/performance.utils.d.ts +0 -1
- package/build/esm/utils/performance.utils.js +92 -195
- package/build/esm/utils/request.utils.d.ts +0 -1
- package/build/esm/utils/request.utils.js +41 -74
- package/build/esm/utils/response.utils.d.ts +0 -1
- package/build/esm/utils/response.utils.js +84 -107
- package/build/esm/utils/stream.utils.d.ts +0 -1
- package/build/esm/utils/stream.utils.js +38 -113
- package/build/esm/utils/string.utils.d.ts +0 -1
- package/build/esm/utils/string.utils.js +6 -11
- package/build/esm/utils/type.utils.d.ts +0 -1
- package/build/esm/utils/type.utils.js +8 -12
- package/build/esm/utils/url.utils.d.ts +0 -1
- package/build/esm/utils/url.utils.js +49 -127
- package/build/esm/utils/validate.utils.d.ts +0 -1
- package/build/esm/utils/validate.utils.js +23 -40
- package/package.json +3 -33
- package/build/esm/config.js.map +0 -1
- package/build/esm/index.js.map +0 -1
- package/build/esm/servers/server.builder.js.map +0 -1
- package/build/esm/servers/server.js.map +0 -1
- package/build/esm/types/api-response.js.map +0 -1
- package/build/esm/types/index.js.map +0 -1
- package/build/esm/types/server.js.map +0 -1
- package/build/esm/utils/array.utils.js.map +0 -1
- package/build/esm/utils/async.utils.js.map +0 -1
- package/build/esm/utils/cache.utils.js.map +0 -1
- package/build/esm/utils/context-store.utils.js.map +0 -1
- package/build/esm/utils/crypto.utils.js.map +0 -1
- package/build/esm/utils/date.utils.js.map +0 -1
- package/build/esm/utils/decorators.utils.js.map +0 -1
- package/build/esm/utils/dir.utils.js.map +0 -1
- package/build/esm/utils/env.utils.js.map +0 -1
- package/build/esm/utils/exception.utils.js.map +0 -1
- package/build/esm/utils/fs.utils.js.map +0 -1
- package/build/esm/utils/http-status-codes.js.map +0 -1
- package/build/esm/utils/id.utils.js.map +0 -1
- package/build/esm/utils/logger.utils.js.map +0 -1
- package/build/esm/utils/middleware.utils.js.map +0 -1
- package/build/esm/utils/obj.utils.js.map +0 -1
- package/build/esm/utils/performance.utils.js.map +0 -1
- package/build/esm/utils/request.utils.js.map +0 -1
- package/build/esm/utils/response.utils.js.map +0 -1
- package/build/esm/utils/stream.utils.js.map +0 -1
- package/build/esm/utils/string.utils.js.map +0 -1
- package/build/esm/utils/type.utils.js.map +0 -1
- package/build/esm/utils/url.utils.js.map +0 -1
- package/build/esm/utils/validate.utils.js.map +0 -1
- package/build/esnext/config.d.ts +0 -122
- package/build/esnext/config.js +0 -133
- package/build/esnext/config.js.map +0 -1
- package/build/esnext/index.d.ts +0 -27
- package/build/esnext/index.js +0 -50
- package/build/esnext/index.js.map +0 -1
- package/build/esnext/servers/server.builder.d.ts +0 -508
- package/build/esnext/servers/server.builder.js +0 -657
- package/build/esnext/servers/server.builder.js.map +0 -1
- package/build/esnext/servers/server.d.ts +0 -256
- package/build/esnext/servers/server.js +0 -955
- package/build/esnext/servers/server.js.map +0 -1
- package/build/esnext/types/api-response.d.ts +0 -152
- package/build/esnext/types/api-response.js +0 -34
- package/build/esnext/types/api-response.js.map +0 -1
- package/build/esnext/types/index.d.ts +0 -125
- package/build/esnext/types/index.js +0 -25
- package/build/esnext/types/index.js.map +0 -1
- package/build/esnext/types/server.d.ts +0 -268
- package/build/esnext/types/server.js +0 -25
- package/build/esnext/types/server.js.map +0 -1
- package/build/esnext/utils/array.utils.d.ts +0 -168
- package/build/esnext/utils/array.utils.js +0 -345
- package/build/esnext/utils/array.utils.js.map +0 -1
- package/build/esnext/utils/async.utils.d.ts +0 -265
- package/build/esnext/utils/async.utils.js +0 -620
- package/build/esnext/utils/async.utils.js.map +0 -1
- package/build/esnext/utils/cache.utils.d.ts +0 -153
- package/build/esnext/utils/cache.utils.js +0 -293
- package/build/esnext/utils/cache.utils.js.map +0 -1
- package/build/esnext/utils/context-store.utils.d.ts +0 -189
- package/build/esnext/utils/context-store.utils.js +0 -289
- package/build/esnext/utils/context-store.utils.js.map +0 -1
- package/build/esnext/utils/crypto.utils.d.ts +0 -160
- package/build/esnext/utils/crypto.utils.js +0 -276
- package/build/esnext/utils/crypto.utils.js.map +0 -1
- package/build/esnext/utils/date.utils.d.ts +0 -159
- package/build/esnext/utils/date.utils.js +0 -384
- package/build/esnext/utils/date.utils.js.map +0 -1
- package/build/esnext/utils/decorators.utils.d.ts +0 -315
- package/build/esnext/utils/decorators.utils.js +0 -504
- package/build/esnext/utils/decorators.utils.js.map +0 -1
- package/build/esnext/utils/dir.utils.d.ts +0 -196
- package/build/esnext/utils/dir.utils.js +0 -477
- package/build/esnext/utils/dir.utils.js.map +0 -1
- package/build/esnext/utils/env.utils.d.ts +0 -377
- package/build/esnext/utils/env.utils.js +0 -785
- package/build/esnext/utils/env.utils.js.map +0 -1
- package/build/esnext/utils/exception.utils.d.ts +0 -230
- package/build/esnext/utils/exception.utils.js +0 -381
- package/build/esnext/utils/exception.utils.js.map +0 -1
- package/build/esnext/utils/fs.utils.d.ts +0 -164
- package/build/esnext/utils/fs.utils.js +0 -349
- package/build/esnext/utils/fs.utils.js.map +0 -1
- package/build/esnext/utils/http-status-codes.d.ts +0 -266
- package/build/esnext/utils/http-status-codes.js +0 -295
- package/build/esnext/utils/http-status-codes.js.map +0 -1
- package/build/esnext/utils/id.utils.d.ts +0 -36
- package/build/esnext/utils/id.utils.js +0 -84
- package/build/esnext/utils/id.utils.js.map +0 -1
- package/build/esnext/utils/logger.utils.d.ts +0 -160
- package/build/esnext/utils/logger.utils.js +0 -300
- package/build/esnext/utils/logger.utils.js.map +0 -1
- package/build/esnext/utils/middleware.utils.d.ts +0 -100
- package/build/esnext/utils/middleware.utils.js +0 -236
- package/build/esnext/utils/middleware.utils.js.map +0 -1
- package/build/esnext/utils/obj.utils.d.ts +0 -124
- package/build/esnext/utils/obj.utils.js +0 -413
- package/build/esnext/utils/obj.utils.js.map +0 -1
- package/build/esnext/utils/performance.utils.d.ts +0 -136
- package/build/esnext/utils/performance.utils.js +0 -271
- package/build/esnext/utils/performance.utils.js.map +0 -1
- package/build/esnext/utils/request.utils.d.ts +0 -86
- package/build/esnext/utils/request.utils.js +0 -186
- package/build/esnext/utils/request.utils.js.map +0 -1
- package/build/esnext/utils/response.utils.d.ts +0 -163
- package/build/esnext/utils/response.utils.js +0 -247
- package/build/esnext/utils/response.utils.js.map +0 -1
- package/build/esnext/utils/stream.utils.d.ts +0 -88
- package/build/esnext/utils/stream.utils.js +0 -210
- package/build/esnext/utils/stream.utils.js.map +0 -1
- package/build/esnext/utils/string.utils.d.ts +0 -93
- package/build/esnext/utils/string.utils.js +0 -165
- package/build/esnext/utils/string.utils.js.map +0 -1
- package/build/esnext/utils/type.utils.d.ts +0 -90
- package/build/esnext/utils/type.utils.js +0 -187
- package/build/esnext/utils/type.utils.js.map +0 -1
- package/build/esnext/utils/url.utils.d.ts +0 -141
- package/build/esnext/utils/url.utils.js +0 -304
- package/build/esnext/utils/url.utils.js.map +0 -1
- package/build/esnext/utils/validate.utils.d.ts +0 -177
- package/build/esnext/utils/validate.utils.js +0 -320
- package/build/esnext/utils/validate.utils.js.map +0 -1
- package/build/src/config.d.ts +0 -122
- package/build/src/config.js +0 -138
- package/build/src/config.js.map +0 -1
- package/build/src/index.d.ts +0 -27
- package/build/src/index.js +0 -69
- package/build/src/index.js.map +0 -1
- package/build/src/servers/server.builder.d.ts +0 -508
- package/build/src/servers/server.builder.js +0 -661
- package/build/src/servers/server.builder.js.map +0 -1
- package/build/src/servers/server.d.ts +0 -256
- package/build/src/servers/server.js +0 -962
- package/build/src/servers/server.js.map +0 -1
- package/build/src/types/api-response.d.ts +0 -152
- package/build/src/types/api-response.js +0 -37
- package/build/src/types/api-response.js.map +0 -1
- package/build/src/types/index.d.ts +0 -125
- package/build/src/types/index.js +0 -26
- package/build/src/types/index.js.map +0 -1
- package/build/src/types/server.d.ts +0 -268
- package/build/src/types/server.js +0 -26
- package/build/src/types/server.js.map +0 -1
- package/build/src/utils/array.utils.d.ts +0 -168
- package/build/src/utils/array.utils.js +0 -364
- package/build/src/utils/array.utils.js.map +0 -1
- package/build/src/utils/async.utils.d.ts +0 -265
- package/build/src/utils/async.utils.js +0 -641
- package/build/src/utils/async.utils.js.map +0 -1
- package/build/src/utils/cache.utils.d.ts +0 -153
- package/build/src/utils/cache.utils.js +0 -297
- package/build/src/utils/cache.utils.js.map +0 -1
- package/build/src/utils/context-store.utils.d.ts +0 -189
- package/build/src/utils/context-store.utils.js +0 -296
- package/build/src/utils/context-store.utils.js.map +0 -1
- package/build/src/utils/crypto.utils.d.ts +0 -160
- package/build/src/utils/crypto.utils.js +0 -293
- package/build/src/utils/crypto.utils.js.map +0 -1
- package/build/src/utils/date.utils.d.ts +0 -159
- package/build/src/utils/date.utils.js +0 -396
- package/build/src/utils/date.utils.js.map +0 -1
- package/build/src/utils/decorators.utils.d.ts +0 -315
- package/build/src/utils/decorators.utils.js +0 -516
- package/build/src/utils/decorators.utils.js.map +0 -1
- package/build/src/utils/dir.utils.d.ts +0 -196
- package/build/src/utils/dir.utils.js +0 -501
- package/build/src/utils/dir.utils.js.map +0 -1
- package/build/src/utils/env.utils.d.ts +0 -377
- package/build/src/utils/env.utils.js +0 -789
- package/build/src/utils/env.utils.js.map +0 -1
- package/build/src/utils/exception.utils.d.ts +0 -230
- package/build/src/utils/exception.utils.js +0 -407
- package/build/src/utils/exception.utils.js.map +0 -1
- package/build/src/utils/fs.utils.d.ts +0 -164
- package/build/src/utils/fs.utils.js +0 -372
- package/build/src/utils/fs.utils.js.map +0 -1
- package/build/src/utils/http-status-codes.d.ts +0 -266
- package/build/src/utils/http-status-codes.js +0 -298
- package/build/src/utils/http-status-codes.js.map +0 -1
- package/build/src/utils/id.utils.d.ts +0 -36
- package/build/src/utils/id.utils.js +0 -91
- package/build/src/utils/id.utils.js.map +0 -1
- package/build/src/utils/logger.utils.d.ts +0 -160
- package/build/src/utils/logger.utils.js +0 -346
- package/build/src/utils/logger.utils.js.map +0 -1
- package/build/src/utils/middleware.utils.d.ts +0 -100
- package/build/src/utils/middleware.utils.js +0 -244
- package/build/src/utils/middleware.utils.js.map +0 -1
- package/build/src/utils/obj.utils.d.ts +0 -124
- package/build/src/utils/obj.utils.js +0 -429
- package/build/src/utils/obj.utils.js.map +0 -1
- package/build/src/utils/performance.utils.d.ts +0 -136
- package/build/src/utils/performance.utils.js +0 -278
- package/build/src/utils/performance.utils.js.map +0 -1
- package/build/src/utils/request.utils.d.ts +0 -86
- package/build/src/utils/request.utils.js +0 -195
- package/build/src/utils/request.utils.js.map +0 -1
- package/build/src/utils/response.utils.d.ts +0 -163
- package/build/src/utils/response.utils.js +0 -260
- package/build/src/utils/response.utils.js.map +0 -1
- package/build/src/utils/stream.utils.d.ts +0 -88
- package/build/src/utils/stream.utils.js +0 -218
- package/build/src/utils/stream.utils.js.map +0 -1
- package/build/src/utils/string.utils.d.ts +0 -93
- package/build/src/utils/string.utils.js +0 -179
- package/build/src/utils/string.utils.js.map +0 -1
- package/build/src/utils/type.utils.d.ts +0 -90
- package/build/src/utils/type.utils.js +0 -196
- package/build/src/utils/type.utils.js.map +0 -1
- package/build/src/utils/url.utils.d.ts +0 -141
- package/build/src/utils/url.utils.js +0 -317
- package/build/src/utils/url.utils.js.map +0 -1
- package/build/src/utils/validate.utils.d.ts +0 -177
- package/build/src/utils/validate.utils.js +0 -345
- package/build/src/utils/validate.utils.js.map +0 -1
|
@@ -1,372 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* The MIT License
|
|
4
|
-
*
|
|
5
|
-
* Copyright (c) 2025 Catbee Technologies. https://catbee-utils.npm.hprasath.com/license
|
|
6
|
-
*
|
|
7
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
-
* in the Software without restriction, including without limitation the rights
|
|
10
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
-
* furnished to do so, subject to the following conditions:
|
|
13
|
-
*
|
|
14
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
-
* copies or substantial portions of the Software.
|
|
16
|
-
*
|
|
17
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
-
* SOFTWARE.
|
|
24
|
-
*/
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.fileExists = fileExists;
|
|
30
|
-
exports.readJsonFile = readJsonFile;
|
|
31
|
-
exports.writeJsonFile = writeJsonFile;
|
|
32
|
-
exports.deleteFileIfExists = deleteFileIfExists;
|
|
33
|
-
exports.readTextFile = readTextFile;
|
|
34
|
-
exports.writeTextFile = writeTextFile;
|
|
35
|
-
exports.appendTextFile = appendTextFile;
|
|
36
|
-
exports.copyFile = copyFile;
|
|
37
|
-
exports.moveFile = moveFile;
|
|
38
|
-
exports.getFileStats = getFileStats;
|
|
39
|
-
exports.createTempFile = createTempFile;
|
|
40
|
-
exports.streamFile = streamFile;
|
|
41
|
-
exports.readDirectory = readDirectory;
|
|
42
|
-
exports.createDirectory = createDirectory;
|
|
43
|
-
exports.safeReadJsonFile = safeReadJsonFile;
|
|
44
|
-
exports.isFile = isFile;
|
|
45
|
-
exports.getFileSize = getFileSize;
|
|
46
|
-
exports.readFileBuffer = readFileBuffer;
|
|
47
|
-
const promises_1 = __importDefault(require("fs/promises"));
|
|
48
|
-
const fs_1 = require("fs");
|
|
49
|
-
const os_1 = require("os");
|
|
50
|
-
const path_1 = __importDefault(require("path"));
|
|
51
|
-
const promises_2 = require("stream/promises");
|
|
52
|
-
const crypto_1 = require("crypto");
|
|
53
|
-
/**
|
|
54
|
-
* Checks whether a file or directory exists at the given path.
|
|
55
|
-
*
|
|
56
|
-
* @param {string} path - The file or directory path to check.
|
|
57
|
-
* @returns {Promise<boolean>} Resolves to `true` if the path exists, `false` otherwise.
|
|
58
|
-
*/
|
|
59
|
-
async function fileExists(path) {
|
|
60
|
-
try {
|
|
61
|
-
await promises_1.default.access(path);
|
|
62
|
-
return true;
|
|
63
|
-
}
|
|
64
|
-
catch (_a) {
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Reads and parses a JSON file from the specified path.
|
|
70
|
-
*
|
|
71
|
-
* @typeParam T - The expected type of the parsed JSON object.
|
|
72
|
-
* @param {string} path - The path to the JSON file.
|
|
73
|
-
* @returns {Promise<T | null>} The parsed object, or `null` if reading or parsing fails.
|
|
74
|
-
*/
|
|
75
|
-
async function readJsonFile(path) {
|
|
76
|
-
try {
|
|
77
|
-
const data = await promises_1.default.readFile(path, 'utf-8');
|
|
78
|
-
return JSON.parse(data);
|
|
79
|
-
}
|
|
80
|
-
catch (_a) {
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Writes a JavaScript object to a file as formatted JSON.
|
|
86
|
-
*
|
|
87
|
-
* @param {string} path - The destination file path.
|
|
88
|
-
* @param {any} data - The object to serialize and write.
|
|
89
|
-
* @param {number} [space=2] - Number of spaces for JSON formatting.
|
|
90
|
-
* @returns {Promise<void>} Resolves when writing is complete.
|
|
91
|
-
*/
|
|
92
|
-
async function writeJsonFile(path, data, space = 2) {
|
|
93
|
-
const json = JSON.stringify(data, null, space);
|
|
94
|
-
await promises_1.default.writeFile(path, json, 'utf-8');
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Deletes a file if it exists.
|
|
98
|
-
*
|
|
99
|
-
* @param {string} path - The file path to delete.
|
|
100
|
-
* @returns {Promise<boolean>} Resolves to `true` if the file was deleted or didn't exist, `false` if deletion failed.
|
|
101
|
-
*/
|
|
102
|
-
async function deleteFileIfExists(path) {
|
|
103
|
-
try {
|
|
104
|
-
await promises_1.default.unlink(path);
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
catch (err) {
|
|
108
|
-
if (err.code === 'ENOENT')
|
|
109
|
-
return true;
|
|
110
|
-
return false;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Reads a text file from the specified path.
|
|
115
|
-
*
|
|
116
|
-
* @param {string} path - The path to the text file.
|
|
117
|
-
* @param {BufferEncoding} [encoding="utf-8"] - The encoding to use.
|
|
118
|
-
* @returns {Promise<string | null>} The file contents, or `null` if reading fails.
|
|
119
|
-
*/
|
|
120
|
-
async function readTextFile(path, encoding = 'utf-8') {
|
|
121
|
-
try {
|
|
122
|
-
return await promises_1.default.readFile(path, encoding);
|
|
123
|
-
}
|
|
124
|
-
catch (_a) {
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Writes text content to a file.
|
|
130
|
-
*
|
|
131
|
-
* @param {string} path - The destination file path.
|
|
132
|
-
* @param {string} content - The text content to write.
|
|
133
|
-
* @param {BufferEncoding} [encoding="utf-8"] - The encoding to use.
|
|
134
|
-
* @returns {Promise<boolean>} Resolves to `true` if successful, `false` otherwise.
|
|
135
|
-
*/
|
|
136
|
-
async function writeTextFile(path, content, encoding = 'utf-8') {
|
|
137
|
-
try {
|
|
138
|
-
await promises_1.default.writeFile(path, content, encoding);
|
|
139
|
-
return true;
|
|
140
|
-
}
|
|
141
|
-
catch (_a) {
|
|
142
|
-
return false;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Appends text content to a file.
|
|
147
|
-
*
|
|
148
|
-
* @param {string} path - The file path to append to.
|
|
149
|
-
* @param {string} content - The text content to append.
|
|
150
|
-
* @param {BufferEncoding} [encoding="utf-8"] - The encoding to use.
|
|
151
|
-
* @returns {Promise<boolean>} Resolves to `true` if successful, `false` otherwise.
|
|
152
|
-
*/
|
|
153
|
-
async function appendTextFile(path, content, encoding = 'utf-8') {
|
|
154
|
-
try {
|
|
155
|
-
await promises_1.default.appendFile(path, content, encoding);
|
|
156
|
-
return true;
|
|
157
|
-
}
|
|
158
|
-
catch (_a) {
|
|
159
|
-
return false;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Copies a file from source to destination.
|
|
164
|
-
*
|
|
165
|
-
* @param {string} source - Source file path.
|
|
166
|
-
* @param {string} destination - Destination file path.
|
|
167
|
-
* @param {boolean} [overwrite=false] - Whether to overwrite if destination exists.
|
|
168
|
-
* @returns {Promise<boolean>} Resolves to `true` if successful, `false` otherwise.
|
|
169
|
-
*/
|
|
170
|
-
async function copyFile(source, destination, overwrite = false) {
|
|
171
|
-
try {
|
|
172
|
-
const flags = overwrite ? 0 : promises_1.default.constants.COPYFILE_EXCL;
|
|
173
|
-
await promises_1.default.copyFile(source, destination, flags);
|
|
174
|
-
return true;
|
|
175
|
-
}
|
|
176
|
-
catch (_a) {
|
|
177
|
-
return false;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Renames/moves a file.
|
|
182
|
-
*
|
|
183
|
-
* @param {string} oldPath - Current file path.
|
|
184
|
-
* @param {string} newPath - New file path.
|
|
185
|
-
* @returns {Promise<boolean>} Resolves to `true` if successful, `false` otherwise.
|
|
186
|
-
*/
|
|
187
|
-
async function moveFile(oldPath, newPath) {
|
|
188
|
-
try {
|
|
189
|
-
await promises_1.default.rename(oldPath, newPath);
|
|
190
|
-
return true;
|
|
191
|
-
}
|
|
192
|
-
catch (_a) {
|
|
193
|
-
// If rename fails (e.g., across devices), try copy+delete
|
|
194
|
-
try {
|
|
195
|
-
await promises_1.default.copyFile(oldPath, newPath);
|
|
196
|
-
await promises_1.default.unlink(oldPath);
|
|
197
|
-
return true;
|
|
198
|
-
}
|
|
199
|
-
catch (_b) {
|
|
200
|
-
return false;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Gets file stats if the file exists.
|
|
206
|
-
*
|
|
207
|
-
* @param {string} path - Path to the file.
|
|
208
|
-
* @returns {Promise<fs.Stats | null>} File stats object or null if file doesn't exist.
|
|
209
|
-
*/
|
|
210
|
-
async function getFileStats(path) {
|
|
211
|
-
try {
|
|
212
|
-
return await promises_1.default.stat(path);
|
|
213
|
-
}
|
|
214
|
-
catch (_a) {
|
|
215
|
-
return null;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Creates a temporary file with optional content.
|
|
220
|
-
*
|
|
221
|
-
* @param {object} [options] - Options for creating the temp file.
|
|
222
|
-
* @param {string} [options.prefix="tmp-"] - Filename prefix.
|
|
223
|
-
* @param {string} [options.extension=""] - File extension.
|
|
224
|
-
* @param {string} [options.dir] - Directory to create the file in (defaults to OS temp dir).
|
|
225
|
-
* @param {string | Buffer} [options.content] - Optional content to write to the file.
|
|
226
|
-
* @returns {Promise<string>} Path to the created temporary file.
|
|
227
|
-
*/
|
|
228
|
-
async function createTempFile({ prefix = 'tmp-', extension = '', dir = (0, os_1.tmpdir)(), content } = {}) {
|
|
229
|
-
const ext = extension ? (extension.startsWith('.') ? extension : `.${extension}`) : '';
|
|
230
|
-
const filename = `${prefix}${(0, crypto_1.randomUUID)()}${ext}`;
|
|
231
|
-
const filepath = path_1.default.join(dir, filename);
|
|
232
|
-
if (content) {
|
|
233
|
-
await promises_1.default.writeFile(filepath, content);
|
|
234
|
-
}
|
|
235
|
-
else {
|
|
236
|
-
await promises_1.default.writeFile(filepath, '');
|
|
237
|
-
}
|
|
238
|
-
return filepath;
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Streams a file from source to destination.
|
|
242
|
-
* Useful for large files to avoid loading the entire file into memory.
|
|
243
|
-
*
|
|
244
|
-
* @param {string} source - Source file path.
|
|
245
|
-
* @param {string} destination - Destination file path.
|
|
246
|
-
* @returns {Promise<void>} Resolves when streaming completes.
|
|
247
|
-
* @throws {Error} If streaming fails.
|
|
248
|
-
*/
|
|
249
|
-
async function streamFile(source, destination) {
|
|
250
|
-
const readStream = (0, fs_1.createReadStream)(source);
|
|
251
|
-
const writeStream = (0, fs_1.createWriteStream)(destination);
|
|
252
|
-
try {
|
|
253
|
-
await (0, promises_2.pipeline)(readStream, writeStream);
|
|
254
|
-
}
|
|
255
|
-
catch (error) {
|
|
256
|
-
// Ensure both streams are closed in case of error
|
|
257
|
-
readStream.destroy();
|
|
258
|
-
writeStream.destroy();
|
|
259
|
-
throw error;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* Reads a directory and returns file names.
|
|
264
|
-
*
|
|
265
|
-
* @param {string} dirPath - Path to the directory.
|
|
266
|
-
* @param {object} [options] - Options for reading the directory.
|
|
267
|
-
* @param {boolean} [options.fullPaths=false] - Whether to return full paths.
|
|
268
|
-
* @param {RegExp} [options.filter] - Optional regex to filter files.
|
|
269
|
-
* @returns {Promise<string[]>} Array of file names or paths.
|
|
270
|
-
* @throws {Error} If directory cannot be read.
|
|
271
|
-
*/
|
|
272
|
-
async function readDirectory(dirPath, options = {}) {
|
|
273
|
-
const files = await promises_1.default.readdir(dirPath);
|
|
274
|
-
let result = files;
|
|
275
|
-
if (options.filter) {
|
|
276
|
-
result = result.filter(file => options.filter.test(file));
|
|
277
|
-
}
|
|
278
|
-
if (options.fullPaths) {
|
|
279
|
-
result = result.map(file => path_1.default.join(dirPath, file));
|
|
280
|
-
}
|
|
281
|
-
return result;
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Creates a directory if it doesn't exist.
|
|
285
|
-
*
|
|
286
|
-
* @param {string} dirPath - Path to the directory.
|
|
287
|
-
* @param {boolean} [recursive=true] - Whether to create parent directories.
|
|
288
|
-
* @returns {Promise<boolean>} Resolves to `true` if successful, `false` otherwise.
|
|
289
|
-
*/
|
|
290
|
-
async function createDirectory(dirPath, recursive = true) {
|
|
291
|
-
try {
|
|
292
|
-
await promises_1.default.mkdir(dirPath, { recursive });
|
|
293
|
-
return true;
|
|
294
|
-
}
|
|
295
|
-
catch (err) {
|
|
296
|
-
// Consider it success if directory already exists
|
|
297
|
-
return err.code === 'EEXIST';
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* Safely reads and parses a JSON file with error details.
|
|
302
|
-
*
|
|
303
|
-
* @typeParam T - The expected type of the parsed JSON object.
|
|
304
|
-
* @param {string} path - The path to the JSON file.
|
|
305
|
-
* @returns {Promise<{ data: T | null; error: Error | null }>} Object with data and error properties.
|
|
306
|
-
*/
|
|
307
|
-
async function safeReadJsonFile(path) {
|
|
308
|
-
try {
|
|
309
|
-
const content = await promises_1.default.readFile(path, 'utf-8');
|
|
310
|
-
try {
|
|
311
|
-
const data = JSON.parse(content);
|
|
312
|
-
return { data, error: null };
|
|
313
|
-
}
|
|
314
|
-
catch (error) {
|
|
315
|
-
return {
|
|
316
|
-
data: null,
|
|
317
|
-
error: new Error(`Invalid JSON in file ${path}: ${error.message}`)
|
|
318
|
-
};
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
catch (error) {
|
|
322
|
-
return {
|
|
323
|
-
data: null,
|
|
324
|
-
error: new Error(`Failed to read file ${path}: ${error.message}`)
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
/**
|
|
329
|
-
* Checks if a path points to a file (not a directory).
|
|
330
|
-
*
|
|
331
|
-
* @param {string} path - Path to check.
|
|
332
|
-
* @returns {Promise<boolean>} True if the path is a file, false otherwise.
|
|
333
|
-
*/
|
|
334
|
-
async function isFile(path) {
|
|
335
|
-
try {
|
|
336
|
-
const stat = await promises_1.default.stat(path);
|
|
337
|
-
return stat.isFile();
|
|
338
|
-
}
|
|
339
|
-
catch (_a) {
|
|
340
|
-
return false;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
/**
|
|
344
|
-
* Gets the size of a file in bytes.
|
|
345
|
-
*
|
|
346
|
-
* @param {string} path - Path to the file.
|
|
347
|
-
* @returns {Promise<number>} Size in bytes or -1 if file doesn't exist.
|
|
348
|
-
*/
|
|
349
|
-
async function getFileSize(path) {
|
|
350
|
-
try {
|
|
351
|
-
const stat = await promises_1.default.stat(path);
|
|
352
|
-
return stat.size;
|
|
353
|
-
}
|
|
354
|
-
catch (_a) {
|
|
355
|
-
return -1;
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
/**
|
|
359
|
-
* Reads a file as a Buffer.
|
|
360
|
-
*
|
|
361
|
-
* @param {string} path - Path to the file.
|
|
362
|
-
* @returns {Promise<Buffer | null>} File contents as Buffer or null if reading fails.
|
|
363
|
-
*/
|
|
364
|
-
async function readFileBuffer(path) {
|
|
365
|
-
try {
|
|
366
|
-
return await promises_1.default.readFile(path);
|
|
367
|
-
}
|
|
368
|
-
catch (_a) {
|
|
369
|
-
return null;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
//# sourceMappingURL=fs.utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fs.utils.js","sourceRoot":"","sources":["../../../src/utils/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KAAK,UAAU,MAAM,CAAC,IAAY;IACvC,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,kBAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjC,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACI,KAAK,UAAU,WAAW,CAAC,IAAY;IAC5C,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,kBAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjC,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,CAAC,CAAC,CAAC;IACZ,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACI,KAAK,UAAU,cAAc,CAAC,IAAY;IAC/C,IAAI,CAAC;QACH,OAAO,MAAM,kBAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IAAC,WAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["/*\n * The MIT License\n *\n * Copyright (c) 2025 Catbee Technologies. https://catbee-utils.npm.hprasath.com/license\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport { BufferEncoding } from './crypto.utils';\nimport fs from 'fs/promises';\nimport { createReadStream, createWriteStream, Stats } from 'fs';\nimport { tmpdir } from 'os';\nimport path from 'path';\nimport { pipeline } from 'stream/promises';\nimport { randomUUID } from 'crypto';\n\n/**\n * Checks whether a file or directory exists at the given path.\n *\n * @param {string} path - The file or directory path to check.\n * @returns {Promise<boolean>} Resolves to `true` if the path exists, `false` otherwise.\n */\nexport async function fileExists(path: string): Promise<boolean> {\n try {\n await fs.access(path);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Reads and parses a JSON file from the specified path.\n *\n * @typeParam T - The expected type of the parsed JSON object.\n * @param {string} path - The path to the JSON file.\n * @returns {Promise<T | null>} The parsed object, or `null` if reading or parsing fails.\n */\nexport async function readJsonFile<T = any>(path: string): Promise<T | null> {\n try {\n const data = await fs.readFile(path, 'utf-8');\n return JSON.parse(data) as T;\n } catch {\n return null;\n }\n}\n\n/**\n * Writes a JavaScript object to a file as formatted JSON.\n *\n * @param {string} path - The destination file path.\n * @param {any} data - The object to serialize and write.\n * @param {number} [space=2] - Number of spaces for JSON formatting.\n * @returns {Promise<void>} Resolves when writing is complete.\n */\nexport async function writeJsonFile(path: string, data: any, space = 2): Promise<void> {\n const json = JSON.stringify(data, null, space);\n await fs.writeFile(path, json, 'utf-8');\n}\n\n/**\n * Deletes a file if it exists.\n *\n * @param {string} path - The file path to delete.\n * @returns {Promise<boolean>} Resolves to `true` if the file was deleted or didn't exist, `false` if deletion failed.\n */\nexport async function deleteFileIfExists(path: string): Promise<boolean> {\n try {\n await fs.unlink(path);\n return true;\n } catch (err: any) {\n if (err.code === 'ENOENT') return true;\n return false;\n }\n}\n\n/**\n * Reads a text file from the specified path.\n *\n * @param {string} path - The path to the text file.\n * @param {BufferEncoding} [encoding=\"utf-8\"] - The encoding to use.\n * @returns {Promise<string | null>} The file contents, or `null` if reading fails.\n */\nexport async function readTextFile(path: string, encoding: BufferEncoding = 'utf-8'): Promise<string | null> {\n try {\n return await fs.readFile(path, encoding);\n } catch {\n return null;\n }\n}\n\n/**\n * Writes text content to a file.\n *\n * @param {string} path - The destination file path.\n * @param {string} content - The text content to write.\n * @param {BufferEncoding} [encoding=\"utf-8\"] - The encoding to use.\n * @returns {Promise<boolean>} Resolves to `true` if successful, `false` otherwise.\n */\nexport async function writeTextFile(\n path: string,\n content: string,\n encoding: BufferEncoding = 'utf-8'\n): Promise<boolean> {\n try {\n await fs.writeFile(path, content, encoding);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Appends text content to a file.\n *\n * @param {string} path - The file path to append to.\n * @param {string} content - The text content to append.\n * @param {BufferEncoding} [encoding=\"utf-8\"] - The encoding to use.\n * @returns {Promise<boolean>} Resolves to `true` if successful, `false` otherwise.\n */\nexport async function appendTextFile(\n path: string,\n content: string,\n encoding: BufferEncoding = 'utf-8'\n): Promise<boolean> {\n try {\n await fs.appendFile(path, content, encoding);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Copies a file from source to destination.\n *\n * @param {string} source - Source file path.\n * @param {string} destination - Destination file path.\n * @param {boolean} [overwrite=false] - Whether to overwrite if destination exists.\n * @returns {Promise<boolean>} Resolves to `true` if successful, `false` otherwise.\n */\nexport async function copyFile(source: string, destination: string, overwrite = false): Promise<boolean> {\n try {\n const flags = overwrite ? 0 : fs.constants.COPYFILE_EXCL;\n await fs.copyFile(source, destination, flags);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Renames/moves a file.\n *\n * @param {string} oldPath - Current file path.\n * @param {string} newPath - New file path.\n * @returns {Promise<boolean>} Resolves to `true` if successful, `false` otherwise.\n */\nexport async function moveFile(oldPath: string, newPath: string): Promise<boolean> {\n try {\n await fs.rename(oldPath, newPath);\n return true;\n } catch {\n // If rename fails (e.g., across devices), try copy+delete\n try {\n await fs.copyFile(oldPath, newPath);\n await fs.unlink(oldPath);\n return true;\n } catch {\n return false;\n }\n }\n}\n\n/**\n * Gets file stats if the file exists.\n *\n * @param {string} path - Path to the file.\n * @returns {Promise<fs.Stats | null>} File stats object or null if file doesn't exist.\n */\nexport async function getFileStats(path: string): Promise<Stats | null> {\n try {\n return await fs.stat(path);\n } catch {\n return null;\n }\n}\n\n/**\n * Creates a temporary file with optional content.\n *\n * @param {object} [options] - Options for creating the temp file.\n * @param {string} [options.prefix=\"tmp-\"] - Filename prefix.\n * @param {string} [options.extension=\"\"] - File extension.\n * @param {string} [options.dir] - Directory to create the file in (defaults to OS temp dir).\n * @param {string | Buffer} [options.content] - Optional content to write to the file.\n * @returns {Promise<string>} Path to the created temporary file.\n */\nexport async function createTempFile({\n prefix = 'tmp-',\n extension = '',\n dir = tmpdir(),\n content\n}: {\n prefix?: string;\n extension?: string;\n dir?: string;\n content?: string | Buffer;\n} = {}): Promise<string> {\n const ext = extension ? (extension.startsWith('.') ? extension : `.${extension}`) : '';\n const filename = `${prefix}${randomUUID()}${ext}`;\n const filepath = path.join(dir, filename);\n\n if (content) {\n await fs.writeFile(filepath, content);\n } else {\n await fs.writeFile(filepath, '');\n }\n\n return filepath;\n}\n\n/**\n * Streams a file from source to destination.\n * Useful for large files to avoid loading the entire file into memory.\n *\n * @param {string} source - Source file path.\n * @param {string} destination - Destination file path.\n * @returns {Promise<void>} Resolves when streaming completes.\n * @throws {Error} If streaming fails.\n */\nexport async function streamFile(source: string, destination: string): Promise<void> {\n const readStream = createReadStream(source);\n const writeStream = createWriteStream(destination);\n\n try {\n await pipeline(readStream, writeStream);\n } catch (error) {\n // Ensure both streams are closed in case of error\n readStream.destroy();\n writeStream.destroy();\n throw error;\n }\n}\n\n/**\n * Reads a directory and returns file names.\n *\n * @param {string} dirPath - Path to the directory.\n * @param {object} [options] - Options for reading the directory.\n * @param {boolean} [options.fullPaths=false] - Whether to return full paths.\n * @param {RegExp} [options.filter] - Optional regex to filter files.\n * @returns {Promise<string[]>} Array of file names or paths.\n * @throws {Error} If directory cannot be read.\n */\nexport async function readDirectory(\n dirPath: string,\n options: { fullPaths?: boolean; filter?: RegExp } = {}\n): Promise<string[]> {\n const files = await fs.readdir(dirPath);\n\n let result = files;\n\n if (options.filter) {\n result = result.filter(file => options.filter!.test(file));\n }\n\n if (options.fullPaths) {\n result = result.map(file => path.join(dirPath, file));\n }\n\n return result;\n}\n\n/**\n * Creates a directory if it doesn't exist.\n *\n * @param {string} dirPath - Path to the directory.\n * @param {boolean} [recursive=true] - Whether to create parent directories.\n * @returns {Promise<boolean>} Resolves to `true` if successful, `false` otherwise.\n */\nexport async function createDirectory(dirPath: string, recursive = true): Promise<boolean> {\n try {\n await fs.mkdir(dirPath, { recursive });\n return true;\n } catch (err: any) {\n // Consider it success if directory already exists\n return err.code === 'EEXIST';\n }\n}\n\n/**\n * Safely reads and parses a JSON file with error details.\n *\n * @typeParam T - The expected type of the parsed JSON object.\n * @param {string} path - The path to the JSON file.\n * @returns {Promise<{ data: T | null; error: Error | null }>} Object with data and error properties.\n */\nexport async function safeReadJsonFile<T = any>(path: string): Promise<{ data: T | null; error: Error | null }> {\n try {\n const content = await fs.readFile(path, 'utf-8');\n try {\n const data = JSON.parse(content) as T;\n return { data, error: null };\n } catch (error: any) {\n return {\n data: null,\n error: new Error(`Invalid JSON in file ${path}: ${error.message}`)\n };\n }\n } catch (error: any) {\n return {\n data: null,\n error: new Error(`Failed to read file ${path}: ${error.message}`)\n };\n }\n}\n\n/**\n * Checks if a path points to a file (not a directory).\n *\n * @param {string} path - Path to check.\n * @returns {Promise<boolean>} True if the path is a file, false otherwise.\n */\nexport async function isFile(path: string): Promise<boolean> {\n try {\n const stat = await fs.stat(path);\n return stat.isFile();\n } catch {\n return false;\n }\n}\n\n/**\n * Gets the size of a file in bytes.\n *\n * @param {string} path - Path to the file.\n * @returns {Promise<number>} Size in bytes or -1 if file doesn't exist.\n */\nexport async function getFileSize(path: string): Promise<number> {\n try {\n const stat = await fs.stat(path);\n return stat.size;\n } catch {\n return -1;\n }\n}\n\n/**\n * Reads a file as a Buffer.\n *\n * @param {string} path - Path to the file.\n * @returns {Promise<Buffer | null>} File contents as Buffer or null if reading fails.\n */\nexport async function readFileBuffer(path: string): Promise<Buffer | null> {\n try {\n return await fs.readFile(path);\n } catch {\n return null;\n }\n}\n"]}
|
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Complete HTTP status codes enum with descriptions.
|
|
3
|
-
* For use with API responses and error handling.
|
|
4
|
-
*/
|
|
5
|
-
export declare enum HttpStatusCodes {
|
|
6
|
-
/**
|
|
7
|
-
* The server has received the request headers and the client should proceed to send the request body.
|
|
8
|
-
*/
|
|
9
|
-
CONTINUE = 100,
|
|
10
|
-
/**
|
|
11
|
-
* The server is switching protocols according to the client's request.
|
|
12
|
-
*/
|
|
13
|
-
SWITCHING_PROTOCOLS = 101,
|
|
14
|
-
/**
|
|
15
|
-
* Server has received the request and is still processing it.
|
|
16
|
-
*/
|
|
17
|
-
PROCESSING = 102,
|
|
18
|
-
/**
|
|
19
|
-
* The server is sending preliminary headers while preparing the final response.
|
|
20
|
-
*/
|
|
21
|
-
EARLY_HINTS = 103,
|
|
22
|
-
/**
|
|
23
|
-
* The request succeeded. The result meaning depends on the HTTP method used.
|
|
24
|
-
*/
|
|
25
|
-
OK = 200,
|
|
26
|
-
/**
|
|
27
|
-
* The request succeeded and a new resource was created as a result.
|
|
28
|
-
*/
|
|
29
|
-
CREATED = 201,
|
|
30
|
-
/**
|
|
31
|
-
* The request has been received but not yet acted upon.
|
|
32
|
-
*/
|
|
33
|
-
ACCEPTED = 202,
|
|
34
|
-
/**
|
|
35
|
-
* The returned information is from a third-party source, not the origin server.
|
|
36
|
-
*/
|
|
37
|
-
NON_AUTHORITATIVE_INFORMATION = 203,
|
|
38
|
-
/**
|
|
39
|
-
* The request succeeded but there's no content to send in the response.
|
|
40
|
-
*/
|
|
41
|
-
NO_CONTENT = 204,
|
|
42
|
-
/**
|
|
43
|
-
* The client should reset the document view that caused this request.
|
|
44
|
-
*/
|
|
45
|
-
RESET_CONTENT = 205,
|
|
46
|
-
/**
|
|
47
|
-
* The server is delivering only part of the resource due to a range header sent by the client.
|
|
48
|
-
*/
|
|
49
|
-
PARTIAL_CONTENT = 206,
|
|
50
|
-
/**
|
|
51
|
-
* Conveys information about multiple resources, for complex operations.
|
|
52
|
-
*/
|
|
53
|
-
MULTI_STATUS = 207,
|
|
54
|
-
/**
|
|
55
|
-
* The members of a DAV binding have already been enumerated and are not included in the response.
|
|
56
|
-
*/
|
|
57
|
-
ALREADY_REPORTED = 208,
|
|
58
|
-
/**
|
|
59
|
-
* The server has fulfilled a request for the resource, and the response represents the result of one or more instance-manipulations.
|
|
60
|
-
*/
|
|
61
|
-
IM_USED = 226,
|
|
62
|
-
/**
|
|
63
|
-
* The request has more than one possible response and the client should choose one.
|
|
64
|
-
*/
|
|
65
|
-
MULTIPLE_CHOICES = 300,
|
|
66
|
-
/**
|
|
67
|
-
* The resource has been permanently moved to a new URL.
|
|
68
|
-
*/
|
|
69
|
-
MOVED_PERMANENTLY = 301,
|
|
70
|
-
/**
|
|
71
|
-
* The resource has been temporarily moved to another URL.
|
|
72
|
-
*/
|
|
73
|
-
MOVED_TEMPORARILY = 302,
|
|
74
|
-
/**
|
|
75
|
-
* The response to the request can be found under another URI using the GET method.
|
|
76
|
-
*/
|
|
77
|
-
SEE_OTHER = 303,
|
|
78
|
-
/**
|
|
79
|
-
* The resource hasn't been modified since the last request.
|
|
80
|
-
*/
|
|
81
|
-
NOT_MODIFIED = 304,
|
|
82
|
-
/**
|
|
83
|
-
* @deprecated
|
|
84
|
-
* Response must be accessed through a proxy.
|
|
85
|
-
*/
|
|
86
|
-
USE_PROXY = 305,
|
|
87
|
-
/**
|
|
88
|
-
* The resource is temporarily available at a different URI, using the same HTTP method.
|
|
89
|
-
*/
|
|
90
|
-
TEMPORARY_REDIRECT = 307,
|
|
91
|
-
/**
|
|
92
|
-
* The resource has been permanently moved to another URL, using the same HTTP method.
|
|
93
|
-
*/
|
|
94
|
-
PERMANENT_REDIRECT = 308,
|
|
95
|
-
/**
|
|
96
|
-
* The server cannot process the request due to a client error (malformed request).
|
|
97
|
-
*/
|
|
98
|
-
BAD_REQUEST = 400,
|
|
99
|
-
/**
|
|
100
|
-
* Authentication is required and has failed or not been provided.
|
|
101
|
-
*/
|
|
102
|
-
UNAUTHORIZED = 401,
|
|
103
|
-
/**
|
|
104
|
-
* Reserved for future use, originally intended for digital payment systems.
|
|
105
|
-
*/
|
|
106
|
-
PAYMENT_REQUIRED = 402,
|
|
107
|
-
/**
|
|
108
|
-
* The client doesn't have permission to access the requested resource.
|
|
109
|
-
*/
|
|
110
|
-
FORBIDDEN = 403,
|
|
111
|
-
/**
|
|
112
|
-
* The requested resource could not be found on the server.
|
|
113
|
-
*/
|
|
114
|
-
NOT_FOUND = 404,
|
|
115
|
-
/**
|
|
116
|
-
* The request method is not supported for the requested resource.
|
|
117
|
-
*/
|
|
118
|
-
METHOD_NOT_ALLOWED = 405,
|
|
119
|
-
/**
|
|
120
|
-
* The server can't provide a response matching the list of acceptable values in the client's headers.
|
|
121
|
-
*/
|
|
122
|
-
NOT_ACCEPTABLE = 406,
|
|
123
|
-
/**
|
|
124
|
-
* Authentication by a proxy is required.
|
|
125
|
-
*/
|
|
126
|
-
PROXY_AUTHENTICATION_REQUIRED = 407,
|
|
127
|
-
/**
|
|
128
|
-
* The server timed out waiting for the request.
|
|
129
|
-
*/
|
|
130
|
-
REQUEST_TIMEOUT = 408,
|
|
131
|
-
/**
|
|
132
|
-
* The request conflicts with the current state of the server.
|
|
133
|
-
*/
|
|
134
|
-
CONFLICT = 409,
|
|
135
|
-
/**
|
|
136
|
-
* The resource has been permanently deleted with no forwarding address.
|
|
137
|
-
*/
|
|
138
|
-
GONE = 410,
|
|
139
|
-
/**
|
|
140
|
-
* The server requires a Content-Length header field.
|
|
141
|
-
*/
|
|
142
|
-
LENGTH_REQUIRED = 411,
|
|
143
|
-
/**
|
|
144
|
-
* Preconditions in the client's headers failed.
|
|
145
|
-
*/
|
|
146
|
-
PRECONDITION_FAILED = 412,
|
|
147
|
-
/**
|
|
148
|
-
* Request entity is larger than limits defined by server.
|
|
149
|
-
*/
|
|
150
|
-
REQUEST_TOO_LONG = 413,
|
|
151
|
-
/**
|
|
152
|
-
* The request payload exceeds server size limits.
|
|
153
|
-
* Modern equivalent of REQUEST_TOO_LONG.
|
|
154
|
-
*/
|
|
155
|
-
PAYLOAD_TOO_LARGE = 413,
|
|
156
|
-
/**
|
|
157
|
-
* The URI requested is too long for the server to interpret.
|
|
158
|
-
*/
|
|
159
|
-
REQUEST_URI_TOO_LONG = 414,
|
|
160
|
-
/**
|
|
161
|
-
* The server does not support the media type requested by the client.
|
|
162
|
-
*/
|
|
163
|
-
UNSUPPORTED_MEDIA_TYPE = 415,
|
|
164
|
-
/**
|
|
165
|
-
* The range specified by the Range header cannot be fulfilled.
|
|
166
|
-
*/
|
|
167
|
-
REQUESTED_RANGE_NOT_SATISFIABLE = 416,
|
|
168
|
-
/**
|
|
169
|
-
* The server cannot meet the expectations given in the Expect header.
|
|
170
|
-
*/
|
|
171
|
-
EXPECTATION_FAILED = 417,
|
|
172
|
-
/**
|
|
173
|
-
* The server refuses to brew coffee because it is a teapot. (April Fools' joke)
|
|
174
|
-
*/
|
|
175
|
-
IM_A_TEAPOT = 418,
|
|
176
|
-
/**
|
|
177
|
-
* The server cannot store the representation needed to complete the request.
|
|
178
|
-
*/
|
|
179
|
-
INSUFFICIENT_SPACE_ON_RESOURCE = 419,
|
|
180
|
-
/**
|
|
181
|
-
* @deprecated
|
|
182
|
-
* A method has failed - specific to Spring Framework.
|
|
183
|
-
*/
|
|
184
|
-
METHOD_FAILURE = 420,
|
|
185
|
-
/**
|
|
186
|
-
* The server cannot produce a response for the requested URI scheme and authority.
|
|
187
|
-
*/
|
|
188
|
-
MISDIRECTED_REQUEST = 421,
|
|
189
|
-
/**
|
|
190
|
-
* The request was well-formed but has semantic errors preventing processing.
|
|
191
|
-
*/
|
|
192
|
-
UNPROCESSABLE_ENTITY = 422,
|
|
193
|
-
/**
|
|
194
|
-
* The requested resource is locked against access.
|
|
195
|
-
*/
|
|
196
|
-
LOCKED = 423,
|
|
197
|
-
/**
|
|
198
|
-
* The request failed due to the failure of a previous request.
|
|
199
|
-
*/
|
|
200
|
-
FAILED_DEPENDENCY = 424,
|
|
201
|
-
/**
|
|
202
|
-
* The client should switch to a different protocol.
|
|
203
|
-
*/
|
|
204
|
-
UPGRADE_REQUIRED = 426,
|
|
205
|
-
/**
|
|
206
|
-
* The server requires conditional requests to prevent lost updates.
|
|
207
|
-
*/
|
|
208
|
-
PRECONDITION_REQUIRED = 428,
|
|
209
|
-
/**
|
|
210
|
-
* The client has sent too many requests in a given time period (rate limiting).
|
|
211
|
-
*/
|
|
212
|
-
TOO_MANY_REQUESTS = 429,
|
|
213
|
-
/**
|
|
214
|
-
* Request headers are too large for the server to process.
|
|
215
|
-
*/
|
|
216
|
-
REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
|
|
217
|
-
/**
|
|
218
|
-
* Resource cannot be legally provided (e.g., censored by government).
|
|
219
|
-
*/
|
|
220
|
-
UNAVAILABLE_FOR_LEGAL_REASONS = 451,
|
|
221
|
-
/**
|
|
222
|
-
* The server encountered an unexpected error preventing it from fulfilling the request.
|
|
223
|
-
*/
|
|
224
|
-
INTERNAL_SERVER_ERROR = 500,
|
|
225
|
-
/**
|
|
226
|
-
* The server does not support the functionality required to fulfill the request.
|
|
227
|
-
*/
|
|
228
|
-
NOT_IMPLEMENTED = 501,
|
|
229
|
-
/**
|
|
230
|
-
* The server, acting as a gateway, received an invalid response from an upstream server.
|
|
231
|
-
*/
|
|
232
|
-
BAD_GATEWAY = 502,
|
|
233
|
-
/**
|
|
234
|
-
* The server is currently unable to handle the request due to temporary overload or maintenance.
|
|
235
|
-
*/
|
|
236
|
-
SERVICE_UNAVAILABLE = 503,
|
|
237
|
-
/**
|
|
238
|
-
* The server, acting as a gateway, did not receive a timely response from an upstream server.
|
|
239
|
-
*/
|
|
240
|
-
GATEWAY_TIMEOUT = 504,
|
|
241
|
-
/**
|
|
242
|
-
* The server does not support the HTTP protocol version used in the request.
|
|
243
|
-
*/
|
|
244
|
-
HTTP_VERSION_NOT_SUPPORTED = 505,
|
|
245
|
-
/**
|
|
246
|
-
* Transparent content negotiation for the request resulted in circular reference.
|
|
247
|
-
*/
|
|
248
|
-
VARIANT_ALSO_NEGOTIATES = 506,
|
|
249
|
-
/**
|
|
250
|
-
* The server cannot store the representation needed to complete the request.
|
|
251
|
-
*/
|
|
252
|
-
INSUFFICIENT_STORAGE = 507,
|
|
253
|
-
/**
|
|
254
|
-
* The server detected an infinite loop while processing the request.
|
|
255
|
-
*/
|
|
256
|
-
LOOP_DETECTED = 508,
|
|
257
|
-
/**
|
|
258
|
-
* Further extensions to the request are required for the server to fulfill it.
|
|
259
|
-
*/
|
|
260
|
-
NOT_EXTENDED = 510,
|
|
261
|
-
/**
|
|
262
|
-
* The client needs to authenticate to gain network access.
|
|
263
|
-
*/
|
|
264
|
-
NETWORK_AUTHENTICATION_REQUIRED = 511
|
|
265
|
-
}
|
|
266
|
-
//# sourceMappingURL=http-status-codes.d.ts.map
|