sheetxl
Version:
SheetXL - Command line tool
106 lines (105 loc) • 3.73 kB
JavaScript
/**
* @license sheetxl - SheetXL - Command line tool - v0.7.26
*
* (C) 2025-present SheetXL Inc. & Michael T. Ford
* License: The license can be found at https://www.sheetxl.com/license.
*/
import e from "node:path";
import t from "node:fs";
import o from "chalk";
import { i as n } from "../cli.js";
const r = async (r2, s2, c2, i2) => {
const a2 = e.normalize(r2), l = `read: '${e.join(process.cwd(), a2)}'`, f = await ((r3, s3, c3) => {
const i3 = e.normalize(r3);
try {
t.accessSync(i3, t.constants.F_OK | t.constants.W_OK);
} catch (e2) {
return process.stdout.write(o.redBright(`Unable to read file: '${i3}' at '${process.cwd()}'
`)), null;
}
const a3 = t.readFileSync(i3), l2 = t.statSync(i3);
c3?.(l2);
const f2 = new File([a3], i3);
return n.read({ ...s3, source: f2 });
})(r2, { progress: c2, ...s2 }, (e2) => {
i2?.(l, e2);
});
return f;
}, s = async (t2, o2, r2, s2, c2) => {
const i2 = e.normalize(t2), a2 = `write: '${e.join(process.cwd(), i2)}'`;
c2 && c2?.(a2, null);
return await n.writeFile(i2, o2, { progress: s2, ...r2 });
};
function c(e2) {
const t2 = {}, o2 = [];
for (let n2 = 0; n2 < e2.length; n2++) {
const r2 = e2[n2];
if ("--" === r2) {
o2.push(...e2.slice(n2 + 1));
break;
}
if (r2.startsWith("--")) {
const [o3, s3] = r2.slice(2).split("=", 2);
if (void 0 !== s3) t2[o3] = s3;
else {
const r3 = e2[n2 + 1];
r3 && !r3.startsWith("-") ? (t2[o3] = r3, n2++) : t2[o3] = true;
}
continue;
}
if (/^-[A-Za-z0-9].*=.+$/.test(r2)) {
const e3 = r2.slice(1), o3 = e3.indexOf("=");
t2[e3.slice(0, o3)] = e3.slice(o3 + 1);
continue;
}
if (r2.startsWith("-") && r2.length > 1) {
const o3 = r2.slice(1);
if (1 === o3.length) {
const r3 = o3, s3 = e2[n2 + 1];
s3 && !s3.startsWith("-") ? (t2[r3] = s3, n2++) : t2[r3] = true;
} else for (const e3 of o3) t2[e3] = true;
continue;
}
const s2 = r2.indexOf("=");
s2 > 0 ? t2[r2.slice(0, s2)] = r2.slice(s2 + 1) : o2.push(r2);
}
return { raw: e2, kv: t2, _: o2 };
}
const i = /* @__PURE__ */ new Set(["global", "globalThis", "console", "process", "Buffer", "URL", "URLSearchParams", "setTimeout", "clearTimeout", "setInterval", "clearInterval", "setImmediate", "clearImmediate", "wb", "io", "sdk", "_"]);
function a(e2, t2, o2, n2 = {}) {
const { mode: r2 = "methods", prefix: s2 = null, skip: c2 = /^_/, overwrite: a2 = false } = n2, l = e2.context;
Object.defineProperty(l, o2, { value: t2, configurable: true, enumerable: false });
const f = /* @__PURE__ */ new Set([...Object.getOwnPropertyNames(l), ...Object.getOwnPropertyNames(globalThis)]);
for (const e3 of i) f.add(e3);
let u = t2;
const p = /* @__PURE__ */ new Set();
for (; u && u !== Object.prototype; ) {
for (const e3 of Object.getOwnPropertyNames(u)) {
if ("constructor" === e3) continue;
if (c2 && c2.test(e3)) continue;
const o3 = s2 ? `${s2}${e3}` : e3;
if ((f.has(o3) || p.has(o3)) && !a2) continue;
if (i.has(o3)) continue;
const n3 = Object.getOwnPropertyDescriptor(u, e3);
n3 && ("function" != typeof n3.value ? "all" === r2 && (Object.defineProperty(l, o3, { configurable: true, enumerable: false, get() {
try {
return t2[e3];
} catch {
return;
}
}, set(o4) {
try {
t2[e3] = o4;
} catch {
}
} }), p.add(o3)) : (Object.defineProperty(l, o3, { configurable: true, enumerable: false, value: n3.value.bind(t2) }), p.add(o3)));
}
u = Object.getPrototypeOf(u);
}
}
export {
a as i,
c as p,
r,
s as w
};