tell-me-when
Version:
human relative date and time parser
21 lines • 741 B
JavaScript
import { applyDateFns } from "./applyDateFns.mjs";
import { ParseError } from "./ParseError.mjs";
import { ParseRootNode } from "./ParseRootNode.mjs";
import { ParseState } from "./ParseState.mjs";
export function tellMeWhen(when, options) {
return applyDateFns(parse(when, options), options);
}
export function parse(input, {
grammar
}) {
var _tree$find;
const state = new ParseState(input, {
flags: 'gi'
});
const tree = grammar.parse(state);
if (state.index !== input.length) {
throw new ParseError(`syntax error at ${state.index}`, state.index);
}
return ((_tree$find = tree.find(ParseRootNode)) === null || _tree$find === void 0 ? void 0 : _tree$find.dateFns(input)) || [];
}
//# sourceMappingURL=parse.mjs.map