@haechi-labs/henesis-cli
Version:
🚀 Command Line Interface tool to Utilize henesis
78 lines • 2.56 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const cli_ux_1 = require("cli-ux");
const configstore_1 = tslib_1.__importDefault(require("./common/configstore"));
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
const utc_1 = tslib_1.__importDefault(require("dayjs/plugin/utc"));
dayjs_1.default.extend(utc_1.default);
const now = dayjs_1.default().utc();
exports.emailPrompt = async () => {
return await cli_ux_1.cli.prompt('email');
};
exports.passwordPrompt = async (sentence = 'password') => {
return await cli_ux_1.cli.prompt(sentence, { type: 'hide' });
};
exports.confirmPrompt = async () => {
return await cli_ux_1.cli.confirm(`(y)es or (n)o`);
};
exports.startWait = (sentence) => {
cli_ux_1.cli.action.start(sentence);
};
exports.endWait = () => {
cli_ux_1.cli.action.stop();
};
exports.concatAndDeDuplicate = (...arrs) => [
...new Set([].concat(...arrs)),
];
exports.formatBytes = (bytes, decimals = 2) => {
if (bytes === 0)
return '0 Bytes';
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
};
exports.formatNumbers = (num) => {
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
};
exports.getStartOfThisMonth = () => {
return now.startOf('month').toDate();
};
exports.getStartOfLastMonth = () => {
return now
.subtract(1, 'month')
.startOf('month')
.toDate();
};
exports.getEndOfLastMonth = () => {
return dayjs_1.default(exports.getStartOfThisMonth())
.subtract(1, 'millisecond')
.toDate();
};
exports.getSpecificDayOfMonth = (day) => {
return now
.startOf('month')
.add(day - 1, 'day')
.toDate();
};
exports.getSpecificHourOfDay = (hour) => {
return now
.set('hour', hour)
.startOf('hour')
.toDate();
};
exports.getUserProperty = (property) => {
const user = configstore_1.default.get('user');
if (!user) {
throw new Error('In order to use the Henesis CLI, you need to login first.\n' +
'Please use the henesis login command to get started.');
//TODO: Enhancement: redirect to login prompt
}
if (!user[property]) {
throw new Error('There is no such property.');
}
return user[property];
};
//# sourceMappingURL=utils.js.map