@ckirby/mr-lister
Advanced tools
Comparing version 2.5.2 to 2.6.0
{ | ||
"name": "@ckirby/mr-lister", | ||
"version": "2.5.2", | ||
"version": "2.6.0", | ||
"description": "format lists of numbers, letters, or arbitrary items", | ||
@@ -5,0 +5,0 @@ "main": "./src/index", |
@@ -26,2 +26,3 @@ | ||
const comma = options.comma || options.separator || ', '; | ||
const minRangeDelta = options.minRangeDelta || 1; | ||
@@ -35,3 +36,4 @@ let isRange = list.every(isInt); | ||
'–', | ||
list | ||
list, | ||
minRangeDelta | ||
); | ||
@@ -38,0 +40,0 @@ } else { // test if alphabetic range |
@@ -16,3 +16,3 @@ /* | ||
function consolidate(arr, delimiter, getVal) { | ||
function consolidate(arr, delimiter, getVal, minRangeDelta = 1) { | ||
const rangeBegs = []; | ||
@@ -26,18 +26,23 @@ const rangeEnds = []; | ||
if (curr !== prev + 1) { | ||
rangeBegs.push(arr[index]); | ||
rangeBegs.push({ index, val: arr[index] }); | ||
} | ||
if (curr !== next - 1) { | ||
rangeEnds.push(arr[index]); | ||
rangeEnds.push({ index, val: arr[index] }); | ||
} | ||
} | ||
return rangeBegs.map((start, i) => { | ||
let out = []; | ||
for (const [ i, start ] of rangeBegs.entries()) { | ||
const end = rangeEnds[i]; | ||
if (start === end) { | ||
return start; | ||
if (start.val === end.val) { | ||
out.push(start.val); | ||
} else if (getVal(end.val) - getVal(start.val) < minRangeDelta) { | ||
out.push(...arr.slice(start.index, end.index + 1)); | ||
} else { | ||
out.push(`${start.val}${delimiter}${end.val}`); | ||
} | ||
return `${start}${delimiter}${end}`; | ||
}); | ||
} | ||
return out; | ||
} | ||
function consolidateRanges(inputArray, delimiter = '–', { needsSort = true, needsUnique = true } = {}) { | ||
function consolidateRanges(inputArray, delimiter = '–', { needsSort = true, needsUnique = true } = {}, minRangeDelta) { | ||
let arr = inputArray.slice(); | ||
@@ -53,3 +58,4 @@ if (needsUnique) { | ||
delimiter, | ||
(x) => x | ||
(x) => x, | ||
minRangeDelta | ||
); | ||
@@ -56,0 +62,0 @@ } |
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
8622
249