UNPKG

@squarecloud/blob

Version:
32 lines (30 loc) 944 B
// src/utils/path-like.ts import { readFile } from "fs/promises"; // src/structures/error.ts var SquareCloudBlobError = class _SquareCloudBlobError extends Error { constructor(code, message, cause) { super(message, { cause }); this.name = _SquareCloudBlobError.name; this.message = this.getMessage(code); } getMessage(rawCode) { const code = rawCode.replaceAll("_", " ").toLowerCase().replace(/(^|\s)\S/g, (L) => L.toUpperCase()); const message = this.message ? `: ${this.message}` : ""; return `${code}${message}`; } }; // src/utils/path-like.ts async function parsePathLike(pathLike) { if (typeof pathLike === "string") { const fileBuffer = await readFile(pathLike).catch(() => void 0); if (!fileBuffer) { throw new SquareCloudBlobError("INVALID_FILE", "File not found"); } return fileBuffer; } return pathLike; } export { parsePathLike }; //# sourceMappingURL=path-like.mjs.map