packages-update
Version:
📦 A flexible and lightweight updater for packages
63 lines (62 loc) • 1.69 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLastParam = exports.hasArg = exports.getArg = void 0;
const node_process_1 = __importDefault(require("node:process"));
const [, , ...processArgs] = node_process_1.default.argv;
/**
* Gets the value of an argument.
*
* ---
*
* CLI arguments examples:
*
* ```sh
* command --arg=some # 'some'
* command --arg="" # ''
* command --arg # undefined
* ```
*/
const getArg = (arg, prefix = '--') => {
var _a;
const mountArg = processArgs.find((a) => a.startsWith(`${prefix}${arg}=`));
if (!mountArg)
return undefined;
return (_a = mountArg.split('=')) === null || _a === void 0 ? void 0 : _a[1].replace(/''|""/, '');
};
exports.getArg = getArg;
/**
* Checks if an argument exists.
*
* ---
*
* CLI arguments examples:
*
* ```sh
* command --arg # true
* command # false
* ```
*/
const hasArg = (arg, prefix = '--') => processArgs.some((a) => a.startsWith(`${prefix}${arg}`));
exports.hasArg = hasArg;
/**
* Gets the last param/value.
*
* CLI arguments examples:
*
* ```sh
* command --arg --arg2=some value # 'value'
* command value # 'value'
* command # undefined
* command --arg # undefined
* ```
*/
const getLastParam = (prefix = '--') => {
const lastArg = processArgs[processArgs.length - 1];
if (!lastArg || lastArg.startsWith(prefix))
return undefined;
return lastArg;
};
exports.getLastParam = getLastParam;
;