@ghini/kit
Version:
js practical tools to assist efficient development
38 lines (37 loc) • 1.16 kB
JavaScript
export { Xdb };
import { rf, wf, mkdir, isdir, xpath, isfile, rm } from "../index.js";
import * as output from "./output.js";
import * as tool from "./tool.js";
const root =
process.platform === "win32"
? "C:/ProgramData/xdb"
: process.platform === "linux"
? "/var/lib/xdb"
: "/usr/local/var/db/xdb";
/**
* 默认系统路径xdb,但指定xdb+任意数字作为新库也是可以的(xdb0 xdb1 xDB2)
* @param {*} dir 兼容大小写敏感,一律处理为小写
*/
function Xdb(dir) {
if (dir) {
dir = xpath(dir);
const last = dir.split("/").at(-1).toLowerCase();
if (last.match(/^xdb\d*$/)) {
dir = dir.replace(/\/xdb(\d*)$/i, "/xdb$1");
} else {
console.error(dir, "路径指定不准确,应指向/xdb或/xdb+数字结尾的文件夹");
return;
}
} else dir = root;
mkdir(dir);
if (!isdir(dir)) {
console.error(dir, "目标文件夹创建失败,检查权限");
return;
}
const xdb = {};
Object.defineProperties(xdb, {
keypath: { value: tool.keypath },
});
Object.defineProperty(xdb, "root", { value: dir, enumerable: true });
return Object.assign(xdb, output);
}