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

interval-operations

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

interval-operations - npm Package Compare versions

Comparing version 1.0.5 to 1.0.6

12

dist/contains.d.ts

@@ -1,3 +0,9 @@

import { Interval } from './types';
export declare function contains(outerInterval: Interval, innerInterval: Interval): boolean;
export declare function arrayContains(outerIntervals: Interval[], innerIntervals: Interval[]): boolean;
import { Interval } from "./types";
export declare function contains(
outerInterval: Interval,
innerInterval: Interval
): boolean;
export declare function arrayContains(
outerIntervals: Interval[],
innerIntervals: Interval[]
): boolean;

@@ -1,3 +0,6 @@

import { Interval } from './types';
import { Interval } from "./types";
export declare function difference(a: Interval, b: Interval): Interval[] | null;
export declare function arrayDifference(inputIntervals: Interval[], inputDiffIntervals: Interval[]): Interval[];
export declare function arrayDifference(
inputIntervals: Interval[],
inputDiffIntervals: Interval[]
): Interval[];

@@ -1,2 +0,2 @@

import { Interval } from './types';
import { Interval } from "./types";
declare type SortResult = -1 | 0 | 1;

@@ -3,0 +3,0 @@ export declare function sortByStart(a: Interval, b: Interval): SortResult;

@@ -1,3 +0,3 @@

import { Interval } from './types';
import { Interval } from "./types";
export declare function intersection(...intervals: Interval[]): Interval | null;
export declare function arrayIntersection(...arrays: Interval[][]): Interval[];

@@ -1,4 +0,4 @@

