├── .editorconfig
├── .eslintrc.json
├── .gitattributes
├── .gitignore
├── .travis.yml
├── .verb.md
├── LICENSE
├── README.md
├── benchmark
├── check.js
├── code
│ ├── brace-expansion.js
│ ├── expand-range.js
│ └── minimatch.js
├── fixtures
│ ├── alpha-lower.js
│ ├── alpha-upper.js
│ ├── padded.js
│ └── range.js
├── index.js
└── last.md
├── index.js
├── package.json
└── test.js
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | indent_style = space
5 | end_of_line = lf
6 | charset = utf-8
7 | indent_size = 2
8 | trim_trailing_whitespace = true
9 | insert_final_newline = true
10 |
11 | [{**/{actual,fixtures,expected,templates}/**,*.md}]
12 | trim_trailing_whitespace = false
13 | insert_final_newline = false
--------------------------------------------------------------------------------
/.eslintrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "ecmaFeatures": {
3 | "modules": true,
4 | "experimentalObjectRestSpread": true
5 | },
6 |
7 | "env": {
8 | "browser": false,
9 | "es6": true,
10 | "node": true,
11 | "mocha": true
12 | },
13 |
14 | "globals": {
15 | "document": false,
16 | "navigator": false,
17 | "window": false
18 | },
19 |
20 | "rules": {
21 | "accessor-pairs": 2,
22 | "arrow-spacing": [2, { "before": true, "after": true }],
23 | "block-spacing": [2, "always"],
24 | "brace-style": [2, "1tbs", { "allowSingleLine": true }],
25 | "comma-dangle": [2, "never"],
26 | "comma-spacing": [2, { "before": false, "after": true }],
27 | "comma-style": [2, "last"],
28 | "constructor-super": 2,
29 | "curly": [2, "multi-line"],
30 | "dot-location": [2, "property"],
31 | "eol-last": 2,
32 | "eqeqeq": [2, "allow-null"],
33 | "generator-star-spacing": [2, { "before": true, "after": true }],
34 | "handle-callback-err": [2, "^(err|error)$" ],
35 | "indent": [2, 2, { "SwitchCase": 1 }],
36 | "key-spacing": [2, { "beforeColon": false, "afterColon": true }],
37 | "keyword-spacing": [2, { "before": true, "after": true }],
38 | "new-cap": [2, { "newIsCap": true, "capIsNew": false }],
39 | "new-parens": 2,
40 | "no-array-constructor": 2,
41 | "no-caller": 2,
42 | "no-class-assign": 2,
43 | "no-cond-assign": 2,
44 | "no-const-assign": 2,
45 | "no-control-regex": 2,
46 | "no-debugger": 2,
47 | "no-delete-var": 2,
48 | "no-dupe-args": 2,
49 | "no-dupe-class-members": 2,
50 | "no-dupe-keys": 2,
51 | "no-duplicate-case": 2,
52 | "no-empty-character-class": 2,
53 | "no-eval": 2,
54 | "no-ex-assign": 2,
55 | "no-extend-native": 2,
56 | "no-extra-bind": 2,
57 | "no-extra-boolean-cast": 2,
58 | "no-extra-parens": [2, "functions"],
59 | "no-fallthrough": 2,
60 | "no-floating-decimal": 2,
61 | "no-func-assign": 2,
62 | "no-implied-eval": 2,
63 | "no-inner-declarations": [2, "functions"],
64 | "no-invalid-regexp": 2,
65 | "no-irregular-whitespace": 2,
66 | "no-iterator": 2,
67 | "no-label-var": 2,
68 | "no-labels": 2,
69 | "no-lone-blocks": 2,
70 | "no-mixed-spaces-and-tabs": 2,
71 | "no-multi-spaces": 2,
72 | "no-multi-str": 2,
73 | "no-multiple-empty-lines": [2, { "max": 1 }],
74 | "no-native-reassign": 0,
75 | "no-negated-in-lhs": 2,
76 | "no-new": 2,
77 | "no-new-func": 2,
78 | "no-new-object": 2,
79 | "no-new-require": 2,
80 | "no-new-wrappers": 2,
81 | "no-obj-calls": 2,
82 | "no-octal": 2,
83 | "no-octal-escape": 2,
84 | "no-proto": 0,
85 | "no-redeclare": 2,
86 | "no-regex-spaces": 2,
87 | "no-return-assign": 2,
88 | "no-self-compare": 2,
89 | "no-sequences": 2,
90 | "no-shadow-restricted-names": 2,
91 | "no-spaced-func": 2,
92 | "no-sparse-arrays": 2,
93 | "no-this-before-super": 2,
94 | "no-throw-literal": 2,
95 | "no-trailing-spaces": 0,
96 | "no-undef": 2,
97 | "no-undef-init": 2,
98 | "no-unexpected-multiline": 2,
99 | "no-unneeded-ternary": [2, { "defaultAssignment": false }],
100 | "no-unreachable": 2,
101 | "no-unused-vars": [2, { "vars": "all", "args": "none" }],
102 | "no-useless-call": 0,
103 | "no-with": 2,
104 | "one-var": [0, { "initialized": "never" }],
105 | "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }],
106 | "padded-blocks": [0, "never"],
107 | "quotes": [2, "single", "avoid-escape"],
108 | "radix": 2,
109 | "semi": [2, "always"],
110 | "semi-spacing": [2, { "before": false, "after": true }],
111 | "space-before-blocks": [2, "always"],
112 | "space-before-function-paren": [2, "never"],
113 | "space-in-parens": [2, "never"],
114 | "space-infix-ops": 2,
115 | "space-unary-ops": [2, { "words": true, "nonwords": false }],
116 | "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }],
117 | "use-isnan": 2,
118 | "valid-typeof": 2,
119 | "wrap-iife": [2, "any"],
120 | "yoda": [2, "never"]
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Enforce Unix newlines
2 | *.* text eol=lf
3 | *.css text eol=lf
4 | *.html text eol=lf
5 | *.js text eol=lf
6 | *.json text eol=lf
7 | *.less text eol=lf
8 | *.md text eol=lf
9 | *.yml text eol=lf
10 |
11 | *.jpg binary
12 | *.gif binary
13 | *.png binary
14 | *.jpeg binary
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # always ignore files
2 | *.DS_Store
3 | *.sublime-*
4 |
5 | # test related, or directories generated by tests
6 | test/actual
7 | actual
8 | coverage
9 | .nyc*
10 |
11 | # npm
12 | node_modules
13 | npm-debug.log
14 |
15 | # yarn
16 | yarn.lock
17 | yarn-error.log
18 |
19 | # misc
20 | _gh_pages
21 | _draft
22 | _drafts
23 | bower_components
24 | vendor
25 | temp
26 | tmp
27 | TODO.md
28 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: false
2 | os:
3 | - linux
4 | - osx
5 | - windows
6 | language: node_js
7 | node_js:
8 | - 'node'
9 | - '11'
10 | - '10'
11 | - '8'
12 | - '4'
13 | - '0.12'
14 | - '0.10'
15 |
--------------------------------------------------------------------------------
/.verb.md:
--------------------------------------------------------------------------------
1 | ## Example usage
2 |
3 | ```js
4 | var expand = require('{%= name %}');
5 | expand('start..end..step', options);
6 |
7 | // examples
8 | console.log(expand('1..3')) //=> ['1', '2', '3']
9 | console.log(expand('1..10..3')) //=> [ '1', '4', '7', '10' ]
10 | ```
11 |
12 | **Params**
13 |
14 | - `start`: the number or letter to start with
15 | - `end`: the number or letter to end with
16 | - `step`: (optional) the step/increment to use. works with letters and numbers.
17 | - `options`: Options object to pass to [fill-range][], or a transform function (see [fill-range][] readme for details and documentation)
18 |
19 | This library wraps [fill-range][] to support range expansion using `..` separated strings. See [fill-range][] for the full list of options and features.
20 |
21 | **Examples**
22 |
23 | ```js
24 | expand('a..e')
25 | //=> ['a', 'b', 'c', 'd', 'e']
26 |
27 | expand('a..e..2')
28 | //=> ['a', 'c', 'e']
29 |
30 | expand('A..E..2')
31 | //=> ['A', 'C', 'E']
32 |
33 | expand('1..3')
34 | //=> ['1', '2', '3']
35 |
36 | expand('0..-5')
37 | //=> [ '0', '-1', '-2', '-3', '-4', '-5' ]
38 |
39 | expand('-9..9..3')
40 | //=> [ '-9', '-6', '-3', '0', '3', '6', '9' ])
41 |
42 | expand('-1..-10..-2')
43 | //=> [ '-1', '-3', '-5', '-7', '-9' ]
44 |
45 | expand('1..10..2')
46 | //=> [ '1', '3', '5', '7', '9' ]
47 | ```
48 |
49 |
50 | ### Custom function
51 |
52 | Optionally pass a custom function as the second argument:
53 |
54 | ```js
55 | expand('a..e', function (val, isNumber, pad, i) {
56 | if (!isNumber) {
57 | return String.fromCharCode(val) + i;
58 | }
59 | return val;
60 | });
61 | //=> ['a0', 'b1', 'c2', 'd3', 'e4']
62 | ```
63 |
64 | ## Benchmarks
65 |
66 | ```sh
67 | {%= docs("benchmark/last.md") %}
68 | ```
69 |
70 | ## History
71 |
72 | ### v2.0.0
73 |
74 | **Changes**
75 |
76 | - Special `step` characters are no longer supported, as the same thing can be accomplished with a custom transform function.
77 | - The signature in the [transform function](https://github.com/jonschlinkert/fill-range#optionstransform) has changed. See [fill-range][] for more details.
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014-present, Jon Schlinkert
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # expand-range [](https://www.npmjs.com/package/expand-range) [](https://npmjs.org/package/expand-range) [](https://npmjs.org/package/expand-range) [](https://travis-ci.org/jonschlinkert/expand-range)
2 |
3 | > Fast, bash-like range expansion. Expand a range of numbers or letters, uppercase or lowercase. Used by micromatch.
4 |
5 | Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
6 |
7 | ## Install
8 |
9 | Install with [npm](https://www.npmjs.com/):
10 |
11 | ```sh
12 | $ npm install --save expand-range
13 | ```
14 |
15 | ## Example usage
16 |
17 | ```js
18 | var expand = require('expand-range');
19 | expand('start..end..step', options);
20 |
21 | // examples
22 | console.log(expand('1..3')) //=> ['1', '2', '3']
23 | console.log(expand('1..10..3')) //=> [ '1', '4', '7', '10' ]
24 | ```
25 |
26 | **Params**
27 |
28 | * `start`: the number or letter to start with
29 | * `end`: the number or letter to end with
30 | * `step`: (optional) the step/increment to use. works with letters and numbers.
31 | * `options`: Options object to pass to [fill-range](https://github.com/jonschlinkert/fill-range), or a transform function (see [fill-range](https://github.com/jonschlinkert/fill-range) readme for details and documentation)
32 |
33 | This library wraps [fill-range](https://github.com/jonschlinkert/fill-range) to support range expansion using `..` separated strings. See [fill-range](https://github.com/jonschlinkert/fill-range) for the full list of options and features.
34 |
35 | **Examples**
36 |
37 | ```js
38 | expand('a..e')
39 | //=> ['a', 'b', 'c', 'd', 'e']
40 |
41 | expand('a..e..2')
42 | //=> ['a', 'c', 'e']
43 |
44 | expand('A..E..2')
45 | //=> ['A', 'C', 'E']
46 |
47 | expand('1..3')
48 | //=> ['1', '2', '3']
49 |
50 | expand('0..-5')
51 | //=> [ '0', '-1', '-2', '-3', '-4', '-5' ]
52 |
53 | expand('-9..9..3')
54 | //=> [ '-9', '-6', '-3', '0', '3', '6', '9' ])
55 |
56 | expand('-1..-10..-2')
57 | //=> [ '-1', '-3', '-5', '-7', '-9' ]
58 |
59 | expand('1..10..2')
60 | //=> [ '1', '3', '5', '7', '9' ]
61 | ```
62 |
63 | ### Custom function
64 |
65 | Optionally pass a custom function as the second argument:
66 |
67 | ```js
68 | expand('a..e', function (val, isNumber, pad, i) {
69 | if (!isNumber) {
70 | return String.fromCharCode(val) + i;
71 | }
72 | return val;
73 | });
74 | //=> ['a0', 'b1', 'c2', 'd3', 'e4']
75 | ```
76 |
77 | ## Benchmarks
78 |
79 | ```sh
80 | [object Object]
81 | ```
82 |
83 | ## History
84 |
85 | ### v2.0.0
86 |
87 | **Changes**
88 |
89 | * Special `step` characters are no longer supported, as the same thing can be accomplished with a custom transform function.
90 | * The signature in the [transform function](https://github.com/jonschlinkert/fill-range#optionstransform) has changed. See [fill-range](https://github.com/jonschlinkert/fill-range) for more details.
91 |
92 | ## About
93 |
94 |
95 | Contributing
96 |
97 | Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
98 |
99 |
100 |
101 |
102 | Running Tests
103 |
104 | Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
105 |
106 | ```sh
107 | $ npm install && npm test
108 | ```
109 |
110 |
111 |
112 |
113 | Building docs
114 |
115 | _(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
116 |
117 | To generate the readme, run the following command:
118 |
119 | ```sh
120 | $ npm install -g verbose/verb#dev verb-generate-readme && verb
121 | ```
122 |
123 |
124 |
125 | ### Related projects
126 |
127 | You might also be interested in these projects:
128 |
129 | * [braces](https://www.npmjs.com/package/braces): Bash-like brace expansion, implemented in JavaScript. Safer than other brace expansion libs, with complete support… [more](https://github.com/micromatch/braces) | [homepage](https://github.com/micromatch/braces "Bash-like brace expansion, implemented in JavaScript. Safer than other brace expansion libs, with complete support for the Bash 4.3 braces specification, without sacrificing speed.")
130 | * [fill-range](https://www.npmjs.com/package/fill-range): Fill in a range of numbers or letters, optionally passing an increment or `step` to… [more](https://github.com/jonschlinkert/fill-range) | [homepage](https://github.com/jonschlinkert/fill-range "Fill in a range of numbers or letters, optionally passing an increment or `step` to use, or create a regex-compatible range with `options.toRegex`")
131 | * [micromatch](https://www.npmjs.com/package/micromatch): Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch. | [homepage](https://github.com/micromatch/micromatch "Glob matching for javascript/node.js. A drop-in replacement and faster alternative to minimatch and multimatch.")
132 |
133 | ### Contributors
134 |
135 | | **Commits** | **Contributor** |
136 | | --- | --- |
137 | | 65 | [jonschlinkert](https://github.com/jonschlinkert) |
138 | | 1 | [dcohenb](https://github.com/dcohenb) |
139 | | 1 | [stevelacy](https://github.com/stevelacy) |
140 |
141 | ### Author
142 |
143 | **Jon Schlinkert**
144 |
145 | * [GitHub Profile](https://github.com/jonschlinkert)
146 | * [Twitter Profile](https://twitter.com/jonschlinkert)
147 | * [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
148 |
149 | ### License
150 |
151 | Copyright © 2018, [Jon Schlinkert](https://github.com/jonschlinkert).
152 | Released under the [MIT License](LICENSE).
153 |
154 | ***
155 |
156 | _This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.8.0, on November 26, 2018._
--------------------------------------------------------------------------------
/benchmark/check.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var path = require('path');
4 | var glob = require('glob');
5 |
6 | /**
7 | * Sanity check
8 | *
9 | * Run to ensure that all fns return the same result.
10 | */
11 |
12 | var fixtures = glob.sync(__dirname + '/fixtures/*.*');
13 |
14 | glob.sync(__dirname + '/code/*.js').forEach(function (fp) {
15 | var fn = require(path.resolve(__dirname, 'code', fp));
16 | var name = path.basename(fp);
17 |
18 | fixtures.forEach(function (fixture) {
19 | console.log(name + ': ' + JSON.stringify(fn.apply(null, require(fixture))));
20 | });
21 | });
22 |
--------------------------------------------------------------------------------
/benchmark/code/brace-expansion.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var expand = require('brace-expansion');
4 |
5 | module.exports = function (str) {
6 | return expand('{' + str + '}');
7 | };
--------------------------------------------------------------------------------
/benchmark/code/expand-range.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var expand = require('../..');
4 |
5 | module.exports = function(str) {
6 | if (Array.isArray(str)) {
7 | return expand.apply(null, str);
8 | }
9 | var res = expand(str);
10 | console.log(res);
11 | return res;
12 | };
13 |
--------------------------------------------------------------------------------
/benchmark/code/minimatch.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var expand = require('minimatch').braceExpand;
4 |
5 | module.exports = function (str) {
6 | return expand('{' + str + '}');
7 | };
--------------------------------------------------------------------------------
/benchmark/fixtures/alpha-lower.js:
--------------------------------------------------------------------------------
1 | module.exports = [['a..d']];
2 |
--------------------------------------------------------------------------------
/benchmark/fixtures/alpha-upper.js:
--------------------------------------------------------------------------------
1 | module.exports = [['A..D']];
2 |
--------------------------------------------------------------------------------
/benchmark/fixtures/padded.js:
--------------------------------------------------------------------------------
1 | module.exports = [['001..050']];
2 |
--------------------------------------------------------------------------------
/benchmark/fixtures/range.js:
--------------------------------------------------------------------------------
1 | module.exports = [['1..5']];
2 |
--------------------------------------------------------------------------------
/benchmark/index.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var Suite = require('benchmarked');
4 | var suite = new Suite({
5 | fixtures: 'fixtures/*.js',
6 | code: 'code/*.js',
7 | cwd: __dirname
8 | });
9 |
10 | suite.run();
11 | // suite.dryRun(function(code, fixture) {
12 | // console.log();
13 | // console.log(code.key);
14 | // console.log('[' + code.run.apply(code, fixture.content).join(',') + ']');
15 | // });
16 |
--------------------------------------------------------------------------------
/benchmark/last.md:
--------------------------------------------------------------------------------
1 | Benchmarking: (4 of 4)
2 | · alpha-lower
3 | · alpha-upper
4 | · padded
5 | · range
6 |
7 | # benchmark/fixtures/alpha-lower.js (29 bytes)
8 | brace-expansion x 105,234 ops/sec ±0.65% (87 runs sampled)
9 | expand-range x 364,206 ops/sec ±1.08% (90 runs sampled)
10 | minimatch x 93,343 ops/sec ±1.61% (86 runs sampled)
11 |
12 | fastest is expand-range
13 |
14 | # benchmark/fixtures/alpha-upper.js (29 bytes)
15 | brace-expansion x 94,729 ops/sec ±0.49% (89 runs sampled)
16 | expand-range x 347,926 ops/sec ±1.11% (83 runs sampled)
17 | minimatch x 89,997 ops/sec ±1.10% (87 runs sampled)
18 |
19 | fastest is expand-range
20 |
21 | # benchmark/fixtures/padded.js (33 bytes)
22 | brace-expansion x 9,948 ops/sec ±0.99% (85 runs sampled)
23 | expand-range x 209,741 ops/sec ±8.85% (83 runs sampled)
24 | minimatch x 9,125 ops/sec ±0.95% (85 runs sampled)
25 |
26 | fastest is expand-range
27 |
28 | # benchmark/fixtures/range.js (29 bytes)
29 | brace-expansion x 75,911 ops/sec ±1.63% (85 runs sampled)
30 | expand-range x 525,728 ops/sec ±1.63% (85 runs sampled)
31 | minimatch x 69,066 ops/sec ±0.55% (86 runs sampled)
32 |
33 | fastest is expand-range
34 |
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | /*!
2 | * expand-range
3 | *
4 | * Copyright (c) 2014-2015, 2017, Jon Schlinkert.
5 | * Released under the MIT License.
6 | */
7 |
8 | 'use strict';
9 |
10 | var extend = require('extend-shallow');
11 | var fill = require('fill-range');
12 |
13 | module.exports = function expandRange(str, options, fn) {
14 | if (typeof str !== 'string') {
15 | throw new TypeError('expand-range expects a string.');
16 | }
17 |
18 | if (typeof options === 'function') {
19 | fn = options;
20 | options = undefined;
21 | }
22 |
23 | // shallow clone options, to ensure we
24 | // don't mutate the object upstream
25 | var opts = extend({}, options);
26 |
27 | if (typeof fn === 'function') {
28 | opts.transform = fn;
29 | }
30 |
31 | if (typeof options === 'boolean') {
32 | opts.makeRe = true;
33 | }
34 |
35 | // create arguments to pass to fill-range
36 | var segs = str.split('..');
37 | var len = segs.length;
38 | if (len > 3) { return str; }
39 |
40 | // if only one segment, it can't expand so return it
41 | if (len === 1) { return segs; }
42 |
43 | // if fn is "true", tell fill-range to regexify the string
44 | if (fn === true) {
45 | opts.toRegex = true;
46 | fn = undefined;
47 | }
48 |
49 | // wrap the result in parentheses, when regexified and necessary
50 | opts.capture = true;
51 | segs.push(opts);
52 |
53 | return fill.apply(null, segs);
54 | };
55 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "expand-range",
3 | "description": "Fast, bash-like range expansion. Expand a range of numbers or letters, uppercase or lowercase. Used by micromatch.",
4 | "version": "2.0.2",
5 | "homepage": "https://github.com/jonschlinkert/expand-range",
6 | "author": "Jon Schlinkert (https://github.com/jonschlinkert)",
7 | "contributors": [
8 | "Daniel Cohen (http://dcb.co.il)",
9 | "Jon Schlinkert (http://twitter.com/jonschlinkert)"
10 | ],
11 | "repository": "jonschlinkert/expand-range",
12 | "bugs": {
13 | "url": "https://github.com/jonschlinkert/expand-range/issues"
14 | },
15 | "license": "MIT",
16 | "files": [
17 | "index.js"
18 | ],
19 | "main": "index.js",
20 | "engines": {
21 | "node": ">=0.10.0"
22 | },
23 | "scripts": {
24 | "test": "mocha"
25 | },
26 | "dependencies": {
27 | "extend-shallow": "^2.0.1",
28 | "fill-range": "^5.0.0"
29 | },
30 | "devDependencies": {
31 | "benchmarked": "^1.1.1",
32 | "brace-expansion": "^1.1.7",
33 | "glob": "^7.1.1",
34 | "gulp-format-md": "^2.0.0",
35 | "minimatch": "^3.0.4",
36 | "mocha": "^3.3.0"
37 | },
38 | "keywords": [
39 | "alpha",
40 | "alphabetical",
41 | "bash",
42 | "brace",
43 | "expand",
44 | "expansion",
45 | "glob",
46 | "match",
47 | "matches",
48 | "matching",
49 | "number",
50 | "numerical",
51 | "range",
52 | "ranges",
53 | "sh"
54 | ],
55 | "verb": {
56 | "plugins": [
57 | "gulp-format-md"
58 | ],
59 | "reflinks": [
60 | "verb",
61 | "fill-range",
62 | "micromatch"
63 | ],
64 | "toc": false,
65 | "layout": "default",
66 | "lint": {
67 | "reflinks": true
68 | },
69 | "tasks": [
70 | "readme"
71 | ],
72 | "related": {
73 | "list": [
74 | "braces",
75 | "fill-range",
76 | "micromatch"
77 | ]
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/test.js:
--------------------------------------------------------------------------------
1 | /*!
2 | * expand-range
3 | *
4 | * Copyright (c) 2014-2015, Jon Schlinkert.
5 | * Licensed under the MIT License
6 | */
7 |
8 | 'use strict';
9 |
10 | require('mocha');
11 | var assert = require('assert');
12 | var expand = require('./');
13 |
14 | describe('expand range', function() {
15 | it('should return the number as an array if no range is specified', function() {
16 | assert.deepEqual(expand('1'), ['1']);
17 | });
18 |
19 | it('should throw when the first arg is not a string.', function() {
20 | assert.throws(function() {
21 | expand();
22 | }, /expand-range expects a string/);
23 | });
24 |
25 | it('should expand numerical ranges', function() {
26 | assert.deepEqual(expand('1..3'), ['1', '2', '3']);
27 | assert.deepEqual(expand('5..8'), ['5', '6', '7', '8']);
28 | });
29 |
30 | it('should expand negative ranges', function() {
31 | assert.deepEqual(expand('0..-5'), ['0', '-1', '-2', '-3', '-4', '-5']);
32 | });
33 |
34 | it('should expand alphabetical ranges', function() {
35 | assert.deepEqual(expand('a..e'), ['a', 'b', 'c', 'd', 'e']);
36 | assert.deepEqual(expand('A..E'), ['A', 'B', 'C', 'D', 'E']);
37 | });
38 |
39 | it('should fill in numerical ranges', function() {
40 | assert.deepEqual(expand('1..3'), ['1', '2', '3']);
41 | assert.deepEqual(expand('5..8'), ['5', '6', '7', '8']);
42 | });
43 |
44 | it('should fill in numerical ranges when numbers are passed as strings', function() {
45 | assert.deepEqual(expand('1..3'), ['1', '2', '3']);
46 | assert.deepEqual(expand('5..8'), ['5', '6', '7', '8']);
47 | });
48 |
49 | it('should fill in negative ranges', function() {
50 | assert.deepEqual(expand('0..-5'), [ '0', '-1', '-2', '-3', '-4', '-5' ]);
51 | assert.deepEqual(expand('0..-5'), [ '0', '-1', '-2', '-3', '-4', '-5' ]);
52 | assert.deepEqual(expand('9..-4'), [ '9', '8', '7', '6', '5', '4', '3', '2', '1', '0', '-1', '-2', '-3', '-4' ]);
53 | assert.deepEqual(expand('-10..-1'), [ '-10', '-9', '-8', '-7', '-6', '-5', '-4', '-3', '-2', '-1' ]);
54 | });
55 |
56 | it('should fill in rangines using the given increment', function() {
57 | assert.deepEqual(expand('1..10'), [ '1', '2', '3', '4', '5', '6', '7', '8', '9', '10' ]);
58 | assert.deepEqual(expand('1..10..1'), [ '1', '2', '3', '4', '5', '6', '7', '8', '9', '10' ]);
59 | assert.deepEqual(expand('1..10..2'), [ '1', '3', '5', '7', '9' ]);
60 | assert.deepEqual(expand('1..10..2'), [ '1', '3', '5', '7', '9' ]);
61 | assert.deepEqual(expand('1..10..2'), [ '1', '3', '5', '7', '9' ]);
62 | assert.deepEqual(expand('1..20..2'), [ '1', '3', '5', '7', '9', '11', '13', '15', '17', '19' ]);
63 | assert.deepEqual(expand('1..20..20'), [ '1' ]);
64 | assert.deepEqual(expand('10..1..-2'), [ '10', '8', '6', '4', '2' ]);
65 | assert.deepEqual(expand('10..1..2'), [ '10', '8', '6', '4', '2' ]);
66 | assert.deepEqual(expand('1..9'), [ '1', '2', '3', '4', '5', '6', '7', '8', '9' ]);
67 | assert.deepEqual(expand('2..10..2'), [ '2', '4', '6', '8', '10' ]);
68 | assert.deepEqual(expand('2..10..1'), [ '2', '3', '4', '5', '6', '7', '8', '9', '10' ]);
69 | assert.deepEqual(expand('2..10..2'), [ '2', '4', '6', '8', '10' ]);
70 | assert.deepEqual(expand('2..10..3'), [ '2', '5', '8' ]);
71 | });
72 |
73 | it('should fill in negative ranges using the given increment', function() {
74 | assert.deepEqual(expand('-1..-10..-2'), [ '-1', '-3', '-5', '-7', '-9' ]);
75 | assert.deepEqual(expand('-1..-10..2'), [ '-1', '-3', '-5', '-7', '-9' ]);
76 | assert.deepEqual(expand('10..1..-2'), [ '10', '8', '6', '4', '2' ]);
77 | assert.deepEqual(expand('-10..-2..2'), [ '-10', '-8', '-6', '-4', '-2' ]);
78 | assert.deepEqual(expand('-2..-10..1'), [ '-2', '-3', '-4', '-5', '-6', '-7', '-8', '-9', '-10' ]);
79 | assert.deepEqual(expand('-2..-10..2'), [ '-2', '-4', '-6', '-8', '-10' ]);
80 | assert.deepEqual(expand('-2..-10..3'), [ '-2', '-5', '-8' ]);
81 | assert.deepEqual(expand('-9..9..3'), [ '-9', '-6', '-3', '0', '3', '6', '9' ]);
82 | });
83 |
84 | it('should fill in negative ranges using the given increment', function() {
85 | assert.deepEqual(expand('1..10..2'), [ '1', '3', '5', '7', '9' ]);
86 | assert.deepEqual(expand('-1..-10..2'), [ '-1', '-3', '-5', '-7', '-9' ]);
87 | assert.deepEqual(expand('-1..-10..-2'), [ '-1', '-3', '-5', '-7', '-9' ]);
88 | assert.deepEqual(expand('10..1..-2'), [ '10', '8', '6', '4', '2' ]);
89 | assert.deepEqual(expand('10..1..2'), [ '10', '8', '6', '4', '2' ]);
90 | assert.deepEqual(expand('1..20..2'), [ '1', '3', '5', '7', '9', '11', '13', '15', '17', '19' ]);
91 | assert.deepEqual(expand('1..20..20'), [ '1' ]);
92 | });
93 |
94 | it('should fill in alphabetical ranges', function() {
95 | assert.deepEqual(expand('a..e'), ['a', 'b', 'c', 'd', 'e']);
96 | assert.deepEqual(expand('A..E'), ['A', 'B', 'C', 'D', 'E']);
97 | assert.deepEqual(expand('E..A'), ['E', 'D', 'C', 'B', 'A']);
98 | });
99 |
100 | it('should use increments with alphabetical ranges', function() {
101 | assert.deepEqual(expand('a..e..2'), ['a','c', 'e']);
102 | assert.deepEqual(expand('E..A..2'), ['E', 'C', 'A']);
103 | });
104 | });
105 |
106 | describe('character classes:', function() {
107 | it('should return a string for a regex range when `true` is passed:', function() {
108 | assert.deepEqual(expand('a..e', true), '[a-e]');
109 | assert.deepEqual(expand('0..9', true), '[0-9]');
110 | assert.deepEqual(expand('A..Z..5', true), '(A|F|K|P|U|Z)');
111 | assert.deepEqual(expand('E..A', true), '[A-E]');
112 | });
113 |
114 |
115 | it('should flip order when a sequential range is backwards', function() {
116 | assert.deepEqual(expand('1023..1021', true), '102[1-3]');
117 | });
118 |
119 | it('should return the string when arguments are invalid:', function() {
120 | assert.equal(expand('1..1..2..1'), '1..1..2..1');
121 | });
122 |
123 | it('should return null for invalid patterns:', function() {
124 | assert.deepEqual(expand('1.1..2.1'), []);
125 | assert.deepEqual(expand('1.2..2'), []);
126 | assert.deepEqual(expand('1.20..2'), []);
127 | assert.deepEqual(expand('1..0f'), []);
128 | assert.deepEqual(expand('1..10..ff'), []);
129 | assert.deepEqual(expand('1..10.f'), []);
130 | assert.deepEqual(expand('1..10f'), []);
131 | assert.deepEqual(expand('1..20..2f'), []);
132 | assert.deepEqual(expand('1..20..f2'), []);
133 | assert.deepEqual(expand('1..2f..2'), []);
134 | assert.deepEqual(expand('1..ff..2'), []);
135 | assert.deepEqual(expand('1..ff'), []);
136 | });
137 | });
138 |
139 | describe('when a custom function is used for expansions', function() {
140 | it('should expose the current value being iterated over', function() {
141 | var res = expand('1..5', function(val, a, b, step, idx, arr, options) {
142 | return String(val);
143 | });
144 | assert.deepEqual(res, ['1', '2', '3', '4', '5']);
145 | });
146 |
147 | it('should expose options', function() {
148 | var res = expand('001..003', function(val, a, b, step, idx, arr, options) {
149 | return Array(options.maxLength - String(val).length).join('0') + val;
150 | });
151 | assert.deepEqual(res, ['001', '002', '003']);
152 | });
153 |
154 | it('should expose options.isNumber', function() {
155 | var res = expand('a..e', function(val, a, b, step, idx, arr, options) {
156 | if (options.isNumber) {
157 | return String.fromCharCode(val);
158 | }
159 | return val;
160 | });
161 | assert.deepEqual(res, ['a', 'b', 'c', 'd', 'e']);
162 | });
163 |
164 | it('should expose the index', function() {
165 | var res = expand('a..e', function(val, a, b, step, idx, arr, options) {
166 | return String.fromCharCode(String(a)) + (idx - 1);
167 | });
168 | assert.deepEqual(res, ['a0', 'b1', 'c2', 'd3', 'e4']);
169 | });
170 | });
171 |
--------------------------------------------------------------------------------