util.js 874 B

123456789101112131415161718192021222324
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.wrap = function (input) {
  4. return typeof input !== 'string' || input.length === 1
  5. ? input.toString()
  6. : "(?:" + input + ")";
  7. };
  8. exports.concat = function () {
  9. var inputs = [];
  10. for (var _i = 0; _i < arguments.length; _i++) {
  11. inputs[_i] = arguments[_i];
  12. }
  13. return inputs.join('');
  14. };
  15. exports.optional = function (input) { return exports.wrap(input) + "?"; };
  16. exports.repeat = function (input, count, max) {
  17. return max === undefined
  18. ? exports.wrap(input) + "{" + count + "}"
  19. : max === Infinity
  20. ? count > 1
  21. ? exports.wrap(input) + "{" + count + ",}"
  22. : count < 1 ? exports.wrap(input) + "*" : exports.wrap(input) + "+"
  23. : exports.wrap(input) + "{" + count + "," + max + "}";
  24. };