export { union, arrayUnion } from './union';
export { difference, arrayDifference } from './difference';
export { intersection, arrayIntersection } from './intersection';
export { contains, arrayContains } from './contains';
export { union, arrayUnion } from "./union";
export { difference, arrayDifference } from "./difference";
export { intersection, arrayIntersection } from "./intersection";
export { contains, arrayContains } from "./contains";
"use strict";
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
Copyright (c) Microsoft Corporation.
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
function r(){for(var r=0,n=0,t=arguments.length;n<t;n++)r+=arguments[n].length;var e=Array(r),o=0;for(n=0;n<t;n++)for(var f=arguments[n],a=0,u=f.length;a<u;a++,o++)e[o]=f[a];return e}function n(r,n){return r[0]<n[0]?-1:r[0]>n[0]?1:0}function t(r,n){return r[1]<n[1]?-1:r[1]>n[1]?1:0}function e(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];if(!t.length)return[];for(var o=[],f=(t=t.sort(n))[0],a=f[0],u=f[1],i=1,l=t.length;i<l;i++){var h=t[i],v=h[0],g=h[1];u<v&&(o.push([a,u]),a=v),u<g&&(u=g)}return r(o,[[a,u]])}function o(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];if(!r.length)return[];for(var t=[],o=0,f=r.length;o<f;o++)t=t.concat(r[o]);return e.apply(void 0,t)}function f(r,n){return function(r,n){return n[1]>r[0]&&n[0]<r[1]}(r,n)?n[0]>r[0]&&n[1]<r[1]?[[r[0],n[0]],[n[1],r[1]]]:n[0]<=r[0]&&n[1]>=r[1]?null:n[0]>r[0]?[[r[0],n[0]]]:[[n[1],r[1]]]:[r]}function a(){for(var r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];r.sort(n);for(var o=[r[r.length-1][0],r.sort(t)[0][1]],f=o[0],a=o[1],u=0,i=r.length;u<i-1;u++){var l=r[u+1],h=l[0],v=l[1];if(h>a||v<f)return null}return[f,a]}function u(r,n){return n[0]>=r[0]&&n[1]<=r[1]}Object.defineProperty(exports,"__esModule",{value:!0}),exports.arrayContains=function(r,n){r=o(r);for(var t=0,e=(n=o(n)).length;t<e;t++){for(var f=!1,a=0,i=r.length;a<i;a++)if(u(r[a],n[t])){f=!0;break}if(!f)return!1}return!0},exports.arrayDifference=function(r,n){var t,o=e.apply(void 0,r),a=e.apply(void 0,n);if(!o.length)return[];if(!a.length)return o;for(var u=[],i=0,l=o.length;i<l;i++){for(var h=o[i],v=h[0],g=h[1],s=!0,c=0,p=a.length;c<p;c++){var x=a[c];if(!(x[1]<=v)){if(x[0]>=g)break;var y=f([v,g],x);if(!y){s=!1;break}v=(t=y[y.length-1])[0],g=t[1],y.length>1&&u.push(y[0])}}s&&u.push([v,g])}return u},exports.arrayIntersection=function(){for(var r=[],t=0;t<arguments.length;t++)r[t]=arguments[t];for(var e=r[0],o=1,f=r.length;o<f;o++){var u=r[o];u.sort(n);for(var i=[],l=0,h=e.length;l<h;l++)for(var v=e[l],g=0,s=u.length;g<s;g++){var c=u[g];if(!(c[1]<=v[0])){if(c[0]>=v[1])break;i.push(a(v,c))}}e=i}return e.length?e:[]},exports.arrayUnion=o,exports.contains=u,exports.difference=f,exports.intersection=a,exports.union=e;
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
Copyright (c) Microsoft Corporation.
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
function r(){for(var r=0,n=0,t=arguments.length;n<t;n++)r+=arguments[n].length;var e=Array(r),f=0;for(n=0;n<t;n++)for(var o=arguments[n],u=0,a=o.length;u<a;u++,f++)e[f]=o[u];return e}function n(r,n){return r[0]<n[0]?-1:r[0]>n[0]?1:0}function t(r,n){return r[1]<n[1]?-1:r[1]>n[1]?1:0}function e(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];if(!t.length)return[];for(var f=[],o=(t=t.sort(n))[0],u=o[0],a=o[1],l=1,h=t.length;l<h;l++){var i=t[l],v=i[0],g=i[1];a<v&&(f.push([u,a]),u=v),a<g&&(a=g)}return r(f,[[u,a]])}function f(){for(var r=[],n=0;n<arguments.length;n++)r[n]=arguments[n];if(!r.length)return[];for(var t=[],f=0,o=r.length;f<o;f++)t=t.concat(r[f]);return e.apply(void 0,t)}function o(r,n){return function(r,n){return n[1]>r[0]&&n[0]<r[1]}(r,n)?n[0]>r[0]&&n[1]<r[1]?[[r[0],n[0]],[n[1],r[1]]]:n[0]<=r[0]&&n[1]>=r[1]?null:n[0]>r[0]?[[r[0],n[0]]]:[[n[1],r[1]]]:[r]}function u(r,n){var t,f=e.apply(void 0,r),u=e.apply(void 0,n);if(!f.length)return[];if(!u.length)return f;for(var a=[],l=0,h=f.length;l<h;l++){for(var i=f[l],v=i[0],g=i[1],c=!0,p=0,s=u.length;p<s;p++){var b=u[p];if(!(b[1]<=v)){if(b[0]>=g)break;var k=o([v,g],b);if(!k){c=!1;break}v=(t=k[k.length-1])[0],g=t[1],k.length>1&&a.push(k[0])}}c&&a.push([v,g])}return a}function a(){for(var r=[],e=0;e<arguments.length;e++)r[e]=arguments[e];r.sort(n);for(var f=[r[r.length-1][0],r.sort(t)[0][1]],o=f[0],u=f[1],a=0,l=r.length;a<l-1;a++){var h=r[a+1],i=h[0],v=h[1];if(i>u||v<o)return null}return[o,u]}function l(){for(var r=[],t=0;t<arguments.length;t++)r[t]=arguments[t];for(var e=r[0],f=1,o=r.length;f<o;f++){var u=r[f];u.sort(n);for(var l=[],h=0,i=e.length;h<i;h++)for(var v=e[h],g=0,c=u.length;g<c;g++){var p=u[g];if(!(p[1]<=v[0])){if(p[0]>=v[1])break;l.push(a(v,p))}}e=l}return e.length?e:[]}function h(r,n){return n[0]>=r[0]&&n[1]<=r[1]}function i(r,n){r=f(r);for(var t=0,e=(n=f(n)).length;t<e;t++){for(var o=!1,u=0,a=r.length;u<a;u++)if(h(r[u],n[t])){o=!0;break}if(!o)return!1}return!0}export{i as arrayContains,u as arrayDifference,l as arrayIntersection,f as arrayUnion,h as contains,o as difference,a as intersection,e as union};
export declare type IntervalPoint = number | Date;
export declare type Interval = [IntervalPoint, IntervalPoint];

