UNPKG

funnycode

Version:

obfuscation {js,ts,cjs,mjs} code

50 lines (47 loc) 1.34 kB
import { cwd as cwd$1 } from 'node:process'; import fs from 'fs'; import path from 'path'; const cwd = cwd$1(); const KEYFILE = ".funnycode"; const CONFIG = "funnycode.config"; const CACHE_PATH = winPath(path.join(cwd, "funnycode.cache.json")); function isDir(path2) { return fs.lstatSync(path2).isDirectory(); } function isUnixBashShellPath(path2) { return /\/?\*{1,2}\/?/.test(path2); } function winPath(path2) { return path2.replace(/\\/g, "/"); } const errorMessage = { 0: "Can not find a command, Please use funnycode encode/decode <path>", 1: "Can not find entry config, Please use funnycode encode/decode <path> Or set in the funny.config entry", 2: "Can not find key, Please use funnycode encode/decode <path> --key <key> Or add .funnycode file", 3: "Please encode first , funnycode encode <path>" }; function error(code) { console.error(errorMessage[code]); process.exit(1); } function getKey() { let key; try { key = fs.readFileSync(KEYFILE, "utf8"); } catch (e) { key = void 0; } return key; } let cache; function loadCache() { if (cache) return cache; try { cache = JSON.parse(fs.readFileSync(CACHE_PATH, "utf8")); } catch (e) { cache = {}; } return cache; } export { CACHE_PATH, CONFIG, KEYFILE, cwd, error, getKey, isDir, isUnixBashShellPath, loadCache, winPath };