pax_global_header 0000666 0000000 0000000 00000000064 13176254007 0014517 g ustar 00root root 0000000 0000000 52 comment=24a18b1aeb322522e13e438c96697d511ae81f9c
fill-range-5.0.0/ 0000775 0000000 0000000 00000000000 13176254007 0013541 5 ustar 00root root 0000000 0000000 fill-range-5.0.0/.editorconfig 0000664 0000000 0000000 00000000441 13176254007 0016215 0 ustar 00root root 0000000 0000000 # http://editorconfig.org/
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
[{**/{actual,fixtures,expected,templates}/**,*.md}]
trim_trailing_whitespace = false
insert_final_newline = false
fill-range-5.0.0/.eslintrc.json 0000664 0000000 0000000 00000006775 13176254007 0016354 0 ustar 00root root 0000000 0000000 {
"env": {
"browser": false,
"es6": true,
"node": true,
"mocha": true
},
"globals": {
"document": false,
"navigator": false,
"window": false
},
"rules": {
"accessor-pairs": 2,
"arrow-spacing": [2, { "before": true, "after": true }],
"block-spacing": [2, "always"],
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
"comma-dangle": [2, "never"],
"comma-spacing": [2, { "before": false, "after": true }],
"comma-style": [2, "last"],
"constructor-super": 2,
"curly": [2, "multi-line"],
"dot-location": [2, "property"],
"eol-last": 2,
"eqeqeq": [2, "allow-null"],
"generator-star-spacing": [2, { "before": true, "after": true }],
"handle-callback-err": [2, "^(err|error)$" ],
"indent": [2, 2, { "SwitchCase": 1 }],
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
"keyword-spacing": [2, { "before": true, "after": true }],
"new-cap": [2, { "newIsCap": true, "capIsNew": false }],
"new-parens": 2,
"no-array-constructor": 2,
"no-caller": 2,
"no-class-assign": 2,
"no-cond-assign": 2,
"no-const-assign": 2,
"no-control-regex": 2,
"no-debugger": 2,
"no-delete-var": 2,
"no-dupe-args": 2,
"no-dupe-class-members": 2,
"no-dupe-keys": 2,
"no-duplicate-case": 2,
"no-empty-character-class": 2,
"no-eval": 2,
"no-ex-assign": 2,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-extra-boolean-cast": 2,
"no-extra-parens": [2, "functions"],
"no-fallthrough": 2,
"no-floating-decimal": 2,
"no-func-assign": 2,
"no-implied-eval": 2,
"no-inner-declarations": [2, "functions"],
"no-invalid-regexp": 2,
"no-irregular-whitespace": 2,
"no-iterator": 2,
"no-label-var": 2,
"no-labels": 2,
"no-lone-blocks": 2,
"no-mixed-spaces-and-tabs": 2,
"no-multi-spaces": 2,
"no-multi-str": 2,
"no-multiple-empty-lines": [2, { "max": 1 }],
"no-native-reassign": 0,
"no-negated-in-lhs": 2,
"no-new": 2,
"no-new-func": 2,
"no-new-object": 2,
"no-new-require": 2,
"no-new-wrappers": 2,
"no-obj-calls": 2,
"no-octal": 2,
"no-octal-escape": 2,
"no-proto": 0,
"no-redeclare": 2,
"no-regex-spaces": 2,
"no-return-assign": 2,
"no-self-compare": 2,
"no-sequences": 2,
"no-shadow-restricted-names": 2,
"no-spaced-func": 2,
"no-sparse-arrays": 2,
"no-this-before-super": 2,
"no-throw-literal": 2,
"no-trailing-spaces": 0,
"no-undef": 2,
"no-undef-init": 2,
"no-unexpected-multiline": 2,
"no-unneeded-ternary": [2, { "defaultAssignment": false }],
"no-unreachable": 2,
"no-unused-vars": [2, { "vars": "all", "args": "none" }],
"no-useless-call": 0,
"no-with": 2,
"one-var": [0, { "initialized": "never" }],
"operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }],
"padded-blocks": [0, "never"],
"quotes": [2, "single", "avoid-escape"],
"radix": 2,
"semi": [2, "always"],
"semi-spacing": [2, { "before": false, "after": true }],
"space-before-blocks": [2, "always"],
"space-before-function-paren": [2, "never"],
"space-in-parens": [2, "never"],
"space-infix-ops": 2,
"space-unary-ops": [2, { "words": true, "nonwords": false }],
"spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }],
"use-isnan": 2,
"valid-typeof": 2,
"wrap-iife": [2, "any"],
"yoda": [2, "never"]
}
}
fill-range-5.0.0/.gitattributes 0000664 0000000 0000000 00000000177 13176254007 0016441 0 ustar 00root root 0000000 0000000 # Enforce Unix newlines
* text eol=lf
# binaries
*.ai binary
*.psd binary
*.jpg binary
*.gif binary
*.png binary
*.jpeg binary fill-range-5.0.0/.gitignore 0000664 0000000 0000000 00000000446 13176254007 0015535 0 ustar 00root root 0000000 0000000 # always ignore files
*.DS_Store
.idea
*.sublime-*
# test related, or directories generated by tests
test/actual
actual
coverage
.nyc*
# npm
node_modules
npm-debug.log
# yarn
yarn.lock
yarn-error.log
# misc
_gh_pages
_draft
_drafts
bower_components
vendor
temp
tmp
TODO.md
package-lock.json fill-range-5.0.0/.travis.yml 0000664 0000000 0000000 00000000214 13176254007 0015647 0 ustar 00root root 0000000 0000000 sudo: false
os:
- linux
- osx
language: node_js
node_js:
- node
- '9'
- '8'
- '7'
- '6'
- '5'
- '4'
- '0.12'
- '0.10'
fill-range-5.0.0/.verb.md 0000664 0000000 0000000 00000010553 13176254007 0015103 0 ustar 00root root 0000000 0000000 ## Usage
Expands numbers and letters, optionally using a `step` as the last argument. _(Numbers may be defined as JavaScript numbers or strings)_.
```js
var fill = require('{%= name %}');
fill(from, to[, step, options]);
// examples
console.log(fill('1', '10')); //=> '[ '1', '2', '3', '4', '5', '6', '7', '8', '9', '10' ]'
console.log(fill('1', '10', {toRegex: true})); //=> [1-9]|10
```
**Params**
- `from`: **{String|Number}** the number or letter to start with
- `to`: **{String|Number}** the number or letter to end with
- `step`: **{String|Number|Object|Function}** Optionally pass a [step](#optionsstep) to use.
- `options`: **{Object|Function}**: See all available [options](#options)
## Examples
By default, an array of values is returned.
**Alphabetical ranges**
```js
console.log(fill('a', 'e')); //=> ['a', 'b', 'c', 'd', 'e']
console.log(fill('A', 'E')); //=> [ 'A', 'B', 'C', 'D', 'E' ]
```
**Numerical ranges**
Numbers can be defined as actual numbers or strings.
```js
console.log(fill(1, 5)); //=> [ 1, 2, 3, 4, 5 ]
console.log(fill('1', '5')); //=> [ 1, 2, 3, 4, 5 ]
```
**Negative ranges**
Numbers can be defined as actual numbers or strings.
```js
console.log(fill('-5', '-1')); //=> [ '-5', '-4', '-3', '-2', '-1' ]
console.log(fill('-5', '5')); //=> [ '-5', '-4', '-3', '-2', '-1', '0', '1', '2', '3', '4', '5' ]
```
**Steps (increments)**
```js
// numerical ranges with increments
console.log(fill('0', '25', 4)); //=> [ '0', '4', '8', '12', '16', '20', '24' ]
console.log(fill('0', '25', 5)); //=> [ '0', '5', '10', '15', '20', '25' ]
console.log(fill('0', '25', 6)); //=> [ '0', '6', '12', '18', '24' ]
// alphabetical ranges with increments
console.log(fill('a', 'z', 4)); //=> [ 'a', 'e', 'i', 'm', 'q', 'u', 'y' ]
console.log(fill('a', 'z', 5)); //=> [ 'a', 'f', 'k', 'p', 'u', 'z' ]
console.log(fill('a', 'z', 6)); //=> [ 'a', 'g', 'm', 's', 'y' ]
```
## Options
### options.step
**Type**: `number` (formatted as a string or number)
**Default**: `undefined`
**Description**: The increment to use for the range. Can be used with letters or numbers.
**Example(s)**
```js
// numbers
console.log(fill('1', '10', 2)); //=> [ '1', '3', '5', '7', '9' ]
console.log(fill('1', '10', 3)); //=> [ '1', '4', '7', '10' ]
console.log(fill('1', '10', 4)); //=> [ '1', '5', '9' ]
// letters
console.log(fill('a', 'z', 5)); //=> [ 'a', 'f', 'k', 'p', 'u', 'z' ]
console.log(fill('a', 'z', 7)); //=> [ 'a', 'h', 'o', 'v' ]
console.log(fill('a', 'z', 9)); //=> [ 'a', 'j', 's' ]
```
### options.strictRanges
**Type**: `boolean`
**Default**: `false`
**Description**: By default, `null` is returned when an invalid range is passed. Enable this option to throw a `RangeError` on invalid ranges.
**Example(s)**
The following are all invalid:
```js
fill('1.1', '2'); // decimals not supported in ranges
fill('a', '2'); // incompatible range values
fill(1, 10, 'foo'); // invalid "step" argument
```
### options.stringify
**Type**: `boolean`
**Default**: `undefined`
**Description**: Cast all returned values to strings. By default, integers are returned as numbers.
**Example(s)**
```js
console.log(fill(1, 5)); //=> [ 1, 2, 3, 4, 5 ]
console.log(fill(1, 5, {stringify: true})); //=> [ '1', '2', '3', '4', '5' ]
```
### options.toRegex
**Type**: `boolean`
**Default**: `undefined`
**Description**: Create a regex-compatible source string, instead of expanding values to an array.
**Example(s)**
```js
// alphabetical range
console.log(fill('a', 'e', {toRegex: true})); //=> '[a-e]'
// alphabetical with step
console.log(fill('a', 'z', 3, {toRegex: true})); //=> 'a|d|g|j|m|p|s|v|y'
// numerical range
console.log(fill('1', '100', {toRegex: true})); //=> '[1-9]|[1-9][0-9]|100'
// numerical range with zero padding
console.log(fill('000001', '100000', {toRegex: true}));
//=> '0{5}[1-9]|0{4}[1-9][0-9]|0{3}[1-9][0-9]{2}|0{2}[1-9][0-9]{3}|0[1-9][0-9]{4}|100000'
```
### options.transform
**Type**: `function`
**Default**: `undefined`
**Description**: Customize each value in the returned array (or [string](#optionstoRegex)). _(you can also pass this function as the last argument to `fill()`)_.
**Example(s)**
```js
// increase padding by two
var arr = fill('01', '05', function(val, a, b, step, idx, arr, options) {
return repeat('0', (options.maxLength + 2) - val.length) + val;
});
console.log(arr);
//=> ['0001', '0002', '0003', '0004', '0005']
```
fill-range-5.0.0/LICENSE 0000664 0000000 0000000 00000002100 13176254007 0014537 0 ustar 00root root 0000000 0000000 The MIT License (MIT)
Copyright (c) 2014-2017, Jon Schlinkert.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
fill-range-5.0.0/README.md 0000664 0000000 0000000 00000021753 13176254007 0015030 0 ustar 00root root 0000000 0000000 # fill-range [](https://www.npmjs.com/package/fill-range) [](https://npmjs.org/package/fill-range) [](https://npmjs.org/package/fill-range) [](https://travis-ci.org/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`
Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
- [Install](#install)
- [Usage](#usage)
- [Examples](#examples)
- [Options](#options)
* [options.step](#optionsstep)
* [options.strictRanges](#optionsstrictranges)
* [options.stringify](#optionsstringify)
* [options.toRegex](#optionstoregex)
* [options.transform](#optionstransform)
- [About](#about)
_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_
## Install
Install with [npm](https://www.npmjs.com/):
```sh
$ npm install --save fill-range
```
## Usage
Expands numbers and letters, optionally using a `step` as the last argument. _(Numbers may be defined as JavaScript numbers or strings)_.
```js
var fill = require('fill-range');
fill(from, to[, step, options]);
// examples
console.log(fill('1', '10')); //=> '[ '1', '2', '3', '4', '5', '6', '7', '8', '9', '10' ]'
console.log(fill('1', '10', {toRegex: true})); //=> [1-9]|10
```
**Params**
* `from`: **{String|Number}** the number or letter to start with
* `to`: **{String|Number}** the number or letter to end with
* `step`: **{String|Number|Object|Function}** Optionally pass a [step](#optionsstep) to use.
* `options`: **{Object|Function}**: See all available [options](#options)
## Examples
By default, an array of values is returned.
**Alphabetical ranges**
```js
console.log(fill('a', 'e')); //=> ['a', 'b', 'c', 'd', 'e']
console.log(fill('A', 'E')); //=> [ 'A', 'B', 'C', 'D', 'E' ]
```
**Numerical ranges**
Numbers can be defined as actual numbers or strings.
```js
console.log(fill(1, 5)); //=> [ 1, 2, 3, 4, 5 ]
console.log(fill('1', '5')); //=> [ 1, 2, 3, 4, 5 ]
```
**Negative ranges**
Numbers can be defined as actual numbers or strings.
```js
console.log(fill('-5', '-1')); //=> [ '-5', '-4', '-3', '-2', '-1' ]
console.log(fill('-5', '5')); //=> [ '-5', '-4', '-3', '-2', '-1', '0', '1', '2', '3', '4', '5' ]
```
**Steps (increments)**
```js
// numerical ranges with increments
console.log(fill('0', '25', 4)); //=> [ '0', '4', '8', '12', '16', '20', '24' ]
console.log(fill('0', '25', 5)); //=> [ '0', '5', '10', '15', '20', '25' ]
console.log(fill('0', '25', 6)); //=> [ '0', '6', '12', '18', '24' ]
// alphabetical ranges with increments
console.log(fill('a', 'z', 4)); //=> [ 'a', 'e', 'i', 'm', 'q', 'u', 'y' ]
console.log(fill('a', 'z', 5)); //=> [ 'a', 'f', 'k', 'p', 'u', 'z' ]
console.log(fill('a', 'z', 6)); //=> [ 'a', 'g', 'm', 's', 'y' ]
```
## Options
### options.step
**Type**: `number` (formatted as a string or number)
**Default**: `undefined`
**Description**: The increment to use for the range. Can be used with letters or numbers.
**Example(s)**
```js
// numbers
console.log(fill('1', '10', 2)); //=> [ '1', '3', '5', '7', '9' ]
console.log(fill('1', '10', 3)); //=> [ '1', '4', '7', '10' ]
console.log(fill('1', '10', 4)); //=> [ '1', '5', '9' ]
// letters
console.log(fill('a', 'z', 5)); //=> [ 'a', 'f', 'k', 'p', 'u', 'z' ]
console.log(fill('a', 'z', 7)); //=> [ 'a', 'h', 'o', 'v' ]
console.log(fill('a', 'z', 9)); //=> [ 'a', 'j', 's' ]
```
### options.strictRanges
**Type**: `boolean`
**Default**: `false`
**Description**: By default, `null` is returned when an invalid range is passed. Enable this option to throw a `RangeError` on invalid ranges.
**Example(s)**
The following are all invalid:
```js
fill('1.1', '2'); // decimals not supported in ranges
fill('a', '2'); // incompatible range values
fill(1, 10, 'foo'); // invalid "step" argument
```
### options.stringify
**Type**: `boolean`
**Default**: `undefined`
**Description**: Cast all returned values to strings. By default, integers are returned as numbers.
**Example(s)**
```js
console.log(fill(1, 5)); //=> [ 1, 2, 3, 4, 5 ]
console.log(fill(1, 5, {stringify: true})); //=> [ '1', '2', '3', '4', '5' ]
```
### options.toRegex
**Type**: `boolean`
**Default**: `undefined`
**Description**: Create a regex-compatible source string, instead of expanding values to an array.
**Example(s)**
```js
// alphabetical range
console.log(fill('a', 'e', {toRegex: true})); //=> '[a-e]'
// alphabetical with step
console.log(fill('a', 'z', 3, {toRegex: true})); //=> 'a|d|g|j|m|p|s|v|y'
// numerical range
console.log(fill('1', '100', {toRegex: true})); //=> '[1-9]|[1-9][0-9]|100'
// numerical range with zero padding
console.log(fill('000001', '100000', {toRegex: true}));
//=> '0{5}[1-9]|0{4}[1-9][0-9]|0{3}[1-9][0-9]{2}|0{2}[1-9][0-9]{3}|0[1-9][0-9]{4}|100000'
```
### options.transform
**Type**: `function`
**Default**: `undefined`
**Description**: Customize each value in the returned array (or [string](#optionstoRegex)). _(you can also pass this function as the last argument to `fill()`)_.
**Example(s)**
```js
// increase padding by two
var arr = fill('01', '05', function(val, a, b, step, idx, arr, options) {
return repeat('0', (options.maxLength + 2) - val.length) + val;
});
console.log(arr);
//=> ['0001', '0002', '0003', '0004', '0005']
```
## About
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
Running Tests
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:
```sh
$ npm install && npm test
```
Building docs
_(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.)_
To generate the readme, run the following command:
```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```
### Related projects
You might also be interested in these projects:
* [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.")
* [expand-range](https://www.npmjs.com/package/expand-range): Fast, bash-like range expansion. Expand a range of numbers or letters, uppercase or lowercase. Used… [more](https://github.com/jonschlinkert/expand-range) | [homepage](https://github.com/jonschlinkert/expand-range "Fast, bash-like range expansion. Expand a range of numbers or letters, uppercase or lowercase. Used by [micromatch].")
* [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.")
* [to-regex-range](https://www.npmjs.com/package/to-regex-range): Pass two numbers, get a regex-compatible source string for matching ranges. Validated against more than… [more](https://github.com/micromatch/to-regex-range) | [homepage](https://github.com/micromatch/to-regex-range "Pass two numbers, get a regex-compatible source string for matching ranges. Validated against more than 2.78 million test assertions.")
### Contributors
| **Commits** | **Contributor** |
| --- | --- |
| 108 | [jonschlinkert](https://github.com/jonschlinkert) |
| 2 | [paulmillr](https://github.com/paulmillr) |
| 1 | [edorivai](https://github.com/edorivai) |
| 1 | [realityking](https://github.com/realityking) |
| 1 | [wtgtybhertgeghgtwtg](https://github.com/wtgtybhertgeghgtwtg) |
### Author
**Jon Schlinkert**
* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
### License
Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).
***
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on November 01, 2017._ fill-range-5.0.0/benchmark/ 0000775 0000000 0000000 00000000000 13176254007 0015473 5 ustar 00root root 0000000 0000000 fill-range-5.0.0/benchmark/code/ 0000775 0000000 0000000 00000000000 13176254007 0016405 5 ustar 00root root 0000000 0000000 fill-range-5.0.0/benchmark/code/fill-range.js 0000664 0000000 0000000 00000000321 13176254007 0020757 0 ustar 00root root 0000000 0000000 'use strict';
var fill = require('../..');
module.exports = function fn(from, to, step) {
if (Array.isArray(from)) {
return fn.apply(undefined, from);
}
return fill.apply(undefined, arguments);
};
fill-range-5.0.0/benchmark/fixtures/ 0000775 0000000 0000000 00000000000 13176254007 0017344 5 ustar 00root root 0000000 0000000 fill-range-5.0.0/benchmark/fixtures/0001-1000-toregex.js 0000664 0000000 0000000 00000000064 13176254007 0022313 0 ustar 00root root 0000000 0000000 module.exports = ['0001', '1000', {toRegex: true}];
fill-range-5.0.0/benchmark/fixtures/0001-1000.js 0000664 0000000 0000000 00000000043 13176254007 0020635 0 ustar 00root root 0000000 0000000 module.exports = ['0001', '1000'];
fill-range-5.0.0/benchmark/fixtures/001-100.js 0000664 0000000 0000000 00000000041 13176254007 0020473 0 ustar 00root root 0000000 0000000 module.exports = ['001', '100'];
fill-range-5.0.0/benchmark/fixtures/1-100-7.js 0000664 0000000 0000000 00000000042 13176254007 0020500 0 ustar 00root root 0000000 0000000 module.exports = ['1', '100', 7];
fill-range-5.0.0/benchmark/fixtures/1-100.js 0000664 0000000 0000000 00000000037 13176254007 0020340 0 ustar 00root root 0000000 0000000 module.exports = ['1', '100'];
fill-range-5.0.0/benchmark/fixtures/1-1000-7.js 0000664 0000000 0000000 00000000043 13176254007 0020561 0 ustar 00root root 0000000 0000000 module.exports = ['1', '1000', 7];
fill-range-5.0.0/benchmark/fixtures/1-1000-toregex.js 0000664 0000000 0000000 00000000061 13176254007 0022070 0 ustar 00root root 0000000 0000000 module.exports = ['1', '1000', {toRegex: true}];
fill-range-5.0.0/benchmark/fixtures/1-1000.js 0000664 0000000 0000000 00000000040 13176254007 0020412 0 ustar 00root root 0000000 0000000 module.exports = ['1', '1000'];
fill-range-5.0.0/benchmark/fixtures/1-5.js 0000664 0000000 0000000 00000000035 13176254007 0020202 0 ustar 00root root 0000000 0000000 module.exports = ['1', '5'];
fill-range-5.0.0/benchmark/fixtures/2-20-2.js 0000664 0000000 0000000 00000000043 13176254007 0020416 0 ustar 00root root 0000000 0000000 module.exports = ['2', '20', '2'];
fill-range-5.0.0/benchmark/fixtures/a-z.js 0000664 0000000 0000000 00000000035 13176254007 0020367 0 ustar 00root root 0000000 0000000 module.exports = ['a', 'z'];
fill-range-5.0.0/benchmark/index.js 0000664 0000000 0000000 00000001375 13176254007 0017146 0 ustar 00root root 0000000 0000000 'use strict';
var path = require('path');
var util = require('util');
var cyan = require('ansi-cyan');
var argv = require('minimist')(process.argv.slice(2));
var Suite = require('benchmarked');
function run(code, fixtures) {
var suite = new Suite({
cwd: __dirname,
fixtures: 'fixtures/' + fixtures + '.js',
code: 'code/' + code + '*.js'
});
if (argv.dry) {
suite.dryRun(function(code, fixture) {
if (/special/.test(fixture.stem)) return;
console.log(cyan('%s > %s'), code.key, fixture.key);
var args = require(fixture.path);
var res = code.run.apply(null, args);
console.log(util.inspect(res, null, 10));
console.log();
});
} else {
suite.run();
}
}
run(argv._[0] || '*', argv._[1] || '*');
fill-range-5.0.0/benchmark/last.md 0000664 0000000 0000000 00000002406 13176254007 0016762 0 ustar 00root root 0000000 0000000 Benchmarking: (11 of 11)
· 0001-1000-toregex
· 0001-1000
· 001-100
· 1-100-7
· 1-100
· 1-1000-7
· 1-1000-toregex
· 1-1000
· 1-5
· 2-20-2
· a-z
# benchmark/fixtures/0001-1000-toregex.js (52 bytes)
fill-range x 713,367 ops/sec ±1.11% (86 runs sampled)
# benchmark/fixtures/0001-1000.js (35 bytes)
fill-range x 16,956 ops/sec ±0.96% (86 runs sampled)
# benchmark/fixtures/001-100.js (33 bytes)
fill-range x 182,150 ops/sec ±0.92% (87 runs sampled)
# benchmark/fixtures/1-100-7.js (34 bytes)
fill-range x 989,458 ops/sec ±1.01% (88 runs sampled)
# benchmark/fixtures/1-100.js (31 bytes)
fill-range x 338,403 ops/sec ±0.93% (90 runs sampled)
# benchmark/fixtures/1-1000-7.js (35 bytes)
fill-range x 263,486 ops/sec ±1.24% (82 runs sampled)
# benchmark/fixtures/1-1000-toregex.js (49 bytes)
fill-range x 649,917 ops/sec ±1.58% (88 runs sampled)
# benchmark/fixtures/1-1000.js (32 bytes)
fill-range x 39,919 ops/sec ±0.67% (88 runs sampled)
# benchmark/fixtures/1-5.js (29 bytes)
fill-range x 1,451,844 ops/sec ±0.62% (86 runs sampled)
# benchmark/fixtures/2-20-2.js (35 bytes)
fill-range x 1,050,072 ops/sec ±1.11% (87 runs sampled)
# benchmark/fixtures/a-z.js (29 bytes)
fill-range x 230,740 ops/sec ±1.33% (86 runs sampled)
fill-range-5.0.0/examples.js 0000664 0000000 0000000 00000001525 13176254007 0015720 0 ustar 00root root 0000000 0000000 'use strict';
var util = require('util');
var fill = require('./');
var res = [];
var ranges = [
[0, 25, 5],
['-1', '-10', -2],
['-9', '9', 3],
['0', '-5'],
['1', '10', 2],
['1', '3'],
['a', 'e'],
['a', 'e', 2],
['A', 'E'],
['A', 'E', 2],
['1', '10', 2],
['1', '10', 3],
['1', '10', 4],
['a', 'z', 5],
['a', 'z', 7],
['a', 'z', 9],
['-5', '-1'],
['-5', '5'],
['a', 'e', {toRegex: true}],
['a', 'z', 3, {toRegex: true}],
['1', '100', {toRegex: true}],
['1', '1000000', {toRegex: true}],
['001', '100', {toRegex: true}],
['000001', '100000', {toRegex: true}],
].forEach(function(args) {
res.push(example(args))
});
function example(args) {
var str = util.inspect(args).slice(2, -2);
return `console.log(fill(${str})); //=> `
+ util.inspect(fill.apply(null, args))
}
console.log(res.join('\n'))
fill-range-5.0.0/index.js 0000664 0000000 0000000 00000011617 13176254007 0015214 0 ustar 00root root 0000000 0000000 /*!
* fill-range
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Released under the MIT License.
*/
'use strict';
var util = require('util');
var isNumber = require('is-number');
var extend = require('extend-shallow');
var repeat = require('repeat-string');
var toRegex = require('to-regex-range');
/**
* Return a range of numbers or letters.
*
* @param {String} `start` Start of the range
* @param {String} `stop` End of the range
* @param {String} `step` Increment or decrement to use.
* @param {Function} `options`
* @return {Array}
*/
function fillRange(start, stop, step, options) {
if (typeof start === 'undefined') {
return [];
}
if (typeof stop === 'undefined' || start === stop) {
// special case, for handling negative zero
var isString = typeof start === 'string';
if (isNumber(start) && !toNumber(start)) {
return [isString ? '0' : 0];
}
return [start];
}
if (typeof step !== 'number' && typeof step !== 'string') {
options = step;
step = undefined;
}
if (typeof options === 'function') {
options = { transform: options };
}
var opts = extend({step: step}, options);
if (opts.step && !isValidNumber(opts.step)) {
if (opts.strictRanges === true) {
throw new TypeError('expected options.step to be a number');
}
return [];
}
opts.isNumber = isValidNumber(start) && isValidNumber(stop);
if (!opts.isNumber && !isValid(start, stop)) {
if (opts.strictRanges === true) {
throw new RangeError('invalid range arguments: ' + util.inspect([start, stop]));
}
return [];
}
opts.isPadded = isPadded(start) || isPadded(stop);
opts.toString = opts.stringify
|| typeof opts.step === 'string'
|| typeof start === 'string'
|| typeof stop === 'string'
|| !opts.isNumber;
if (opts.isPadded) {
opts.maxLength = Math.max(String(start).length, String(stop).length);
}
// support legacy minimatch/fill-range options
if (typeof opts.optimize === 'boolean') opts.toRegex = opts.optimize;
if (typeof opts.makeRe === 'boolean') opts.toRegex = opts.makeRe;
return expand(start, stop, opts);
}
function expand(start, stop, options) {
var a = options.isNumber ? toNumber(start) : start.charCodeAt(0);
var b = options.isNumber ? toNumber(stop) : stop.charCodeAt(0);
var step = Math.abs(toNumber(options.step)) || 1;
if (options.toRegex && step === 1) {
return toRange(a, b, start, stop, options);
}
var zero = {greater: [], lesser: []};
var asc = a < b;
var arr = new Array(Math.round((asc ? b - a : a - b) / step));
var idx = 0;
while (asc ? a <= b : a >= b) {
var val = options.isNumber ? a : String.fromCharCode(a);
if (options.toRegex && (val >= 0 || !options.isNumber)) {
zero.greater.push(val);
} else {
zero.lesser.push(Math.abs(val));
}
if (options.isPadded) {
val = zeros(val, options);
}
if (options.toString) {
val = String(val);
}
if (typeof options.transform === 'function') {
arr[idx++] = options.transform(val, a, b, step, idx, arr, options);
} else {
arr[idx++] = val;
}
if (asc) {
a += step;
} else {
a -= step;
}
}
if (options.toRegex === true) {
return toSequence(arr, zero, options);
}
return arr;
}
function toRange(a, b, start, stop, options) {
if (options.isPadded) {
return toRegex(start, stop, options);
}
if (options.isNumber) {
return toRegex(Math.min(a, b), Math.max(a, b), options);
}
var start = String.fromCharCode(Math.min(a, b));
var stop = String.fromCharCode(Math.max(a, b));
return '[' + start + '-' + stop + ']';
}
function toSequence(arr, zeros, options) {
var greater = '', lesser = '';
if (zeros.greater.length) {
greater = zeros.greater.join('|');
}
if (zeros.lesser.length) {
lesser = '-(' + zeros.lesser.join('|') + ')';
}
var res = greater && lesser
? greater + '|' + lesser
: greater || lesser;
if (options.capture) {
return '(' + res + ')';
}
return res;
}
function zeros(val, options) {
if (options.isPadded) {
var str = String(val);
var len = str.length;
var dash = '';
if (str.charAt(0) === '-') {
dash = '-';
str = str.slice(1);
}
var diff = options.maxLength - len;
var pad = repeat('0', diff);
val = (dash + pad + str);
}
if (options.stringify) {
return String(val);
}
return val;
}
function toNumber(val) {
return Number(val) || 0;
}
function isPadded(str) {
return /^-?0\d/.test(str);
}
function isValid(min, max) {
return (isValidNumber(min) || isValidLetter(min))
&& (isValidNumber(max) || isValidLetter(max));
}
function isValidLetter(ch) {
return typeof ch === 'string' && ch.length === 1 && /^\w+$/.test(ch);
}
function isValidNumber(n) {
return isNumber(n) && !/\./.test(n);
}
/**
* Expose `fillRange`
* @type {Function}
*/
module.exports = fillRange;
fill-range-5.0.0/package.json 0000664 0000000 0000000 00000003354 13176254007 0016034 0 ustar 00root root 0000000 0000000 {
"name": "fill-range",
"description": "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`",
"version": "5.0.0",
"homepage": "https://github.com/jonschlinkert/fill-range",
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
"contributors": [
"Edo Rivai (edo.rivai.nl)",
"Jon Schlinkert (http://twitter.com/jonschlinkert)",
"Paul Miller (paulmillr.com)",
"Rouven Weßling (www.rouvenwessling.de)",
"(https://github.com/wtgtybhertgeghgtwtg)"
],
"repository": "jonschlinkert/fill-range",
"bugs": {
"url": "https://github.com/jonschlinkert/fill-range/issues"
},
"license": "MIT",
"files": [
"index.js"
],
"main": "index.js",
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "mocha"
},
"dependencies": {
"extend-shallow": "^2.0.1",
"is-number": "^4.0.0",
"repeat-string": "^1.6.1",
"to-regex-range": "^2.1.1"
},
"devDependencies": {
"ansi-cyan": "^0.1.1",
"benchmarked": "^2.0.0",
"gulp-format-md": "^1.0.0",
"minimist": "^1.2.0",
"mocha": "^3.5.0"
},
"keywords": [
"alpha",
"alphabetical",
"array",
"bash",
"brace",
"expand",
"expansion",
"fill",
"glob",
"match",
"matches",
"matching",
"number",
"numerical",
"range",
"ranges",
"regex",
"sh"
],
"verb": {
"related": {
"list": [
"braces",
"expand-range",
"micromatch",
"to-regex-range"
]
},
"toc": true,
"layout": "default",
"tasks": [
"readme"
],
"plugins": [
"gulp-format-md"
],
"lint": {
"reflinks": true
}
}
}
fill-range-5.0.0/test/ 0000775 0000000 0000000 00000000000 13176254007 0014520 5 ustar 00root root 0000000 0000000 fill-range-5.0.0/test/custom-expand.js 0000664 0000000 0000000 00000002427 13176254007 0017652 0 ustar 00root root 0000000 0000000 'use strict';
require('mocha');
var repeat = require('repeat-string');
var isNumber = require('is-number');
var assert = require('assert');
var exact = require('./support/exact');
var fill = require('..');
describe('custom function for expansions:', function() {
it('should expose the current value as the first param.', function() {
var arr = fill(1, 5, function(val, a, b, step, idx, arr, options) {
return val;
});
exact(arr, [1, 2, 3, 4, 5]);
});
it('should expose the `isNumber` boolean as the second param.', function() {
var arr = fill('a', 'e', function(val, a, b, step, idx, arr, options) {
return !isNumber ? String.fromCharCode(val) : val;
});
exact(arr, ['a', 'b', 'c', 'd', 'e']);
});
it('should expose padding `maxLength` on options', function() {
var arr = fill('01', '05', function(val, a, b, step, idx, arr, options) {
// increase padding by two
return repeat('0', (options.maxLength + 2) - val.length) + val;
});
exact(arr, ['0001', '0002', '0003', '0004', '0005']);
});
it('should expose the index as the fifth param.', function() {
var arr = fill('a', 'e', function(val, a, b, step, idx, arr, options) {
return val + (idx - 1);
});
exact(arr, ['a0', 'b1', 'c2', 'd3', 'e4']);
});
});
fill-range-5.0.0/test/matching.js 0000664 0000000 0000000 00000003761 13176254007 0016657 0 ustar 00root root 0000000 0000000 /*!
* fill-range
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Released under the MIT License.
*/
'use strict';
require('mocha');
var assert = require('assert');
var expand = require('./support/expand');
var exact = require('./support/exact');
var fill = require('..');
function toRegex() {
var str = fill.apply(null, arguments);
return new RegExp('^(' + str + ')$');
}
function matcher() {
var regex = toRegex.apply(null, arguments);
return function(num) {
return regex.test(String(num));
};
}
function isMatch() {
var args = [].slice.call(arguments);
var last = args.pop();
var fn = matcher.apply(null, args);
return fn(last);
}
describe('when options.toRegex is used', function() {
it('should create regex ranges for numbers in ascending order', function() {
assert(!isMatch(2, 8, {toRegex: true}, '10'));
assert(isMatch(2, 8, {toRegex: true}, '3'));
assert(isMatch(2, 10, {toRegex: true}, '10'));
assert(isMatch(2, 100, {toRegex: true}, '10'));
assert(!isMatch(2, 100, {toRegex: true}, '101'));
});
it('should create regex ranges with positive and negative numbers', function() {
assert(isMatch(-10, 10, {toRegex: true}, '10'));
assert(isMatch(-10, 10, 2, {toRegex: true}, '10'));
});
it('should create regex ranges for numbers in descending order', function() {
assert(isMatch(8, 2, {toRegex: true}, '2'));
assert(isMatch(8, 2, {toRegex: true}, '8'));
assert(!isMatch(8, 2, {toRegex: true}, '10'));
});
it('should create regex ranges when a step is given', function() {
assert(!isMatch(8, 2, {toRegex: true, step: 2}, '10'));
assert(!isMatch(8, 2, {toRegex: true, step: 2}, '3'));
assert(!isMatch(8, 2, {toRegex: true, step: 2}, '5'));
assert(isMatch(8, 2, {toRegex: true, step: 2}, '8'));
assert(!isMatch(2, 8, {toRegex: true, step: 2}, '10'));
assert(!isMatch(2, 8, {toRegex: true, step: 2}, '3'));
assert(isMatch(2, 8, {toRegex: true, step: 2}, '8'));
});
});
fill-range-5.0.0/test/options.js 0000664 0000000 0000000 00000012273 13176254007 0016556 0 ustar 00root root 0000000 0000000 /*!
* fill-range
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Released under the MIT License.
*/
'use strict';
require('mocha');
var assert = require('assert');
var exact = require('./support/exact');
var fill = require('..');
describe('options', function() {
describe('options.stringify', function() {
it('should cast values to strings', function() {
exact(fill('1', '10', '1', {stringify: true}), ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']);
exact(fill(2, 10, '2', {stringify: true}), ['2', '4', '6', '8', '10']);
exact(fill(2, 10, 1, {stringify: true}), ['2', '3', '4', '5', '6', '7', '8', '9', '10']);
exact(fill(2, 10, 3, {stringify: true}), ['2', '5', '8']);
});
});
describe('options.strict', function() {
it('should return an empty array by default', function() {
assert.deepEqual(fill('1.1', '2.1'), []);
assert.deepEqual(fill('1.2', '2'), []);
assert.deepEqual(fill('1.20', '2'), []);
assert.deepEqual(fill('1', '0f'), []);
assert.deepEqual(fill('1', '10', 'ff'), []);
assert.deepEqual(fill('1', '10.f'), []);
assert.deepEqual(fill('1', '10f'), []);
assert.deepEqual(fill('1', '20', '2f'), []);
assert.deepEqual(fill('1', '20', 'f2'), []);
assert.deepEqual(fill('1', '2f', '2'), []);
assert.deepEqual(fill('1', 'ff', '2'), []);
assert.deepEqual(fill('1', 'ff'), []);
});
it('should throw on invalid range arguments are invalid and options.strict is true.', function() {
assert.throws(function() {
fill('0a', '0z', {strictRanges: true});
}, /invalid range arguments: \[ \'0a\', \'0z\' \]/);
assert.throws(function() {
fill('.', '*', 2, {strictRanges: true});
}, /invalid range arguments: \[ \'\.\', \'\*\' \]/);
assert.throws(function() {
fill('!', '$', {strictRanges: true});
}, /invalid range arguments: \[ \'\!\', \'\$\' \]/);
});
it('should throw when args are incompatible.', function() {
assert.throws(function() {
fill('a8', 10, {strictRanges: true});
}, /invalid range arguments: \[ \'a8\', 10 \]/);
assert.throws(function() {
fill(1, 'zz', {strictRanges: true});
}, /invalid range arguments: \[ 1, \'zz\' \]/);
});
it('should throw when the step is bad.', function() {
assert.throws(function() {
fill('1', '10', 'z', {strictRanges: true});
}, /expected options\.step to be a number/);
assert.throws(function() {
fill('a', 'z', 'a', {strictRanges: true});
}, /expected options\.step to be a number/);
assert.throws(function() {
fill('a', 'z', '0a', {strictRanges: true});
}, /expected options\.step to be a number/);
});
});
describe('options.toRegex', function() {
it('should create regex ranges for numbers in ascending order', function() {
assert.equal(fill(2, 8, {toRegex: true}), '[2-8]');
assert.equal(fill(2, 10, {toRegex: true}), '[2-9]|10');
assert.equal(fill(2, 100, {toRegex: true}), '[2-9]|[1-9][0-9]|100');
});
it('should support zero-padding', function() {
assert.equal(fill('002', '008', {toRegex: true}), '0{2}[2-8]');
assert.equal(fill('02', '08', {toRegex: true}), '0[2-8]');
assert.equal(fill('02', '10', {toRegex: true}), '0[2-9]|10');
assert.equal(fill('002', '100', {toRegex: true}), '0{2}[2-9]|0[1-9][0-9]|100');
});
it('should support negative zero-padding', function() {
assert.equal(fill('-02', '-08', {toRegex: true}), '-0*[2-8]');
assert.equal(fill('-02', '100', {toRegex: true}), '-0*[12]|0{2}[0-9]|0[1-9][0-9]|100');
assert.equal(fill('-02', '-100', {toRegex: true}), '-0*[2-9]|-0*[1-9][0-9]|-0*100');
assert.equal(fill('-002', '-100', {toRegex: true}), '-0*[2-9]|-0*[1-9][0-9]|-0*100');
});
it('should create regex ranges for alpha chars defined in ascending order', function() {
assert.equal(fill('a', 'b', {toRegex: true}), '[a-b]');
assert.equal(fill('A', 'b', {toRegex: true}), '[A-b]');
assert.equal(fill('Z', 'a', {toRegex: true}), '[Z-a]');
});
it('should create regex ranges for alpha chars defined in descending order', function() {
assert.equal(fill('z', 'A', {toRegex: true}), '[A-z]');
});
it('should create regex ranges with positive and negative numbers', function() {
assert.equal(fill(-10, 10, {toRegex: true}), '-[1-9]|-?10|[0-9]');
assert.equal(fill(-10, 10, 2, {toRegex: true}), '0|2|4|6|8|10|-(10|8|6|4|2)');
});
it('should create regex ranges for numbers in descending order', function() {
assert.equal(fill(8, 2, {toRegex: true}), '[2-8]');
});
it('should create regex ranges when a step is given', function() {
assert.equal(fill(8, 2, {toRegex: true, step: 2}), '8|6|4|2');
assert.equal(fill(2, 8, {toRegex: true, step: 2}), '2|4|6|8');
});
});
describe('options.capture', function() {
it('should wrap the returned string in parans', function() {
assert.equal(fill(-10, 10, {toRegex: true, capture: true}), '(-[1-9]|-?10|[0-9])');
assert.equal(fill(-10, 10, 2, {toRegex: true, capture: true}), '(0|2|4|6|8|10|-(10|8|6|4|2))');
});
});
});
fill-range-5.0.0/test/padding.js 0000664 0000000 0000000 00000004646 13176254007 0016476 0 ustar 00root root 0000000 0000000 /*!
* fill-range
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Released under the MIT License.
*/
'use strict';
require('mocha');
var util = require('util');
var assert = require('assert');
var exact = require('./support/exact');
var fill = require('..');
describe('padding: numbers', function() {
it('should pad incremented numbers:', function() {
exact(fill('1', '3'), ['1', '2', '3']);
exact(fill('01', '03'), ['01', '02', '03']);
exact(fill('01', '3'), ['01', '02', '03']);
exact(fill('1', '03'), ['01', '02', '03']);
exact(fill('0001', '0003'), ['0001', '0002', '0003']);
exact(fill('-10', '00'), ['-10', '-09', '-08', '-07', '-06', '-05', '-04', '-03', '-02', '-01', '000']);
exact(fill('05', '010'), ['005','006','007','008','009','010']);
exact(fill('05', '100'), ['005','006','007','008','009','010','011','012','013','014','015','016','017','018','019','020','021','022','023','024','025','026','027','028','029','030','031','032','033','034','035','036','037','038','039','040','041','042','043','044','045','046','047','048','049','050','051','052','053','054','055','056','057','058','059','060','061','062','063','064','065','066','067','068','069','070','071','072','073','074','075','076','077','078','079','080','081','082','083','084','085','086','087','088','089','090','091','092','093','094','095','096','097','098','099','100']);
});
it('should pad decremented numbers:', function() {
exact(fill('03', '01'), ['03', '02', '01']);
exact(fill('3', '01'), ['03', '02', '01']);
exact(fill('003', '1'), ['003', '002', '001']);
exact(fill('003', '001'), ['003', '002', '001']);
exact(fill('3', '001'), ['003', '002', '001']);
exact(fill('03', '001'), ['003', '002', '001']);
});
it('should pad stepped numbers', function() {
exact(fill('1', '05', '3'), ['01','04']);
exact(fill('1', '005', '3'), ['001','004']);
exact(fill('00', '1000', '200'), ['0000','0200', '0400', '0600', '0800', '1000']);
exact(fill('0', '01000', '200'), ['00000','00200', '00400', '00600', '00800', '01000']);
exact(fill('001', '5', '3'), ['001','004']);
exact(fill('02', '10', 2), ['02', '04', '06', '08', '10']);
exact(fill('002', '10', 2), ['002', '004', '006', '008', '010']);
exact(fill('002', '010', 2), ['002', '004', '006', '008', '010']);
exact(fill('-04', 4, 2), ['-04', '-02', '000', '002', '004']);
});
});
fill-range-5.0.0/test/ranges.js 0000664 0000000 0000000 00000010600 13176254007 0016332 0 ustar 00root root 0000000 0000000 /*!
* fill-range
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Released under the MIT License.
*/
'use strict';
require('mocha');
var assert = require('assert');
var exact = require('./support/exact');
var fill = require('..');
describe('ranges', function() {
describe('alphabetical', function() {
it('should increment alphabetical ranges', function() {
exact(fill('a'), ['a']);
exact(fill('a', 'a'), ['a']);
exact(fill('a', 'b'), ['a', 'b']);
exact(fill('a', 'e'), ['a', 'b', 'c', 'd', 'e']);
exact(fill('A', 'E'), ['A', 'B', 'C', 'D', 'E']);
});
it('should decrement alphabetical ranges', function() {
exact(fill('E', 'A'), ['E', 'D', 'C', 'B', 'A']);
exact(fill('a', 'C'), ['a','`','_','^',']',"\\",'[','Z','Y','X','W','V','U','T','S','R','Q','P','O','N','M','L','K','J','I','H','G','F','E','D','C']);
exact(fill('z', 'm'), ['z', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p', 'o', 'n', 'm']);
});
});
describe('alphanumeric', function() {
it('should increment alphanumeric ranges', function() {
exact(fill('9', 'B'), ['9', ':', ';', '<', '=', '>', '?', '@', 'A', 'B']);
exact(fill('A', '10'), ['A', '@', '?', '>', '=', '<', ';', ':', '9', '8', '7', '6', '5', '4', '3', '2', '1']);
exact(fill('a', '10'), ['a', '`', '_', '^', ']', '\\', '[', 'Z', 'Y', 'X', 'W', 'V', 'U', 'T', 'S', 'R', 'Q', 'P', 'O', 'N', 'M', 'L', 'K', 'J', 'I', 'H', 'G', 'F', 'E', 'D', 'C', 'B', 'A', '@', '?', '>', '=', '<', ';', ':', '9', '8', '7', '6', '5', '4', '3', '2', '1']);
});
it('should step alphanumeric ranges', function() {
exact(fill('9', 'B', 3), [ '9', '<', '?', 'B' ]);
});
it('should decrement alphanumeric ranges', function() {
exact(fill('C', '9'), ['C', 'B', 'A', '@', '?', '>', '=', '<', ';', ':', '9']);
});
});
describe('ranges: letters', function() {
it('should increment alphabetical ranges', function() {
exact(fill('a'), ['a']);
exact(fill('a', 'a'), ['a']);
exact(fill('a', 'b'), ['a', 'b']);
exact(fill('a', 'e'), ['a', 'b', 'c', 'd', 'e']);
exact(fill('A', 'E'), ['A', 'B', 'C', 'D', 'E']);
});
it('should decrement alphabetical ranges', function() {
exact(fill('E', 'A'), ['E', 'D', 'C', 'B', 'A']);
exact(fill('a', 'C'), ['a','`','_','^',']',"\\",'[','Z','Y','X','W','V','U','T','S','R','Q','P','O','N','M','L','K','J','I','H','G','F','E','D','C']);
exact(fill('z', 'm'), ['z', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p', 'o', 'n', 'm']);
});
});
describe('numbers', function() {
it('should increment numerical *string* ranges', function() {
exact(fill('1'), ['1']);
exact(fill('1', '1'), ['1']);
exact(fill('1', '2'), ['1', '2']);
exact(fill('1', '10'), ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']);
exact(fill('1', '3'), ['1', '2', '3']);
exact(fill('5', '8'), ['5', '6', '7', '8']);
exact(fill(1, '9'), ['1', '2', '3', '4', '5', '6', '7', '8', '9']);
});
it('should increment numerical *number* ranges', function() {
exact(fill(1, 3), [1, 2, 3]);
exact(fill(1, 9), [1, 2, 3, 4, 5, 6, 7, 8, 9]);
exact(fill(5, 8), [5, 6, 7, 8]);
});
it('should increment numerical ranges that are a combination of number and string', function() {
exact(fill(1, '9'), ['1', '2', '3', '4', '5', '6', '7', '8', '9']);
exact(fill('2', 5), ['2', '3', '4', '5']);
});
it('should decrement numerical *string* ranges', function() {
exact(fill('0', '-5'), ['0', '-1', '-2', '-3', '-4', '-5']);
exact(fill('-1', '-5'), ['-1', '-2', '-3', '-4', '-5']);
});
it('should decrement numerical *number* ranges', function() {
exact(fill(-10, -1), [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1]);
exact(fill(0, -5), [0, -1, -2, -3, -4, -5]);
});
it('should handle *string* ranges ranges that are positive and negative:', function() {
exact(fill('9', '-4'), ['9', '8', '7', '6', '5', '4', '3', '2', '1', '0', '-1', '-2', '-3', '-4']);
exact(fill('-5', '5'), ['-5', '-4', '-3', '-2', '-1', '0', '1', '2', '3', '4', '5']);
});
it('should handle *number* ranges ranges that are positive and negative:', function() {
exact(fill(9, -4), [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4]);
exact(fill(-5, 5), [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]);
});
});
});
fill-range-5.0.0/test/special.js 0000664 0000000 0000000 00000002204 13176254007 0016474 0 ustar 00root root 0000000 0000000 /*!
* fill-range
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Released under the MIT License.
*/
'use strict';
require('mocha');
var assert = require('assert');
var exact = require('./support/exact');
var fill = require('..');
describe('special cases', function() {
describe('negative zero', function() {
it('should handle negative zero', function() {
exact(fill('-5', '-0', '-1'), ['-5', '-4', '-3', '-2', '-1', '0']);
exact(fill('1', '-0', 1), ['1', '0']);
exact(fill('1', '-0', 0), ['1', '0']);
exact(fill('1', '-0', '0'), ['1', '0']);
exact(fill('1', '-0', '1'), ['1', '0']);
exact(fill('-0', '-0', '1'), ['0']);
exact(fill('-0', '0', '1'), ['0']);
exact(fill('-0', '5', '1'), ['0', '1', '2', '3', '4', '5']);
exact(fill(-0, 5), [0, 1, 2, 3, 4, 5]);
exact(fill(5, -0, 5), [5, 0]);
exact(fill(5, -0, 2), [5, 3, 1]);
exact(fill(0, 5, 2), [0, 2, 4]);
});
it('should adjust padding for negative numbers:', function() {
exact(fill('-01', '5'), ['-01','000','001','002','003','004','005']);
});
});
});
fill-range-5.0.0/test/steps.js 0000664 0000000 0000000 00000007335 13176254007 0016224 0 ustar 00root root 0000000 0000000 /*!
* fill-range
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Released under the MIT License.
*/
'use strict';
require('mocha');
var assert = require('assert');
var exact = require('./support/exact');
var fill = require('..');
describe('steps', function() {
describe('steps: numbers', function() {
it('should increment ranges using the given step', function() {
exact(fill('1', '10', '1'), ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']);
exact(fill('1', '10', '2'), ['1', '3', '5', '7', '9']);
exact(fill('0', '1000', '200'), ['0','200', '400', '600', '800', '1000']);
exact(fill('1', '10', 2), ['1', '3', '5', '7', '9']);
exact(fill('1', '20', '2'), ['1', '3', '5', '7', '9', '11', '13', '15', '17', '19']);
exact(fill('1', '20', '20'), ['1']);
exact(fill('10', '1', '2'), ['10', '8', '6', '4', '2']);
exact(fill('10', '1', '-2'), ['10', '8', '6', '4', '2']);
exact(fill('10', '1', '2'), ['10', '8', '6', '4', '2']);
exact(fill(2, 10, '2'), ['2', '4', '6', '8', '10']);
exact(fill(2, 10, 1), [2, 3, 4, 5, 6, 7, 8, 9, 10]);
exact(fill(2, 10, 2), [2, 4, 6, 8, 10]);
exact(fill(2, 10, 3), [2, 5, 8]);
exact(fill(0, 5, 2), [0, 2, 4]);
exact(fill(5, 0, 2), [5, 3, 1]);
exact(fill(1, 5, 2), [1, 3, 5]);
exact(fill(2, '10', '2'), ['2', '4', '6', '8', '10']);
exact(fill(2, '10', 1), ['2', '3', '4', '5', '6', '7', '8', '9', '10']);
exact(fill(2, '10', '2'), ['2', '4', '6', '8', '10']);
exact(fill('2', 10, '3'), ['2', '5', '8']);
});
it('should fill in negative ranges using the given step (strings)', function() {
exact(fill('0', '-10', '-2'), ['0', '-2', '-4', '-6', '-8', '-10']);
exact(fill('-0', '-10', '-2'), ['0', '-2', '-4', '-6', '-8', '-10']);
exact(fill('-1', '-10', '-2'), ['-1', '-3', '-5', '-7', '-9']);
exact(fill('-1', '-10', '2'), ['-1', '-3', '-5', '-7', '-9']);
exact(fill('1', '10', '2'), ['1', '3', '5', '7', '9']);
exact(fill('1', '20', '2'), ['1', '3', '5', '7', '9', '11', '13', '15', '17', '19']);
exact(fill('1', '20', '20'), ['1']);
exact(fill('10', '1', '-2'), ['10', '8', '6', '4', '2']);
exact(fill('-10', '0', '2'), ['-10', '-8', '-6', '-4', '-2', '0']);
exact(fill('-10', '-0', '2'), ['-10', '-8', '-6', '-4', '-2', '0']);
exact(fill('-0', '-10', '0'), ['0', '-1', '-2', '-3', '-4', '-5', '-6', '-7', '-8', '-9', '-10']);
exact(fill('0', '-10', '-0'), ['0', '-1', '-2', '-3', '-4', '-5', '-6', '-7', '-8', '-9', '-10']);
});
it('should fill in negative ranges using the given step (numbers)', function() {
exact(fill(-10, 0, 2), [-10, -8, -6, -4, -2, 0]);
exact(fill(-10, -2, 2), [-10, -8, -6, -4, -2]);
exact(fill(-2, -10, 1), [-2, -3, -4, -5, -6, -7, -8, -9, -10]);
exact(fill(0, -10, 2), [0, -2, -4, -6, -8, -10]);
exact(fill(-2, -10, 2), [-2, -4, -6, -8, -10]);
exact(fill(-2, -10, 3), [-2, -5, -8]);
exact(fill(-9, 9, 3), [-9, -6, -3, 0, 3, 6, 9]);
});
it('should fill in negative ranges when negative zero is passed', function() {
exact(fill(-10, -0, 2), [-10, -8, -6, -4, -2, 0]);
exact(fill(-0, -10, 2), [0, -2, -4, -6, -8, -10]);
});
});
describe('steps: letters', function() {
it('should use increments with alphabetical ranges', function() {
exact(fill('a', 'e', 2), ['a','c', 'e']);
exact(fill('E', 'A', 2), ['E', 'C', 'A']);
});
});
describe('options: step', function() {
it('should use the step defined on the options:', function() {
var opts = { step: 2 };
exact(fill('a', 'e', opts), ['a','c', 'e']);
exact(fill('E', 'A', opts), ['E', 'C', 'A']);
});
});
});
fill-range-5.0.0/test/support/ 0000775 0000000 0000000 00000000000 13176254007 0016234 5 ustar 00root root 0000000 0000000 fill-range-5.0.0/test/support/exact.js 0000664 0000000 0000000 00000000513 13176254007 0017675 0 ustar 00root root 0000000 0000000 'use strict';
var util = require('util');
var assert = require('assert');
module.exports = function exact(a, b) {
assert(Array.isArray(a));
assert(Array.isArray(b));
var aString = util.inspect(a, null, 10);
var bString = util.inspect(b, null, 10);
assert.strictEqual(aString, bString, aString + ' !== ' + bString);
};
fill-range-5.0.0/test/support/expand.js 0000664 0000000 0000000 00000000357 13176254007 0020056 0 ustar 00root root 0000000 0000000 'use strict';
module.exports = function toRange(start, stop, step) {
step = step || 1;
var arr = new Array((stop - start) / step);
var num = 0;
for (var i = start; i <= stop; i += step) {
arr[num++] = i;
}
return arr;
};
fill-range-5.0.0/test/verify-matches.js 0000664 0000000 0000000 00000005306 13176254007 0020010 0 ustar 00root root 0000000 0000000 /*!
* fill-range
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Released under the MIT License.
*/
'use strict';
require('mocha');
var assert = require('assert');
var expand = require('./support/expand');
var exact = require('./support/exact');
var fill = require('..');
var count = 0;
function toRegex() {
var str = fill.apply(null, arguments);
return new RegExp('^(' + str + ')$');
}
function matcher() {
var regex = toRegex.apply(null, arguments);
return function(num) {
return regex.test(String(num));
};
}
function verifyRange(min, max, from, to) {
var fn = matcher(min, max, {makeRe: true});
var range = expand(from, to);
var len = range.length, i = -1;
while (++i < len) {
var num = range[i];
if (min <= num && num <= max) {
assert(fn(num));
} else {
assert(!fn(num));
}
count++;
}
}
describe('validate ranges', function() {
after(function() {
var num = (+(+(count).toFixed(2))).toLocaleString();
console.log();
console.log(' ', num, 'patterns tested');
});
it('should support equal numbers:', function() {
verifyRange(1, 1, 0, 100);
verifyRange(65443, 65443, 65000, 66000);
verifyRange(192, 1000, 0, 1000);
});
it('should support large numbers:', function() {
verifyRange(100019999300000, 100020000300000, 100019999999999, 100020000100000);
});
it('should support repeated digits:', function() {
verifyRange(10331, 20381, 0, 99999);
});
it('should support repeated zeros:', function() {
verifyRange(10031, 20081, 0, 59999);
verifyRange(10000, 20000, 0, 59999);
});
it('should support zero one:', function() {
verifyRange(10301, 20101, 0, 99999);
});
it('should support repetead ones:', function() {
verifyRange(102, 111, 0, 1000);
});
it('should support small diffs:', function() {
verifyRange(102, 110, 0, 1000);
verifyRange(102, 130, 0, 1000);
});
it('should support random ranges:', function() {
verifyRange(4173, 7981, 0, 99999);
});
it('should support one digit numbers:', function() {
verifyRange(3, 7, 0, 99);
});
it('should support one digit at bounds:', function() {
verifyRange(1, 9, 0, 1000);
});
it('should support power of ten:', function() {
verifyRange(1000, 8632, 0, 99999);
});
it('should work with numbers of varying lengths:', function() {
verifyRange(1030, 20101, 0, 99999);
verifyRange(13, 8632, 0, 10000);
});
it('should support small ranges:', function() {
verifyRange(9, 11, 0, 100);
verifyRange(19, 21, 0, 100);
});
it('should support big ranges:', function() {
verifyRange(90, 98009, 0, 98999);
verifyRange(999, 10000, 1, 20000);
});
});