@@ -1,3 +0,3 @@

import { Interval } from './types';
import { Interval } from "./types";
export declare function union(...intervals: Interval[]): Interval[];
export declare function arrayUnion(...arrays: Interval[][]): Interval[];
{
"name": "interval-operations",
"version": "1.0.5",
"version": "1.0.6",
"description": "Utilities for performing mathematical set operations on intervals and arrays of intervals",

@@ -35,17 +35,17 @@ "keywords": [

"devDependencies": {
"@types/jest": "^25.1.3",
"@types/node": "^13.7.4",
"@typescript-eslint/eslint-plugin": "^2.21.0",
"@typescript-eslint/parser": "^2.21.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-jest": "^23.8.0",
"eslint-plugin-prettier": "^3.1.2",
"jest": "^25.1.0",
"prettier": "^1.19.1",
"rollup": "^1.31.1",
"rollup-plugin-terser": "^5.2.0",
"rollup-plugin-typescript2": "^0.26.0",
"ts-jest": "^25.2.1",
"typescript": "^3.8.2"
"@types/jest": "^25.2.3",
"@types/node": "^14.0.5",
"@typescript-eslint/eslint-plugin": "^3.0.2",
"@typescript-eslint/parser": "^3.0.2",
"eslint": "^7.1.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-jest": "^23.13.2",
"eslint-plugin-prettier": "^3.1.3",
"jest": "^26.0.1",
"prettier": "^2.0.5",
"rollup": "^2.11.2",
"rollup-plugin-terser": "^6.1.0",
"rollup-plugin-typescript2": "^0.27.1",
"ts-jest": "^26.0.0",
"typescript": "^3.9.3"
},

@@ -52,0 +52,0 @@ "jest": {

@@ -0,0 +0,0 @@ # Interval operations

@@ -1,15 +0,15 @@

import typescript from 'rollup-plugin-typescript2';
import pkg from './package.json';
import { terser } from 'rollup-plugin-terser';
import typescript from "rollup-plugin-typescript2";
import pkg from "./package.json";
import { terser } from "rollup-plugin-terser";
export default {
input: 'src/main.ts',
input: "src/main.ts",
output: [
{
file: pkg.main,
format: 'cjs'
format: "cjs",
},
{
file: pkg.module,
format: 'es'
}
format: "es",
},
],

@@ -19,6 +19,6 @@ external: [...Object.keys(pkg.dependencies || {})],

typescript({
typescript: require('typescript')
typescript: require("typescript"),
}),
terser()
]
terser(),
],
};

@@ -1,5 +0,5 @@

