UNPKG

locka

Version:

Simple, elegant encryption ttoolkit. AES, XOR, password generation & CLIβ€”zero dependencies.

43 lines (37 loc) β€’ 1.09 kB
import fs from "fs/promises"; // === Optional Logger (disabled via env flag) === function log(msg, type = "info") { const icons = { info: "πŸ“‚", error: "❌", success: "βœ…" }; if (process.env.LOCKA_SILENT !== "true") { console.log(`${icons[type] || ""} ${msg}`); } } // === File Utilities === // πŸ“– Read file as UTF-8 string export async function readTextFile(path) { try { const data = await fs.readFile(path, "utf8"); log(`Read file: ${path}`, "info"); return data; } catch { throw new Error(`❌ Failed to read: ${path}`); } } // πŸ—‘οΈ Delete file at path export async function deleteFile(path) { try { await fs.unlink(path); log(`Deleted file: ${path}`, "success"); } catch { throw new Error(`❌ Failed to delete: ${path}`); } } // πŸ’Ύ Write string to file export async function writeTextFile(path, content) { try { await fs.writeFile(path, content, "utf8"); log(`Wrote to file: ${path}`, "success"); } catch { throw new Error(`❌ Failed to write: ${path}`); } }