Skip to content

Commit

Permalink
ensure that maxLen is passed down, to handle zero-padding
Browse files Browse the repository at this point in the history
  • Loading branch information
jonschlinkert committed May 21, 2024
1 parent 6327885 commit 95349d0
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const toMaxLen = (input, maxLength) => {
return negative ? ('-' + input) : input;
};

const toSequence = (parts, options) => {
const toSequence = (parts, options, maxLen) => {
parts.negatives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
parts.positives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);

Expand All @@ -70,11 +70,11 @@ const toSequence = (parts, options) => {
let result;

if (parts.positives.length) {
positives = parts.positives.join('|');
positives = parts.positives.map(v => toMaxLen(String(v), maxLen)).join('|');
}

if (parts.negatives.length) {
negatives = `-(${prefix}${parts.negatives.join('|')})`;
negatives = `-(${prefix}${parts.negatives.map(v => toMaxLen(String(v), maxLen)).join('|')})`;
}

if (positives && negatives) {
Expand Down Expand Up @@ -172,7 +172,7 @@ const fillNumbers = (start, end, step = 1, options = {}) => {

if (options.toRegex === true) {
return step > 1
? toSequence(parts, options)
? toSequence(parts, options, maxLen)
: toRegex(range, null, { wrap: false, ...options });
}

Expand All @@ -184,7 +184,6 @@ const fillLetters = (start, end, step = 1, options = {}) => {
return invalidRange(start, end, options);
}


let format = options.transform || (val => String.fromCharCode(val));
let a = `${start}`.charCodeAt(0);
let b = `${end}`.charCodeAt(0);
Expand Down

0 comments on commit 95349d0

Please sign in to comment.