import { contains, arrayContains } from './contains';
import { contains, arrayContains } from "./contains";
describe('contains', () => {
test('contains', () => {
describe("contains", () => {
test("contains", () => {
expect(contains([1, 3], [2, 4])).toBe(false);

@@ -9,8 +9,29 @@ expect(contains([1, 3], [2, 3])).toBe(true);

test('arrayContains', () => {
expect(arrayContains([[1, 3], [4, 5]], [[1, 2], [2, 4]])).toBe(false);
expect(arrayContains([[1, 3], [2, 4], [5, 6]], [[1, 4], [5, 6]])).toBe(
true
);
test("arrayContains", () => {
expect(
arrayContains(
[
[1, 3],
[4, 5],
],
[
[1, 2],
[2, 4],
]
)
).toBe(false);
expect(
arrayContains(
[
[1, 3],
[2, 4],
[5, 6],
],
[
[1, 4],
[5, 6],
]
)
).toBe(true);
});
});

@@ -1,3 +0,3 @@

import { Interval } from './types';
import { arrayUnion } from './union';
import { Interval } from "./types";
import { arrayUnion } from "./union";

@@ -4,0 +4,0 @@ export function contains(

@@ -1,5 +0,5 @@

import { difference, arrayDifference } from './difference';
import { difference, arrayDifference } from "./difference";
describe('difference', () => {
test('difference', () => {
describe("difference", () => {
test("difference", () => {
expect(difference([2, 5], [2, 5])).toBeNull();

@@ -9,17 +9,45 @@ expect(difference([2, 5], [0, 1])).toEqual([[2, 5]]);

expect(difference([2, 5], [1, 4])).toEqual([[4, 5]]);
expect(difference([2, 5], [3, 4])).toEqual([[2, 3], [4, 5]]);
expect(difference([2, 5], [3, 4])).toEqual([
[2, 3],
[4, 5],
]);
});
test('arrayDifference', () => {
test("arrayDifference", () => {
expect(arrayDifference([], [[1, 2]])).toEqual([]);
expect(arrayDifference([[1, 2]], [])).toEqual([[1, 2]]);
expect(arrayDifference([[2, 5]], [[5, 7]])).toEqual([[2, 5]]);
expect(arrayDifference([[2, 5], [7, 10]], [[2, 6], [4, 11]])).toEqual([]);
expect(
arrayDifference(
[[2, 7], [8, 13]],
[[1, 3], [4, 5], [6, 9], [10, 11], [12, 14]]
[
[2, 5],
[7, 10],
],
[
[2, 6],
[4, 11],
]
)
).toEqual([[3, 4], [5, 6], [9, 10], [11, 12]]);
).toEqual([]);
expect(
arrayDifference(
[
[2, 7],
[8, 13],
],
[
[1, 3],
[4, 5],
[6, 9],
[10, 11],
[12, 14],
]
)
).toEqual([
[3, 4],
[5, 6],
[9, 10],
[11, 12],
]);
});
});

@@ -1,4 +0,4 @@

import { Interval } from './types';
import { union } from './union';
import { hasOverlap } from './helpers';
import { Interval } from "./types";
import { union } from "./union";
import { hasOverlap } from "./helpers";

@@ -12,3 +12,6 @@ export function difference(a: Interval, b: Interval): Interval[] | null {

if (b[0] > a[0] && b[1] < a[1]) {
return [[a[0], b[0]], [b[1], a[1]]];
return [
[a[0], b[0]],
[b[1], a[1]],
];
}

@@ -15,0 +18,0 @@ // b contains a

@@ -1,5 +0,5 @@

import { sortByStart, sortByEnd, hasOverlap } from './helpers';
import { sortByStart, sortByEnd, hasOverlap } from "./helpers";
describe('helpers', () => {
test('sortByStart', () => {
describe("helpers", () => {
test("sortByStart", () => {
expect(sortByStart([0, 4], [1, 2])).toBe(-1);

@@ -10,3 +10,3 @@ expect(sortByStart([2, 4], [1, 2])).toBe(1);

test('sortByEnd', () => {
test("sortByEnd", () => {
expect(sortByEnd([0, 2], [1, 3])).toBe(-1);

@@ -17,3 +17,3 @@ expect(sortByEnd([2, 3], [1, 2])).toBe(1);

test('hasOverlap', () => {
test("hasOverlap", () => {
expect(hasOverlap([0, 2], [3, 4])).toBe(false);

@@ -20,0 +20,0 @@ expect(hasOverlap([0, 2], [2, 3])).toBe(false);

@@ -1,2 +0,2 @@

import { Interval } from './types';
import { Interval } from "./types";

@@ -3,0 +3,0 @@ type SortResult = -1 | 0 | 1;

@@ -1,5 +0,5 @@

import { intersection, arrayIntersection } from './intersection';
import { intersection, arrayIntersection } from "./intersection";
describe('intersection', () => {
test('intersection', () => {
describe("intersection", () => {
test("intersection", () => {
expect(intersection([1, 2], [3, 4])).toBeNull();

@@ -9,11 +9,47 @@ expect(intersection([1, 3], [2, 4])).toEqual([2, 3]);

test('arrayIntersection', () => {
expect(arrayIntersection([[1, 2], [3, 4]], [[2, 3], [4, 5]])).toEqual([]);
expect(arrayIntersection([[1, 2], [3, 5]], [[2, 3], [4, 6]])).toEqual([
[4, 5]
test("arrayIntersection", () => {
expect(
arrayIntersection(
[
[1, 2],
[3, 4],
],
[
[2, 3],
[4, 5],
]
)
).toEqual([]);
expect(
arrayIntersection(
[
[1, 2],
[3, 5],
],
[
[2, 3],
[4, 6],
]
)
).toEqual([[4, 5]]);
expect(
arrayIntersection(
[
[1, 4],
[5, 8],
],
[
[2, 5],
[6, 9],
],
[
[0, 3],
[7, 10],
]
)
).toEqual([
[2, 3],
[7, 8],
]);
expect(
arrayIntersection([[1, 4], [5, 8]], [[2, 5], [6, 9]], [[0, 3], [7, 10]])
).toEqual([[2, 3], [7, 8]]);
});
});

@@ -1,3 +0,3 @@

import { Interval } from './types';
import { sortByStart, sortByEnd } from './helpers';
import { Interval } from "./types";
import { sortByStart, sortByEnd } from "./helpers";

@@ -8,3 +8,3 @@ export function intersection(...intervals: Interval[]): Interval | null {

intervals[intervals.length - 1][0],
intervals.sort(sortByEnd)[0][1]
intervals.sort(sortByEnd)[0][1],
];

@@ -11,0 +11,0 @@ for (let i = 0, n = intervals.length; i < n - 1; i++) {

@@ -1,4 +0,4 @@

export { union, arrayUnion } from './union';
export { difference, arrayDifference } from './difference';
export { intersection, arrayIntersection } from './intersection';
export { contains, arrayContains } from './contains';
export { union, arrayUnion } from "./union";
export { difference, arrayDifference } from "./difference";
export { intersection, arrayIntersection } from "./intersection";
export { contains, arrayContains } from "./contains";
export type IntervalPoint = number | Date;
export type Interval = [IntervalPoint, IntervalPoint];

@@ -1,16 +0,38 @@

import { union, arrayUnion } from './union';
import { union, arrayUnion } from "./union";
describe('union', () => {
test('union', () => {
describe("union", () => {
test("union", () => {
expect(union()).toEqual([]);
expect(union([1, 2], [3, 4])).toEqual([[1, 2], [3, 4]]);
expect(union([1, 3], [2, 4], [5, 6])).toEqual([[1, 4], [5, 6]]);
expect(union([1, 2], [3, 4])).toEqual([
[1, 2],
[3, 4],
]);
expect(union([1, 3], [2, 4], [5, 6])).toEqual([
[1, 4],
[5, 6],
]);
});
test('arrayUnion', () => {
test("arrayUnion", () => {
expect(arrayUnion()).toEqual([]);
expect(
arrayUnion([[1, 2], [3, 4]], [[2, 3], [5, 7]], [[0, 3], [6, 8]])
).toEqual([[0, 4], [5, 8]]);
arrayUnion(
[
[1, 2],
[3, 4],
],
[
[2, 3],
[5, 7],
],
[
[0, 3],
[6, 8],
]
)
).toEqual([
[0, 4],
[5, 8],
]);
});
});

@@ -1,3 +0,3 @@

import { Interval } from './types';
import { sortByStart } from './helpers';
import { Interval } from "./types";
import { sortByStart } from "./helpers";

@@ -4,0 +4,0 @@ export function union(...intervals: Interval[]): Interval[] {

@@ -0,0 +0,0 @@ {

Sorry, the diff of this file is not supported yet

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