[Pkg-javascript-commits] [node-fill-range] 01/05: New upstream version 5.0.0
Julien Puydt
julien.puydt at laposte.net
Sat Nov 25 17:10:51 UTC 2017
This is an automated email from the git hooks/post-receive script.
jpuydt-guest pushed a commit to branch master
in repository node-fill-range.
commit e6698ee38b4850a9fea1e459ef723186e63de235
Author: Julien Puydt <julien.puydt at laposte.net>
Date: Sat Nov 25 17:09:27 2017 +0100
New upstream version 5.0.0
---
.editorconfig | 9 +-
.eslintrc.json | 5 -
.gitignore | 10 +-
.travis.yml | 13 +-
.verb.md | 165 ++++++++++++++--------
LICENSE | 2 +-
README.md | 243 ++++++++++++++++++++------------
benchmark/code/fill-range.js | 9 +-
benchmark/fixtures/0001-1000-toregex.js | 1 +
benchmark/fixtures/0001-1000.js | 1 +
benchmark/fixtures/001-100.js | 1 +
benchmark/fixtures/1-100-7.js | 1 +
benchmark/fixtures/1-1000-7.js | 1 +
benchmark/fixtures/1-1000-toregex.js | 1 +
benchmark/fixtures/1-1000.js | 1 +
benchmark/index.js | 10 +-
benchmark/last.md | 55 +++++---
examples.js | 48 +++++--
index.js | 39 +++--
package.json | 36 ++---
test/errors.js | 43 ------
test/invalid.js | 29 ----
test/matching.js | 4 +-
test/options.js | 78 +++++++++-
test/padding.js | 4 +-
test/ranges.js | 4 +-
test/special.js | 4 +-
test/steps.js | 4 +-
test/support/exact.js | 2 +-
test/verify-matches.js | 4 +-
30 files changed, 513 insertions(+), 314 deletions(-)
diff --git a/.editorconfig b/.editorconfig
index 818e072..449f0da 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -1,13 +1,14 @@
+# http://editorconfig.org/
root = true
[*]
-indent_style = space
-end_of_line = lf
charset = utf-8
+end_of_line = lf
indent_size = 2
-trim_trailing_whitespace = true
+indent_style = space
insert_final_newline = true
+trim_trailing_whitespace = true
[{**/{actual,fixtures,expected,templates}/**,*.md}]
trim_trailing_whitespace = false
-insert_final_newline = false
\ No newline at end of file
+insert_final_newline = false
diff --git a/.eslintrc.json b/.eslintrc.json
index 948dbdb..61e8895 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -1,9 +1,4 @@
{
- "ecmaFeatures": {
- "modules": true,
- "experimentalObjectRestSpread": true
- },
-
"env": {
"browser": false,
"es6": true,
diff --git a/.gitignore b/.gitignore
index 7988154..4bf0a60 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,21 +1,29 @@
# 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
-benchmark
+_draft
+_drafts
bower_components
vendor
temp
tmp
TODO.md
+package-lock.json
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
index 04a029e..1686664 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,12 +1,15 @@
sudo: false
+os:
+ - linux
+ - osx
language: node_js
node_js:
- node
+ - '9'
+ - '8'
+ - '7'
- '6'
- '5'
+ - '4'
- '0.12'
-matrix:
- fast_finish: true
- allow_failures:
- - node_js: '4'
- - node_js: '0.12'
+ - '0.10'
diff --git a/.verb.md b/.verb.md
index f022cb2..e3dda5c 100644
--- a/.verb.md
+++ b/.verb.md
@@ -4,104 +4,153 @@ Expands numbers and letters, optionally using a `step` as the last argument. _(N
```js
var fill = require('{%= name %}');
+fill(from, to[, step, options]);
-console.log(fill('a', 'e'));
-//=> ['a', 'b', 'c', 'd', 'e']
+// 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**
-console.log(fill(0, 25, 5));
-//=> [ 0, 5, 10, 15, 20, 25 ]
+- `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)
-console.log(fill('a', 'e', {toRegex: true}));
-//=> '[a-e]'
-console.log(fill('a', 'z', 3, {toRegex: true}));
-//=> 'a|d|g|j|m|p|s|v|y'
+## Examples
-console.log(fill('1', '100', {toRegex: true}));
-//=> '[1-9]|[1-9][0-9]|100'
+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' ]
```
-Create regex-compatible ranges (returns a string, which can be used however you need to create a regex):
+**Numerical ranges**
+
+Numbers can be defined as actual numbers or strings.
```js
-console.log(fill('a', 'e', {toRegex: true}));
-//=> '[a-e]'
+console.log(fill(1, 5)); //=> [ 1, 2, 3, 4, 5 ]
+console.log(fill('1', '5')); //=> [ 1, 2, 3, 4, 5 ]
+```
+
+**Negative ranges**
-console.log(fill('a', 'z', 3, {toRegex: true}));
-//=> 'a|d|g|j|m|p|s|v|y'
+Numbers can be defined as actual numbers or strings.
-console.log(fill('1', '100', {toRegex: true}));
-//=> '[1-9]|[1-9][0-9]|100'
+```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' ]
```
-**Params**
+**Steps (increments)**
```js
-fill(start, stop, step, options, fn);
+// 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' ]
```
- - `start`: **{String|Number}** the number or letter to start with
- - `end`: **{String|Number}** the number or letter to end with
- - `step`: **{String|Number}** optionally pass the step to use. works for letters or numbers.
- - `options`: **{Object}**:
- + `toRegex`: return a regex-compatible string (still returned as an array for consistency)
- + `step`: pass the step on the options as an alternative to passing it as an argument
- + `strict`: `undefined` by default, set to true to throw errors on invalid ranges.
- - `fn`: **{Function}** optionally [pass a function](#custom-function) to modify each character. This can also be defined as `options.transform`
+## Options
+### options.step
-**Examples**
+**Type**: `number` (formatted as a string or number)
-```js
-fill(1, 3)
-//=> ['1', '2', '3']
+**Default**: `undefined`
+
+**Description**: The increment to use for the range. Can be used with letters or numbers.
+
+**Example(s)**
-fill('1', '3')
-//=> ['1', '2', '3']
+```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' ]
+```
-fill('0', '-5')
-//=> [ '0', '-1', '-2', '-3', '-4', '-5' ]
+### options.strictRanges
-fill(-9, 9, 3)
-//=> [ '-9', '-6', '-3', '0', '3', '6', '9' ])
+**Type**: `boolean`
-fill('-1', '-10', '-2')
-//=> [ '-1', '-3', '-5', '-7', '-9' ]
+**Default**: `false`
-fill('1', '10', '2')
-//=> [ '1', '3', '5', '7', '9' ]
+**Description**: By default, `null` is returned when an invalid range is passed. Enable this option to throw a `RangeError` on invalid ranges.
-fill('a', 'e')
-//=> ['a', 'b', 'c', 'd', 'e']
+**Example(s)**
-fill('a', 'e', 2)
-//=> ['a', 'c', 'e']
+The following are all invalid:
-fill('A', 'E', 2)
-//=> ['A', 'C', 'E']
+```js
+fill('1.1', '2'); // decimals not supported in ranges
+fill('a', '2'); // incompatible range values
+fill(1, 10, 'foo'); // invalid "step" argument
```
-### Invalid ranges
+### options.stringify
-When an invalid range is passed, `null` is returned.
+**Type**: `boolean`
+
+**Default**: `undefined`
+
+**Description**: Cast all returned values to strings. By default, integers are returned as numbers.
+
+**Example(s)**
```js
-fill('1.1', '2'); // decimals not supported in ranges
-//=> null
+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`
-fill('a', '2'); // unmatched values
-//=> null
+**Description**: Create a regex-compatible source string, instead of expanding values to an array.
-fill(1, 10, 'foo'); // invalid step
-//=> null
+**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'
```
-If you want errors to be throw, set `options.strict` to true.
+### options.transform
+
+**Type**: `function`
+**Default**: `undefined`
-### Custom function
+**Description**: Customize each value in the returned array (or [string](#optionstoRegex)). _(you can also pass this function as the last argument to `fill()`)_.
-Optionally pass a custom function as last argument or on `options.transform`.
+**Example(s)**
```js
// increase padding by two
diff --git a/LICENSE b/LICENSE
index 842218c..3f2eca1 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)
-Copyright (c) 2014-2016, Jon Schlinkert
+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
diff --git a/README.md b/README.md
index e069ea9..22c1d78 100644
--- a/README.md
+++ b/README.md
@@ -1,20 +1,19 @@
-# fill-range [![NPM version](https://img.shields.io/npm/v/fill-range.svg?style=flat)](https://www.npmjs.com/package/fill-range) [![NPM downloads](https://img.shields.io/npm/dm/fill-range.svg?style=flat)](https://npmjs.org/package/fill-range) [![Build Status](https://img.shields.io/travis/jonschlinkert/fill-range.svg?style=flat)](https://travis-ci.org/jonschlinkert/fill-range)
+# fill-range [![NPM version](https://img.shields.io/npm/v/fill-range.svg?style=flat)](https://www.npmjs.com/package/fill-range) [![NPM monthly downloads](https://img.shields.io/npm/dm/fill-range.svg?style=flat)](https://npmjs.org/package/fill-range) [![NPM total downloads](https://img.shields.io/npm/dt/fill-range.svg?style=flat)](https://npmjs.org/package/fill-range) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/fill-range.svg?style=flat&label=Travis)](https://travis [...]
> 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`
-## Table of Contents
+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)
- * [Invalid ranges](#invalid-ranges)
- * [Custom function](#custom-function)
+- [Examples](#examples)
+- [Options](#options)
+ * [options.step](#optionsstep)
+ * [options.strictRanges](#optionsstrictranges)
+ * [options.stringify](#optionsstringify)
+ * [options.toRegex](#optionstoregex)
+ * [options.transform](#optionstransform)
- [About](#about)
- * [Related projects](#related-projects)
- * [Contributing](#contributing)
- * [Building docs](#building-docs)
- * [Running tests](#running-tests)
- * [Author](#author)
- * [License](#license)
_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_
@@ -32,102 +31,151 @@ Expands numbers and letters, optionally using a `step` as the last argument. _(N
```js
var fill = require('fill-range');
+fill(from, to[, step, options]);
-console.log(fill('a', 'e'));
-//=> ['a', 'b', 'c', 'd', 'e']
+// 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**
-console.log(fill(0, 25, 5));
-//=> [ 0, 5, 10, 15, 20, 25 ]
+* `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)
-console.log(fill('a', 'e', {toRegex: true}));
-//=> '[a-e]'
+## Examples
-console.log(fill('a', 'z', 3, {toRegex: true}));
-//=> 'a|d|g|j|m|p|s|v|y'
+By default, an array of values is returned.
-console.log(fill('1', '100', {toRegex: true}));
-//=> '[1-9]|[1-9][0-9]|100'
+**Alphabetical ranges**
+
+```js
+console.log(fill('a', 'e')); //=> ['a', 'b', 'c', 'd', 'e']
+console.log(fill('A', 'E')); //=> [ 'A', 'B', 'C', 'D', 'E' ]
```
-Create regex-compatible ranges (returns a string, which can be used however you need to create a regex):
+**Numerical ranges**
+
+Numbers can be defined as actual numbers or strings.
```js
-console.log(fill('a', 'e', {toRegex: true}));
-//=> '[a-e]'
+console.log(fill(1, 5)); //=> [ 1, 2, 3, 4, 5 ]
+console.log(fill('1', '5')); //=> [ 1, 2, 3, 4, 5 ]
+```
+
+**Negative ranges**
-console.log(fill('a', 'z', 3, {toRegex: true}));
-//=> 'a|d|g|j|m|p|s|v|y'
+Numbers can be defined as actual numbers or strings.
-console.log(fill('1', '100', {toRegex: true}));
-//=> '[1-9]|[1-9][0-9]|100'
+```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' ]
```
-**Params**
+**Steps (increments)**
```js
-fill(start, stop, step, options, fn);
+// 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' ]
```
-* `start`: **{String|Number}** the number or letter to start with
-* `end`: **{String|Number}** the number or letter to end with
-* `step`: **{String|Number}** optionally pass the step to use. works for letters or numbers.
-* `options`: **{Object}**:
- - `toRegex`: return a regex-compatible string (still returned as an array for consistency)
- - `step`: pass the step on the options as an alternative to passing it as an argument
- - `strict`: `undefined` by default, set to true to throw errors on invalid ranges.
-* `fn`: **{Function}** optionally [pass a function](#custom-function) to modify each character. This can also be defined as `options.transform`
+## Options
-**Examples**
+### options.step
-```js
-fill(1, 3)
-//=> ['1', '2', '3']
+**Type**: `number` (formatted as a string or number)
-fill('1', '3')
-//=> ['1', '2', '3']
+**Default**: `undefined`
-fill('0', '-5')
-//=> [ '0', '-1', '-2', '-3', '-4', '-5' ]
+**Description**: The increment to use for the range. Can be used with letters or numbers.
-fill(-9, 9, 3)
-//=> [ '-9', '-6', '-3', '0', '3', '6', '9' ])
+**Example(s)**
-fill('-1', '-10', '-2')
-//=> [ '-1', '-3', '-5', '-7', '-9' ]
+```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' ]
+```
-fill('1', '10', '2')
-//=> [ '1', '3', '5', '7', '9' ]
+### options.strictRanges
-fill('a', 'e')
-//=> ['a', 'b', 'c', 'd', 'e']
+**Type**: `boolean`
-fill('a', 'e', 2)
-//=> ['a', 'c', 'e']
+**Default**: `false`
-fill('A', 'E', 2)
-//=> ['A', 'C', 'E']
-```
+**Description**: By default, `null` is returned when an invalid range is passed. Enable this option to throw a `RangeError` on invalid ranges.
-### Invalid ranges
+**Example(s)**
-When an invalid range is passed, `null` is returned.
+The following are all invalid:
```js
fill('1.1', '2'); // decimals not supported in ranges
-//=> null
+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.
-fill('a', '2'); // unmatched values
-//=> null
+**Example(s)**
-fill(1, 10, 'foo'); // invalid step
-//=> null
+```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'
```
-If you want errors to be throw, set `options.strict` to true.
+### options.transform
+
+**Type**: `function`
+
+**Default**: `undefined`
-### Custom function
+**Description**: Customize each value in the returned array (or [string](#optionstoRegex)). _(you can also pass this function as the last argument to `fill()`)_.
-Optionally pass a custom function as last argument or on `options.transform`.
+**Example(s)**
```js
// increase padding by two
@@ -141,47 +189,68 @@ console.log(arr);
## About
-### Related projects
-
-* [braces](https://www.npmjs.com/package/braces): Fastest brace expansion for node.js, with the most complete support for the Bash 4.3 braces… [more](https://github.com/jonschlinkert/braces) | [homepage](https://github.com/jonschlinkert/braces "Fastest brace expansion for node.js, with the most complete support for the Bash 4.3 braces specification.")
-* [expand-range](https://www.npmjs.com/package/expand-range): Fast, bash-like range expansion. Expand a range of numbers or letters, uppercase or lowercase. See… [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. See the benchmarks. 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/jonschlinkert/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): Returns a regex-compatible range from two numbers, min and max, with 855,412 generated unit tests… [more](https://github.com/jonschlinkert/to-regex-range) | [homepage](https://github.com/jonschlinkert/to-regex-range "Returns a regex-compatible range from two numbers, min and max, with 855,412 generated unit tests to validate it's accuracy! Useful for creating regular expressions to validate numbers, ranges, years, etc. Ret [...]
-
-### Contributing
+<details>
+<summary><strong>Contributing</strong></summary>
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
-### Building docs
+</details>
-_(This document was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme) (a [verb](https://github.com/verbose/verb) generator), please don't edit the readme directly. Any changes to the readme must be made in [.verb.md](.verb.md).)_
+<details>
+<summary><strong>Running Tests</strong></summary>
-To generate the readme and API documentation with [verb](https://github.com/verbose/verb):
+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 -g verb verb-generate-readme && verb
+$ npm install && npm test
```
-### Running tests
+</details>
+
+<details>
+<summary><strong>Building docs</strong></summary>
+
+_(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.)_
-Install dev dependencies:
+To generate the readme, run the following command:
```sh
-$ npm install -d && npm test
+$ npm install -g verbose/verb#dev verb-generate-readme && verb
```
+</details>
+
+### 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](http://twitter.com/jonschlinkert)
+* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
### License
-Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
-Released under the [MIT license](https://github.com/jonschlinkert/fill-range/blob/master/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.1.30, on September 15, 2016._
\ No newline at end of file
+_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on November 01, 2017._
\ No newline at end of file
diff --git a/benchmark/code/fill-range.js b/benchmark/code/fill-range.js
index 3e20024..ee41f06 100644
--- a/benchmark/code/fill-range.js
+++ b/benchmark/code/fill-range.js
@@ -1,3 +1,10 @@
'use strict';
-module.exports = require('../..');
+var fill = require('../..');
+
+module.exports = function fn(from, to, step) {
+ if (Array.isArray(from)) {
+ return fn.apply(undefined, from);
+ }
+ return fill.apply(undefined, arguments);
+};
diff --git a/benchmark/fixtures/0001-1000-toregex.js b/benchmark/fixtures/0001-1000-toregex.js
new file mode 100644
index 0000000..acff0dc
--- /dev/null
+++ b/benchmark/fixtures/0001-1000-toregex.js
@@ -0,0 +1 @@
+module.exports = ['0001', '1000', {toRegex: true}];
diff --git a/benchmark/fixtures/0001-1000.js b/benchmark/fixtures/0001-1000.js
new file mode 100644
index 0000000..2f5efdd
--- /dev/null
+++ b/benchmark/fixtures/0001-1000.js
@@ -0,0 +1 @@
+module.exports = ['0001', '1000'];
diff --git a/benchmark/fixtures/001-100.js b/benchmark/fixtures/001-100.js
new file mode 100644
index 0000000..4d4781c
--- /dev/null
+++ b/benchmark/fixtures/001-100.js
@@ -0,0 +1 @@
+module.exports = ['001', '100'];
diff --git a/benchmark/fixtures/1-100-7.js b/benchmark/fixtures/1-100-7.js
new file mode 100644
index 0000000..cd1c2a7
--- /dev/null
+++ b/benchmark/fixtures/1-100-7.js
@@ -0,0 +1 @@
+module.exports = ['1', '100', 7];
diff --git a/benchmark/fixtures/1-1000-7.js b/benchmark/fixtures/1-1000-7.js
new file mode 100644
index 0000000..3813d17
--- /dev/null
+++ b/benchmark/fixtures/1-1000-7.js
@@ -0,0 +1 @@
+module.exports = ['1', '1000', 7];
diff --git a/benchmark/fixtures/1-1000-toregex.js b/benchmark/fixtures/1-1000-toregex.js
new file mode 100644
index 0000000..086c849
--- /dev/null
+++ b/benchmark/fixtures/1-1000-toregex.js
@@ -0,0 +1 @@
+module.exports = ['1', '1000', {toRegex: true}];
diff --git a/benchmark/fixtures/1-1000.js b/benchmark/fixtures/1-1000.js
new file mode 100644
index 0000000..c82f101
--- /dev/null
+++ b/benchmark/fixtures/1-1000.js
@@ -0,0 +1 @@
+module.exports = ['1', '1000'];
diff --git a/benchmark/index.js b/benchmark/index.js
index 2888f6e..871cd60 100644
--- a/benchmark/index.js
+++ b/benchmark/index.js
@@ -3,14 +3,14 @@
var path = require('path');
var util = require('util');
var cyan = require('ansi-cyan');
-var argv = require('yargs-parser')(process.argv.slice(2));
+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`
+ fixtures: 'fixtures/' + fixtures + '.js',
+ code: 'code/' + code + '*.js'
});
if (argv.dry) {
@@ -18,7 +18,7 @@ function run(code, fixtures) {
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).length;
+ var res = code.run.apply(null, args);
console.log(util.inspect(res, null, 10));
console.log();
});
@@ -27,4 +27,4 @@ function run(code, fixtures) {
}
}
-run(argv._[0] || '*', argv._[1] || '**/{1,2,a}*');
+run(argv._[0] || '*', argv._[1] || '*');
diff --git a/benchmark/last.md b/benchmark/last.md
index 7bf8958..038523d 100644
--- a/benchmark/last.md
+++ b/benchmark/last.md
@@ -1,26 +1,45 @@
-#1: 1-100-logical-or.js
- fill-range.js x 272,324 ops/sec ±0.86% (96 runs sampled)
+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
-#2: 1-100.js
- fill-range.js x 348,125 ops/sec ±0.90% (93 runs sampled)
+# benchmark/fixtures/0001-1000-toregex.js (52 bytes)
+ fill-range x 713,367 ops/sec ±1.11% (86 runs sampled)
-#3: 1-5.js
- fill-range.js x 1,295,990 ops/sec ±0.95% (98 runs sampled)
+# benchmark/fixtures/0001-1000.js (35 bytes)
+ fill-range x 16,956 ops/sec ±0.96% (86 runs sampled)
-#4: 2-20-2.js
- fill-range.js x 1,009,256 ops/sec ±0.70% (99 runs sampled)
+# benchmark/fixtures/001-100.js (33 bytes)
+ fill-range x 182,150 ops/sec ±0.92% (87 runs sampled)
-#5: a-z-character-class.js
- fill-range.js x 1,360,704 ops/sec ±0.75% (93 runs sampled)
+# benchmark/fixtures/1-100-7.js (34 bytes)
+ fill-range x 989,458 ops/sec ±1.01% (88 runs sampled)
-#6: a-z.js
- fill-range.js x 1,006,624 ops/sec ±0.76% (98 runs sampled)
+# benchmark/fixtures/1-100.js (31 bytes)
+ fill-range x 338,403 ops/sec ±0.93% (90 runs sampled)
-#7: options-num.js
- fill-range.js x 1,063,593 ops/sec ±0.82% (97 runs sampled)
+# benchmark/fixtures/1-1000-7.js (35 bytes)
+ fill-range x 263,486 ops/sec ±1.24% (82 runs sampled)
-#8: options-str.js
- fill-range.js x 1,347,300 ops/sec ±0.88% (92 runs sampled)
+# benchmark/fixtures/1-1000-toregex.js (49 bytes)
+ fill-range x 649,917 ops/sec ±1.58% (88 runs sampled)
-#9: random.js
- fill-range.js x 580,981 ops/sec ±0.90% (88 runs sampled)
\ No newline at end of file
+# 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)
diff --git a/examples.js b/examples.js
index 44073ef..e867210 100644
--- a/examples.js
+++ b/examples.js
@@ -1,13 +1,41 @@
-var fill = require('./');
-
-console.log(fill(0, 25, 5));
-//=> [ 0, 5, 10, 15, 20, 25 ]
+'use strict';
-console.log(fill('a', 'e', {toRegex: true}));
-//=> '[a-e]'
+var util = require('util');
+var fill = require('./');
+var res = [];
-console.log(fill('a', 'z', 3, {toRegex: true}));
-//=> 'a|d|g|j|m|p|s|v|y'
+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))
+});
-console.log(fill('1', '100', {toRegex: true}));
-//=> '[1-9]|[1-9][0-9]|100'
+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'))
diff --git a/index.js b/index.js
index ec822b3..7f6859a 100644
--- a/index.js
+++ b/index.js
@@ -1,8 +1,8 @@
/*!
* fill-range <https://github.com/jonschlinkert/fill-range>
*
- * Copyright (c) 2014-2015, Jon Schlinkert.
- * Licensed under the MIT License.
+ * Copyright (c) 2014-2017, Jon Schlinkert.
+ * Released under the MIT License.
*/
'use strict';
@@ -19,7 +19,7 @@ var toRegex = require('to-regex-range');
* @param {String} `start` Start of the range
* @param {String} `stop` End of the range
* @param {String} `step` Increment or decrement to use.
- * @param {Function} `fn` Custom function to modify each element in the range.
+ * @param {Function} `options`
* @return {Array}
*/
@@ -39,7 +39,7 @@ function fillRange(start, stop, step, options) {
if (typeof step !== 'number' && typeof step !== 'string') {
options = step;
- step = null;
+ step = undefined;
}
if (typeof options === 'function') {
@@ -48,7 +48,7 @@ function fillRange(start, stop, step, options) {
var opts = extend({step: step}, options);
if (opts.step && !isValidNumber(opts.step)) {
- if (opts.strict === true) {
+ if (opts.strictRanges === true) {
throw new TypeError('expected options.step to be a number');
}
return [];
@@ -56,7 +56,7 @@ function fillRange(start, stop, step, options) {
opts.isNumber = isValidNumber(start) && isValidNumber(stop);
if (!opts.isNumber && !isValid(start, stop)) {
- if (opts.strict === true) {
+ if (opts.strictRanges === true) {
throw new RangeError('invalid range arguments: ' + util.inspect([start, stop]));
}
return [];
@@ -85,7 +85,7 @@ function expand(start, stop, options) {
var step = Math.abs(toNumber(options.step)) || 1;
if (options.toRegex && step === 1) {
- return toRange(a, b, options);
+ return toRange(a, b, start, stop, options);
}
var zero = {greater: [], lesser: []};
@@ -123,21 +123,26 @@ function expand(start, stop, options) {
}
if (options.toRegex === true) {
- return toSequence(arr, zero);
+ return toSequence(arr, zero, options);
}
return arr;
}
-function toRange(a, b, options) {
+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));
+ 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) {
+function toSequence(arr, zeros, options) {
var greater = '', lesser = '';
if (zeros.greater.length) {
greater = zeros.greater.join('|');
@@ -145,10 +150,14 @@ function toSequence(arr, zeros) {
if (zeros.lesser.length) {
lesser = '-(' + zeros.lesser.join('|') + ')';
}
- if (greater && lesser) {
- return greater + '|' + lesser;
+ var res = greater && lesser
+ ? greater + '|' + lesser
+ : greater || lesser;
+
+ if (options.capture) {
+ return '(' + res + ')';
}
- return greater || lesser;
+ return res;
}
function zeros(val, options) {
@@ -175,7 +184,7 @@ function toNumber(val) {
}
function isPadded(str) {
- return /^-*0\d+/.test(str);
+ return /^-?0\d/.test(str);
}
function isValid(min, max) {
diff --git a/package.json b/package.json
index f1c51d4..2699023 100644
--- a/package.json
+++ b/package.json
@@ -1,12 +1,15 @@
{
"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": "3.0.3",
+ "version": "5.0.0",
"homepage": "https://github.com/jonschlinkert/fill-range",
"author": "Jon Schlinkert (https://github.com/jonschlinkert)",
"contributors": [
- "Jon Schlinkert <jon.schlinkert at sellside.com> (http://twitter.com/jonschlinkert)",
- "Paul Miller <paul+gh at paulmillr.com> (paulmillr.com)"
+ "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": {
@@ -25,18 +28,21 @@
},
"dependencies": {
"extend-shallow": "^2.0.1",
- "is-number": "^3.0.0",
- "repeat-string": "^1.5.4",
- "to-regex-range": "^0.2.0"
+ "is-number": "^4.0.0",
+ "repeat-string": "^1.6.1",
+ "to-regex-range": "^2.1.1"
},
"devDependencies": {
- "gulp-format-md": "^0.1.10",
- "mocha": "^3.0.2"
+ "ansi-cyan": "^0.1.1",
+ "benchmarked": "^2.0.0",
+ "gulp-format-md": "^1.0.0",
+ "minimist": "^1.2.0",
+ "mocha": "^3.5.0"
},
"keywords": [
- "array",
"alpha",
"alphabetical",
+ "array",
"bash",
"brace",
"expand",
@@ -48,18 +54,18 @@
"matching",
"number",
"numerical",
- "regex",
"range",
"ranges",
+ "regex",
"sh"
],
"verb": {
"related": {
"list": [
"braces",
- "to-regex-range",
"expand-range",
- "micromatch"
+ "micromatch",
+ "to-regex-range"
]
},
"toc": true,
@@ -72,10 +78,6 @@
],
"lint": {
"reflinks": true
- },
- "reflinks": [
- "verb",
- "verb-generate-readme"
- ]
+ }
}
}
diff --git a/test/errors.js b/test/errors.js
deleted file mode 100644
index cb8ba2a..0000000
--- a/test/errors.js
+++ /dev/null
@@ -1,43 +0,0 @@
-'use strict';
-
-require('mocha');
-var assert = require('assert');
-var fill = require('..');
-
-describe('error handling', function() {
- it('should throw when range arguments are invalid and `strict` is true.', function() {
- assert.throws(function() {
- fill('0a', '0z', {strict: true});
- }, /invalid range arguments: \[ \'0a\', \'0z\' \]/);
-
- assert.throws(function() {
- fill('.', '*', 2, {strict: true});
- }, /invalid range arguments: \[ \'\.\', \'\*\' \]/);
-
- assert.throws(function() {
- fill('!', '$', {strict: true});
- }, /invalid range arguments: \[ \'\!\', \'\$\' \]/);
- });
-
- it('should throw when args are incompatible.', function() {
- assert.throws(function() {
- fill('a8', 10, {strict: true});
- }, /invalid range arguments: \[ \'a8\', 10 \]/);
-
- assert.throws(function() {
- fill(1, 'zz', {strict: true});
- }, /invalid range arguments: \[ 1, \'zz\' \]/);
- });
-
- it('should throw when the step is bad.', function() {
- assert.throws(function() {
- fill('1', '10', 'z', {strict: true});
- }, /expected options\.step to be a number/);
- assert.throws(function() {
- fill('a', 'z', 'a', {strict: true});
- }, /expected options\.step to be a number/);
- assert.throws(function() {
- fill('a', 'z', '0a', {strict: true});
- }, /expected options\.step to be a number/);
- });
-});
diff --git a/test/invalid.js b/test/invalid.js
deleted file mode 100644
index 85623b4..0000000
--- a/test/invalid.js
+++ /dev/null
@@ -1,29 +0,0 @@
-/*!
- * fill-range <https://github.com/jonschlinkert/fill-range>
- *
- * Copyright (c) 2014-2015, Jon Schlinkert.
- * Licensed under the MIT License.
- */
-
-'use strict';
-
-require('mocha');
-var assert = require('assert');
-var fill = require('..');
-
-describe('invalid ranges', function() {
- it('should return an empty array when options.strict is not true', 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'), []);
- });
-});
diff --git a/test/matching.js b/test/matching.js
index b406e28..9bc8628 100644
--- a/test/matching.js
+++ b/test/matching.js
@@ -1,8 +1,8 @@
/*!
* fill-range <https://github.com/jonschlinkert/fill-range>
*
- * Copyright (c) 2014-2015, Jon Schlinkert.
- * Licensed under the MIT License.
+ * Copyright (c) 2014-2017, Jon Schlinkert.
+ * Released under the MIT License.
*/
'use strict';
diff --git a/test/options.js b/test/options.js
index 2275df8..5f6c5a1 100644
--- a/test/options.js
+++ b/test/options.js
@@ -1,8 +1,8 @@
/*!
* fill-range <https://github.com/jonschlinkert/fill-range>
*
- * Copyright (c) 2014-2015, Jon Schlinkert.
- * Licensed under the MIT License.
+ * Copyright (c) 2014-2017, Jon Schlinkert.
+ * Released under the MIT License.
*/
'use strict';
@@ -22,6 +22,59 @@ describe('options', function() {
});
});
+ 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]');
@@ -29,6 +82,20 @@ describe('options', function() {
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]');
@@ -53,4 +120,11 @@ describe('options', function() {
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))');
+ });
+ });
});
diff --git a/test/padding.js b/test/padding.js
index 52fe751..44ab355 100644
--- a/test/padding.js
+++ b/test/padding.js
@@ -1,8 +1,8 @@
/*!
* fill-range <https://github.com/jonschlinkert/fill-range>
*
- * Copyright (c) 2014-2015, Jon Schlinkert.
- * Licensed under the MIT License.
+ * Copyright (c) 2014-2017, Jon Schlinkert.
+ * Released under the MIT License.
*/
'use strict';
diff --git a/test/ranges.js b/test/ranges.js
index 1feeead..8223ca0 100644
--- a/test/ranges.js
+++ b/test/ranges.js
@@ -1,8 +1,8 @@
/*!
* fill-range <https://github.com/jonschlinkert/fill-range>
*
- * Copyright (c) 2014-2015, Jon Schlinkert.
- * Licensed under the MIT License.
+ * Copyright (c) 2014-2017, Jon Schlinkert.
+ * Released under the MIT License.
*/
'use strict';
diff --git a/test/special.js b/test/special.js
index fc3f0fc..6e60617 100644
--- a/test/special.js
+++ b/test/special.js
@@ -1,8 +1,8 @@
/*!
* fill-range <https://github.com/jonschlinkert/fill-range>
*
- * Copyright (c) 2014-2015, Jon Schlinkert.
- * Licensed under the MIT License.
+ * Copyright (c) 2014-2017, Jon Schlinkert.
+ * Released under the MIT License.
*/
'use strict';
diff --git a/test/steps.js b/test/steps.js
index 88b5de5..d0d7b8e 100644
--- a/test/steps.js
+++ b/test/steps.js
@@ -1,8 +1,8 @@
/*!
* fill-range <https://github.com/jonschlinkert/fill-range>
*
- * Copyright (c) 2014-2015, Jon Schlinkert.
- * Licensed under the MIT License.
+ * Copyright (c) 2014-2017, Jon Schlinkert.
+ * Released under the MIT License.
*/
'use strict';
diff --git a/test/support/exact.js b/test/support/exact.js
index 3636ea4..a319594 100644
--- a/test/support/exact.js
+++ b/test/support/exact.js
@@ -9,5 +9,5 @@ module.exports = function exact(a, b) {
var aString = util.inspect(a, null, 10);
var bString = util.inspect(b, null, 10);
- assert.equal(aString, bString, aString + ' !== ' + bString);
+ assert.strictEqual(aString, bString, aString + ' !== ' + bString);
};
diff --git a/test/verify-matches.js b/test/verify-matches.js
index 71995df..676b1cb 100644
--- a/test/verify-matches.js
+++ b/test/verify-matches.js
@@ -1,8 +1,8 @@
/*!
* fill-range <https://github.com/jonschlinkert/fill-range>
*
- * Copyright (c) 2014-2015, Jon Schlinkert.
- * Licensed under the MIT License.
+ * Copyright (c) 2014-2017, Jon Schlinkert.
+ * Released under the MIT License.
*/
'use strict';
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-fill-range.git
More information about the Pkg-javascript-commits
mailing list