@jsse/quick-maths
Version:
101 lines (96 loc) • 3.32 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/cli.ts
var cli_exports = {};
__export(cli_exports, {
cli: () => cli
});
module.exports = __toCommonJS(cli_exports);
var import_node_process = __toESM(require("process"), 1);
// package.json
var version = "0.0.2";
// src/quick-maths.ts
function quickmaths() {
let r = 0;
r += 2 + 2;
r -= 1;
return r;
}
// src/cli.ts
function isDebug() {
const _debugEnvStr = (import_node_process.default.env["DEBUG"] ?? "false").toLowerCase();
const isNotDebug = _debugEnvStr === "false" || _debugEnvStr === "f" || _debugEnvStr === "0";
return !isNotDebug || !import_node_process.default.argv.some((arg) => arg.toLowerCase() === "--debug");
}
function isTest() {
return import_node_process.default.env["NODE_ENV"] === "test";
}
function noop(..._args) {
}
var debug = isDebug() && !isTest() ? (
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument,@typescript-eslint/no-explicit-any
(...args) => console.log(...args)
) : noop;
var echo = isTest() ? noop : console.log;
async function cli(args) {
const argv = args || [];
if (debug) {
debug("Debugging enabled");
}
if (argv.includes("--help") || argv.includes("-h")) {
echo("Usage: quick-maths");
return;
}
if (argv.includes("--version") || argv.includes("-v")) {
echo(`quick-maths v${version}`);
return;
}
const ti = Date.now();
const result = quickmaths();
const tf = Date.now();
echo(
`2 plus 2 that's 4 minus 1 that's ${result} quick maths! (${tf - ti}ms)`
);
}
async function main(args) {
const argv = args || import_node_process.default.argv.slice(2);
await cli(argv);
}
if (import_node_process.default.env["NODE_ENV"] !== "test") {
main().catch((e) => {
console.error(e);
import_node_process.default.exit(1);
}).finally(() => {
import_node_process.default.exit(0);
});
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
cli
});