Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ckirby/mr-lister

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ckirby/mr-lister - npm Package Compare versions

Comparing version 2.5.2 to 2.6.0

2

package.json
{
"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 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc