1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*!
  2. * expand-range <https://github.com/jonschlinkert/expand-range>
  3. *
  4. * Copyright (c) 2014-2015, Jon Schlinkert.
  5. * Licensed under the MIT license.
  6. */
  7. 'use strict';
  8. var fill = require('fill-range');
  9. module.exports = function expandRange(str, options, fn) {
  10. if (typeof str !== 'string') {
  11. throw new TypeError('expand-range expects a string.');
  12. }
  13. if (typeof options === 'function') {
  14. fn = options;
  15. options = {};
  16. }
  17. if (typeof options === 'boolean') {
  18. options = {};
  19. options.makeRe = true;
  20. }
  21. // create arguments to pass to fill-range
  22. var opts = options || {};
  23. var args = str.split('..');
  24. var len = args.length;
  25. if (len > 3) { return str; }
  26. // if only one argument, it can't expand so return it
  27. if (len === 1) { return args; }
  28. // if `true`, tell fill-range to regexify the string
  29. if (typeof fn === 'boolean' && fn === true) {
  30. opts.makeRe = true;
  31. }
  32. args.push(opts);
  33. return fill.apply(null, args.concat(fn));
  34. };