Socket
Socket
Sign inDemoInstall

intervals-fn

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

intervals-fn - npm Package Compare versions

Comparing version 2.8.2 to 2.8.3

29

dist/lib.js

@@ -121,2 +121,5 @@ "use strict";

};
const isOverlappingNum = (a, b) => {
return a.start < b && b < a.end;
};
const beforeOrAdjTo = (afterInt) => (beforeInt) => beforeInt.end <= afterInt.start;

@@ -328,10 +331,18 @@ const isOverlappingRec = (intervalsA, intervalsB) => {

exports.substract = substract;
const numberToRange = (n) => ({ start: n, end: n });
const splitIntervalWithIndex = (int, index) => {
if (!isOverlappingNum(int, index)) {
return [int];
}
return [Object.assign({}, int, { start: int.start, end: index }), Object.assign({}, int, { start: index, end: int.end })];
};
/**
* ||  |  |     |
* [ ] [ ][ ]
*
*/
const splitGen = (splits, intervals) => {
return ramda_1.chain((i => {
return ramda_1.chain((int => isOverlappingSimple(int, numberToRange(i)) ? [
Object.assign({}, int, { start: int.start, end: i }),
Object.assign({}, int, { start: i, end: int.end }),
] : [int]), intervals);
}), splits);
return ramda_1.unnest(intervals.map(int => splits.reduce((acc, i) => {
const lastInt = acc.pop();
return [...acc, ...splitIntervalWithIndex(lastInt, i)];
}, [int])));
};

@@ -341,6 +352,6 @@ const splitCurry = (splitIndexes, intervals) => {

const intervalSE = prepareInput(typeStr, intervals);
if (splitIndexes.length < 1 || Array.isArray(intervals) && intervals.length < 1) {
if (splitIndexes.length < 1 || (Array.isArray(intervals) && intervals.length < 1)) {
return intervalSE.map(convertTo(typeStr));
}
return splitGen(splitIndexes, intervalSE).map(convertTo(typeStr));
return splitGen([...splitIndexes].sort(), intervalSE).map(convertTo(typeStr));
};

@@ -347,0 +358,0 @@ function split(splitIndexes, interv) {

@@ -347,3 +347,3 @@ "use strict";

});
ava_1.default('intersection will not simplify', t => {
ava_1.default('intersection will not simplify when there is inner intersection', t => {
const r1 = [{ start: 1, end: 5 }];

@@ -359,2 +359,13 @@ const r2 = [{ start: 1, end: 3 }, { start: 2, end: 5 }];

});
ava_1.default('intersection will not simplify when two intervals are touching', t => {
const r1 = [{ start: 1, end: 10 }];
const r2 = [{ start: 2, end: 5 }, { start: 5, end: 8 }];
const testOutputFn = (res) => {
t.true(res.length === 2);
t.true(res[0].start === 2 && res[0].end === 5);
t.true(res[1].start === 5 && res[1].end === 8);
};
testFnToIntervals(r1, r2, lib_1.intersect, testOutputFn, t);
testFnToIntervals(r2, r1, lib_1.intersect, testOutputFn, t);
});
ava_1.default('intersection will keep object properties', t => {

@@ -399,3 +410,3 @@ const r1 = [{ start: 1, end: 5, test: 'foo' }];

ava_1.default('will not split when no intersection', t => {
const r1 = [{ start: 0, end: 7, test: 'foo' }, { start: 8, end: 10 }];
const r1 = [{ start: 0, end: 7, test: 'foo' }, { start: 8, end: 10, test: 'bar' }];
const r2 = [9];

@@ -405,4 +416,13 @@ const res = lib_1.split(r2, r1);

testInterval(t, res[0], [0, 7], { test: 'foo' });
testInterval(t, res[1], [8, 9]);
testInterval(t, res[2], [9, 10]);
testInterval(t, res[1], [8, 9], { test: 'bar' });
testInterval(t, res[2], [9, 10], { test: 'bar' });
});
ava_1.default('will split with multiple indexes', t => {
const r1 = [{ start: 0, end: 10, test: 'foo' }];
const r2 = [2, 8];
const res = lib_1.split(r2, r1);
t.is(res.length, 3);
testInterval(t, res[0], [0, 2], { test: 'foo' });
testInterval(t, res[1], [2, 8], { test: 'foo' });
testInterval(t, res[2], [8, 10], { test: 'foo' });
});

@@ -10,3 +10,3 @@ var __rest = (this && this.__rest) || function (s, e) {

};
import { any, aperture, applySpec, chain, concat, converge, dissoc, drop, dropWhile, either, groupWith, head, identity, isEmpty, isNil, map, nthArg, pipe, prop, reject, sortBy, unfold, unnest, } from 'ramda';
import { any, aperture, applySpec, concat, converge, dissoc, drop, dropWhile, either, groupWith, head, identity, isEmpty, isNil, map, nthArg, pipe, prop, reject, sortBy, unfold, unnest, } from 'ramda';
const sortByStart = sortBy(prop('start'));

@@ -119,2 +119,5 @@ const dissocMany = (...props) => {

};
const isOverlappingNum = (a, b) => {
return a.start < b && b < a.end;
};
const beforeOrAdjTo = (afterInt) => (beforeInt) => beforeInt.end <= afterInt.start;

@@ -313,10 +316,18 @@ const isOverlappingRec = (intervalsA, intervalsB) => {

}
const numberToRange = (n) => ({ start: n, end: n });
const splitIntervalWithIndex = (int, index) => {
if (!isOverlappingNum(int, index)) {
return [int];
}
return [Object.assign({}, int, { start: int.start, end: index }), Object.assign({}, int, { start: index, end: int.end })];
};
/**
* ||  |  |     |
* [ ] [ ][ ]
*
*/
const splitGen = (splits, intervals) => {
return chain((i => {
return chain((int => isOverlappingSimple(int, numberToRange(i)) ? [
Object.assign({}, int, { start: int.start, end: i }),
Object.assign({}, int, { start: i, end: int.end }),
] : [int]), intervals);
}), splits);
return unnest(intervals.map(int => splits.reduce((acc, i) => {
const lastInt = acc.pop();
return [...acc, ...splitIntervalWithIndex(lastInt, i)];
}, [int])));
};

@@ -326,6 +337,6 @@ const splitCurry = (splitIndexes, intervals) => {

const intervalSE = prepareInput(typeStr, intervals);
if (splitIndexes.length < 1 || Array.isArray(intervals) && intervals.length < 1) {
if (splitIndexes.length < 1 || (Array.isArray(intervals) && intervals.length < 1)) {
return intervalSE.map(convertTo(typeStr));
}
return splitGen(splitIndexes, intervalSE).map(convertTo(typeStr));
return splitGen([...splitIndexes].sort(), intervalSE).map(convertTo(typeStr));
};

@@ -332,0 +343,0 @@ export function split(splitIndexes, interv) {

@@ -345,3 +345,3 @@ import test from 'ava';

});
test('intersection will not simplify', t => {
test('intersection will not simplify when there is inner intersection', t => {
const r1 = [{ start: 1, end: 5 }];

@@ -357,2 +357,13 @@ const r2 = [{ start: 1, end: 3 }, { start: 2, end: 5 }];

});
test('intersection will not simplify when two intervals are touching', t => {
const r1 = [{ start: 1, end: 10 }];
const r2 = [{ start: 2, end: 5 }, { start: 5, end: 8 }];
const testOutputFn = (res) => {
t.true(res.length === 2);
t.true(res[0].start === 2 && res[0].end === 5);
t.true(res[1].start === 5 && res[1].end === 8);
};
testFnToIntervals(r1, r2, intersect, testOutputFn, t);
testFnToIntervals(r2, r1, intersect, testOutputFn, t);
});
test('intersection will keep object properties', t => {

@@ -397,3 +408,3 @@ const r1 = [{ start: 1, end: 5, test: 'foo' }];

test('will not split when no intersection', t => {
const r1 = [{ start: 0, end: 7, test: 'foo' }, { start: 8, end: 10 }];
const r1 = [{ start: 0, end: 7, test: 'foo' }, { start: 8, end: 10, test: 'bar' }];
const r2 = [9];

@@ -403,4 +414,13 @@ const res = split(r2, r1);

testInterval(t, res[0], [0, 7], { test: 'foo' });
testInterval(t, res[1], [8, 9]);
testInterval(t, res[2], [9, 10]);
testInterval(t, res[1], [8, 9], { test: 'bar' });
testInterval(t, res[2], [9, 10], { test: 'bar' });
});
test('will split with multiple indexes', t => {
const r1 = [{ start: 0, end: 10, test: 'foo' }];
const r2 = [2, 8];
const res = split(r2, r1);
t.is(res.length, 3);
testInterval(t, res[0], [0, 2], { test: 'foo' });
testInterval(t, res[1], [2, 8], { test: 'foo' });
testInterval(t, res[2], [8, 10], { test: 'foo' });
});
{
"name": "intervals-fn",
"version": "2.8.2",
"version": "2.8.3",
"description": "Manipulate intervals in a functional way",

@@ -5,0 +5,0 @@ "main": "dist/lib.js",

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