fill-range
Advanced tools
Comparing version 1.6.0 to 1.7.0
83
index.js
@@ -37,7 +37,6 @@ /*! | ||
if (typeof step === 'function') { | ||
fn = step; | ||
step = null; | ||
fn = step; step = null; | ||
} | ||
var expand, sep = ''; | ||
var expand, regex = false, sep = ''; | ||
@@ -56,8 +55,11 @@ // store a ref to unmodified arg | ||
// repeat string | ||
if (match[0] === '+') { | ||
return repeat(a, b); | ||
// randomize a, `b` times | ||
} else if (match[0] === '?') { | ||
return [randomize(a, b)]; | ||
// expand right, no regex reduction | ||
} else if (match[0] === '>') { | ||
@@ -67,6 +69,17 @@ step = step.substr(0, i) + step.substr(i + 1); | ||
// expand to an array, or if valid create a reduced | ||
// string for a regex logic `or` | ||
} else if (match[0] === '|') { | ||
step = step.substr(0, i) + step.substr(i + 1); | ||
expand = true; | ||
sep = '|'; | ||
regex = true; | ||
sep = match[0]; | ||
// expand to an array, or if valid create a reduced | ||
// string for a regex range | ||
} else if (match[0] === '~') { | ||
step = step.substr(0, i) + step.substr(i + 1); | ||
expand = true; | ||
regex = true; | ||
sep = match[0]; | ||
} | ||
@@ -94,5 +107,4 @@ } else if (!isNumber(step)) { | ||
var isNum = isNumA; | ||
var num = step && isNumber(step) | ||
? Math.abs(step) | ||
var num = step && isNumber(step) && step !== 0 && step !== '0' | ||
? Math.abs(+step) | ||
: 1; | ||
@@ -102,3 +114,3 @@ | ||
if (isNum) { | ||
// if numeric coerce to an integer | ||
// if numericm coerce to an integer | ||
a = +a; | ||
@@ -113,3 +125,3 @@ b = +b; | ||
// is the pattern positive or negative? | ||
var isNegative = b < a; | ||
var isNegative = a >= b; | ||
@@ -121,2 +133,7 @@ // detect padding | ||
// character classes, ranges and logical `or` | ||
if (regex && !padding && num === 1 && a < b) { | ||
return wrap([origA, origB], '-'); | ||
} | ||
while (isNegative ? (a >= b) : (a <= b)) { | ||
@@ -155,3 +172,20 @@ if (padding && isNum) { | ||
return expand ? join(arr, sep) : arr; | ||
// handle regex character classes, ranges | ||
// or logical `or`, now that the array is expanded | ||
if (sep === '~') { sep = '-'; } | ||
if (regex) { | ||
if (a < 0 || b < 0) { return arr; } | ||
var len = arr.length; | ||
if (isNegative) { | ||
return wrap(arr, '|'); | ||
} | ||
if (num === 1 && len === 2) { | ||
return wrap(arr, '|'); | ||
} | ||
if (num > 1 /* step */) { | ||
return wrap(arr, '|'); | ||
} | ||
} | ||
return expand ? wrap(arr, sep) : arr; | ||
} | ||
@@ -163,4 +197,19 @@ | ||
function wrap(str, sep) { | ||
str = str.join(sep); | ||
if (sep === '|') { | ||
str = '(' + str + ')'; | ||
} | ||
if (sep === '-') { | ||
str = '[' + str + ']'; | ||
} | ||
return [str]; | ||
} | ||
/** | ||
* Step regex | ||
*/ | ||
function stepRe() { | ||
return /\?|>|\||\+/g; | ||
return /\?|>|\||\+|\~/g; | ||
} | ||
@@ -227,14 +276,2 @@ | ||
/** | ||
* Join `arr` with the given `sep` | ||
*/ | ||
function join(arr, sep) { | ||
var res = arr.join(sep); | ||
if (sep === '|') { | ||
res = '(?:' + res + ')'; | ||
} | ||
return [res]; | ||
} | ||
/** | ||
* Get the string length of `val` | ||
@@ -241,0 +278,0 @@ */ |
{ | ||
"name": "fill-range", | ||
"description": "Fill in a range of numbers or letters, optionally passing an increment or multiplier to use.", | ||
"version": "1.6.0", | ||
"version": "1.7.0", | ||
"homepage": "https://github.com/jonschlinkert/fill-range", | ||
@@ -6,0 +6,0 @@ "author": { |
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
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
10739
224