index.js 741 B

12345678910111213141516171819202122232425262728
  1. /**
  2. * The MIT License (MIT)
  3. * Copyright (c) 2017-present Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
  4. */
  5. 'use strict';
  6. var regexpTreeParser = require('./generated/regexp-tree');
  7. /**
  8. * Original parse function.
  9. */
  10. var generatedParseFn = regexpTreeParser.parse.bind(regexpTreeParser);
  11. /**
  12. * Parses a regular expression.
  13. *
  14. * Override original `regexpTreeParser.parse` to convert a value to a string,
  15. * since in regexp-tree we may pass strings, and RegExp instance.
  16. */
  17. regexpTreeParser.parse = function (regexp, options) {
  18. return generatedParseFn('' + regexp, options);
  19. };
  20. // By default do not capture locations; callers may override.
  21. regexpTreeParser.setOptions({ captureLocations: false });
  22. module.exports = regexpTreeParser;