tell-me-when
Version:
human relative date and time parser
20 lines (19 loc) • 764 B
JavaScript
import { tellMeWhen, ParseError } from "./index.mjs";
const expr = process.argv.slice(2).filter(a => !a.startsWith('--')).join(' ');
const iso = process.argv.includes('--iso');
let result;
try {
result = tellMeWhen(expr);
} catch (error) {
if (error instanceof ParseError) {
// eslint-disable-next-line no-console
console.error(expr);
// eslint-disable-next-line no-console
console.error(`${' '.repeat(error.from)}${'^'.repeat(Math.max(1, error.to - error.from))} parse error`);
}
process.exit(1);
}
const formatDate = iso ? d => d.toISOString() : d => d.toLocaleString();
// eslint-disable-next-line no-console
console.log(Array.isArray(result) ? result.map(formatDate).join(' to ') : formatDate(result));
//# sourceMappingURL=cli.mjs.map