expand-range
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -38,7 +38,18 @@ # {%= name %} {%= badge("fury") %} | ||
### Custom function | ||
Pass a function as the last argument to customize the expansions: | ||
**Params:** | ||
- `str` the expanded string | ||
- `ch` the [unicode value][unicode] for the string | ||
- `i` the current index | ||
**Example using the `str` value:** | ||
```js | ||
var range = expand('a..e', function (str, i) { | ||
return String.fromCharCode(str) + i; | ||
var range = expand('a..e', function (str, ch, i) { | ||
return str + i; | ||
}); | ||
@@ -50,2 +61,13 @@ | ||
**Example using the unicode value:** | ||
```js | ||
var range = expand('a..e', function (str, ch, i) { | ||
return String.fromCharCode(ch) + i; | ||
}); | ||
console.log(range); | ||
//=> ['a0', 'b1', 'c2', 'd3', 'e4'] | ||
``` | ||
## Install | ||
@@ -73,1 +95,4 @@ {%= include("install") %} | ||
{%= include("footer") %} | ||
[unicode]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode |
@@ -1,1 +0,1 @@ | ||
module.exports = 'a..b'; | ||
module.exports = 'a..d'; |
@@ -1,1 +0,1 @@ | ||
module.exports = 'A..B'; | ||
module.exports = 'A..D'; |
@@ -44,3 +44,3 @@ /*! | ||
if (typeof special === 'function') { | ||
arr.push(special(i, idx++)); | ||
arr.push(special(String.fromCharCode(i), i, idx++)); | ||
} else if (typeof special === 'number') { | ||
@@ -47,0 +47,0 @@ arr.push(pad(i, special)); |
{ | ||
"name": "expand-range", | ||
"description": "Expand a range of numbers or letters, uppercase or lowercase. Super fast, see the benchmarks.", | ||
"version": "0.1.0", | ||
"description": "Faster, bash-like range expansion. Expand a range of numbers or letters, uppercase or lowercase. See the benchmarks.", | ||
"version": "0.1.1", | ||
"homepage": "https://github.com/jonschlinkert/expand-range", | ||
@@ -33,2 +33,3 @@ "author": { | ||
"brace-expansion": "0.0.0", | ||
"glob": "^4.0.6", | ||
"mocha": "*", | ||
@@ -60,2 +61,2 @@ "should": "^4.1.0", | ||
} | ||
} | ||
} |
# expand-range [![NPM version](https://badge.fury.io/js/expand-range.svg)](http://badge.fury.io/js/expand-range) | ||
> Expand a range of numbers or letters, uppercase or lowercase. Super fast, see the benchmarks. | ||
> Faster, bash-like range expansion. Expand a range of numbers or letters, uppercase or lowercase. See the benchmarks. | ||
@@ -38,7 +38,18 @@ ## Benchmarks | ||
### Custom function | ||
Pass a function as the last argument to customize the expansions: | ||
**Params:** | ||
- `str` the expanded string | ||
- `ch` the [unicode value][unicode] for the string | ||
- `i` the current index | ||
**Example using the `str` value:** | ||
```js | ||
var range = expand('a..e', function (str, i) { | ||
return String.fromCharCode(str) + i; | ||
var range = expand('a..e', function (str, ch, i) { | ||
return str + i; | ||
}); | ||
@@ -50,2 +61,13 @@ | ||
**Example using the unicode value:** | ||
```js | ||
var range = expand('a..e', function (str, ch, i) { | ||
return String.fromCharCode(ch) + i; | ||
}); | ||
console.log(range); | ||
//=> ['a0', 'b1', 'c2', 'd3', 'e4'] | ||
``` | ||
## Install | ||
@@ -80,2 +102,5 @@ #### Install with [npm](npmjs.org): | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on October 20, 2014._ | ||
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on October 25, 2014._ | ||
[unicode]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode |
24
test.js
@@ -31,8 +31,24 @@ /*! | ||
it('should use a custom function for expansions.', function () { | ||
var range = expand('a..e', function (str, i) { | ||
return String.fromCharCode(str) + i; | ||
describe('when a custom function is used for expansions', function () { | ||
it('should expose the actual character as the first param.', function () { | ||
var range = expand('a..e', function (str, ch, i) { | ||
return str; | ||
}); | ||
range.should.eql(['a', 'b', 'c', 'd', 'e']); | ||
}); | ||
range.should.eql(['a0', 'b1', 'c2', 'd3', 'e4']); | ||
it('should expose the charCode as the second param.', function () { | ||
var range = expand('a..e', function (str, ch, i) { | ||
return String.fromCharCode(ch); | ||
}); | ||
range.should.eql(['a', 'b', 'c', 'd', 'e']); | ||
}); | ||
it('should expose the index as the third param.', function () { | ||
var range = expand('a..e', function (str, ch, i) { | ||
return String.fromCharCode(ch) + i; | ||
}); | ||
range.should.eql(['a0', 'b1', 'c2', 'd3', 'e4']); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11144
18
136
103
7
2