index.js 807 B

123456789101112131415161718192021222324
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = buildMatchPatternFn;
  6. function buildMatchPatternFn(args) {
  7. return function (string) {
  8. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  9. var matchResult = string.match(args.matchPattern);
  10. if (!matchResult) return null;
  11. var matchedString = matchResult[0];
  12. var parseResult = string.match(args.parsePattern);
  13. if (!parseResult) return null;
  14. var value = args.valueCallback ? args.valueCallback(parseResult[0]) : parseResult[0];
  15. value = options.valueCallback ? options.valueCallback(value) : value;
  16. var rest = string.slice(matchedString.length);
  17. return {
  18. value: value,
  19. rest: rest
  20. };
  21. };
  22. }
  23. module.exports = exports.default;