index.js 825 B

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