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

ranges-set

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

ranges-set - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

2

index.js

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

var n=/^\s*(?:0|[1-9]\d*)\s*$/,t=/^\s*(0|[1-9]\d*)\s*-\s*(0|[1-9]\d*)\s*$/;function r(n,t){if(n.kind!==t.kind)return null;switch(n.kind){case 0:return n.text===t.text?n:null;case 1:var r=Math.max(n.min,t.min),i=Math.min(n.max,t.max);return r>i?null:{kind:1,min:r,max:i}}}function i(n,t){if(n.kind!==t.kind)return n.kind-t.kind;switch(n.kind){case 0:return n.text<t.text?-1:1;case 1:return n.min-t.min||n.max-t.max}}function e(n){return n.split(",").filter(Boolean).map(a)}function a(r){if(n.test(r))return{kind:1,min:+r,max:+r};var i=t.exec(r);return i?{kind:1,min:+i[1],max:+i[2]}:{kind:0,text:r}}function u(n){return n.map(m).join()}function m(n){switch(n.kind){case 0:return n.text;case 1:return n.min===n.max?""+n.min:n.min+"-"+n.max}}function c(n,t){return 0!==n.length&&function(n,t){if(n.kind!==t.kind)return!1;switch(n.kind){case 0:return n.text===t.text;case 1:var r=n.min<=t.max+1&&n.max>=t.min||t.min<=n.max+1&&t.max>=n.min;return r&&(n.min=Math.min(n.min,t.min),n.max=Math.max(n.max,t.max)),r}}(n[n.length-1],t)||n.push(t),n}function x(n){return n.sort(i).reduce(c,[])}exports.difference=function(n,t){return u(function(n,t){var r=[];n:for(var i=0;i<n.length;++i){var e=n[i];switch(e.kind){case 0:for(var a=0;a<t.length;++a){var u=t[a];if(0===u.kind&&u.text===e.text)continue n}r.push(e);break;case 1:for(var m=0;m<t.length;++m){var c=t[m];if(1===c.kind){if(e.min>=c.min&&e.max<=c.max)continue n;e.min>=c.min&&e.min<=c.max?e.min=c.max+1:e.max>=c.min&&e.max<=c.max&&(e.max=c.min-1)}}r.push(e)}}return r}(x(e(n)),x(e(t))))},exports.expand=function(n){return function(n){for(var t=[],r=0;r<n.length;++r){var i=n[r];switch(i.kind){case 0:t.push(i.text);break;case 1:for(var e=i.min;e<=i.max;++e)t.push(""+e)}}return t}(x(e(n)))},exports.intersection=function(n,t){return u(function(n,t){for(var i=[],e=0;e<n.length;++e)for(var a=n[e],u=0;u<t.length;++u){var m=r(a,t[u]);null!==m&&i.push(m)}return i}(x(e(n)),x(e(t))))},exports.normalize=function(n){return u(x(e(n)))},exports.subset=function(n,t){return function(n,t){n:for(var r=0;r<t.length;++r){var i=t[r];switch(i.kind){case 0:for(var e=0;e<n.length;++e){var a=n[e];if(0===a.kind&&a.text===i.text)continue n}return!1;case 1:for(var u=0;u<n.length;++u){var m=n[u];if(1===m.kind&&i.min>=m.min&&i.max<=m.max)continue n}return!1}}return!0}(x(e(n)),x(e(t)))},exports.union=function(n,t){var r=x(e(n)),i=x(e(t));return u(x(r.concat(i)))};
var n=/^\s*(?:0|[1-9]\d*)\s*$/,t=/^\s*(0|[1-9]\d*)\s*-\s*(0|[1-9]\d*)\s*$/;function i(n,t){if(n.kind!==t.kind)return null;switch(n.kind){case 0:return n.text===t.text?n:null;case 1:var i=Math.max(n.min,t.min),r=Math.min(n.max,t.max);return i>r?null:{kind:1,min:i,max:r}}}function r(n,t){if(n.kind!==t.kind)return n.kind-t.kind;switch(n.kind){case 0:return n.text<t.text?-1:1;case 1:return n.min-t.min||n.max-t.max}}function e(n){return n.split(",").filter(Boolean).map(a)}function a(i){if(n.test(i))return{kind:1,min:+i,max:+i};var r=t.exec(i);return r?{kind:1,min:+r[1],max:+r[2]}:{kind:0,text:i}}function m(n){return n.map(u).join()}function u(n){switch(n.kind){case 0:return n.text;case 1:return n.min===n.max?""+n.min:n.min+"-"+n.max}}function x(n,t){return 0!==n.length&&function(n,t){if(n.kind!==t.kind)return!1;switch(n.kind){case 0:return n.text===t.text;case 1:var i=n.min<=t.max+1&&n.max>=t.min||t.min<=n.max+1&&t.max>=n.min;return i&&(n.min=Math.min(n.min,t.min),n.max=Math.max(n.max,t.max)),i}}(n[n.length-1],t)||n.push(t),n}function c(n){return n.sort(r).reduce(x,[])}exports.difference=function(n,t){return m(function(n,t){var i=[];n:for(var r=0;r<n.length;++r){var e=n[r];switch(e.kind){case 0:for(var a=0;a<t.length;++a){var m=t[a];if(0===m.kind&&m.text===e.text)continue n}i.push(e);break;case 1:for(var u=0;u<t.length;++u){var x=t[u];if(1===x.kind){if(e.min>=x.min&&e.max<=x.max)continue n;if(e.min<=x.min&&e.max>=x.max){e.max>x.max&&n.splice(r+1,0,{kind:1,min:x.max+1,max:e.max}),e.min<x.min&&n.splice(r+1,0,{kind:1,min:e.min,max:x.min-1});continue n}e.min>=x.min&&e.min<=x.max?e.min=x.max+1:e.max>=x.min&&e.max<=x.max&&(e.max=x.min-1)}}i.push(e)}}return i}(c(e(n)),c(e(t))))},exports.expand=function(n){return function(n){for(var t=[],i=0;i<n.length;++i){var r=n[i];switch(r.kind){case 0:t.push(r.text);break;case 1:for(var e=r.min;e<=r.max;++e)t.push(""+e)}}return t}(c(e(n)))},exports.intersection=function(n,t){return m(function(n,t){for(var r=[],e=0;e<n.length;++e)for(var a=n[e],m=0;m<t.length;++m){var u=i(a,t[m]);null!==u&&r.push(u)}return r}(c(e(n)),c(e(t))))},exports.normalize=function(n){return m(c(e(n)))},exports.subset=function(n,t){return function(n,t){n:for(var i=0;i<t.length;++i){var r=t[i];switch(r.kind){case 0:for(var e=0;e<n.length;++e){var a=n[e];if(0===a.kind&&a.text===r.text)continue n}return!1;case 1:for(var m=0;m<n.length;++m){var u=n[m];if(1===u.kind&&r.min>=u.min&&r.max<=u.max)continue n}return!1}}return!0}(c(e(n)),c(e(t)))},exports.union=function(n,t){var i=c(e(n)),r=c(e(t));return m(c(i.concat(r)))};
//# sourceMappingURL=index.js.map

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

const n=/^\s*(?:0|[1-9]\d*)\s*$/,t=/^\s*(0|[1-9]\d*)\s*-\s*(0|[1-9]\d*)\s*$/;function i(n,t){return s(function(n,t){const i=[];n:for(let e=0;e<n.length;++e){const r=n[e];switch(r.kind){case 0:for(let n=0;n<t.length;++n){const i=t[n];if(0===i.kind&&i.text===r.text)continue n}i.push(r);break;case 1:for(let n=0;n<t.length;++n){const i=t[n];if(1===i.kind){if(r.min>=i.min&&r.max<=i.max)continue n;r.min>=i.min&&r.min<=i.max?r.min=i.max+1:r.max>=i.min&&r.max<=i.max&&(r.max=i.min-1)}}i.push(r)}}return i}(d(o(n)),d(o(t))))}function e(n){return function(n){const t=[];for(let i=0;i<n.length;++i){const e=n[i];switch(e.kind){case 0:t.push(e.text);break;case 1:for(let n=e.min;n<=e.max;++n)t.push(`${n}`)}}return t}(d(o(n)))}function r(n,t){return s(function(n,t){const i=[];for(let e=0;e<n.length;++e){const r=n[e];for(let n=0;n<t.length;++n){const e=c(r,t[n]);null!==e&&i.push(e)}}return i}(d(o(n)),d(o(t))))}function c(n,t){if(n.kind!==t.kind)return null;switch(n.kind){case 0:return n.text===t.text?n:null;case 1:{const i=Math.max(n.min,t.min),e=Math.min(n.max,t.max);return i>e?null:{kind:1,min:i,max:e}}}}function u(n){return s(d(o(n)))}function m(n,t){if(n.kind!==t.kind)return n.kind-t.kind;switch(n.kind){case 0:return n.text<t.text?-1:1;case 1:return n.min-t.min||n.max-t.max}}function o(n){return n.split(",").filter(Boolean).map(a)}function a(i){if(n.test(i))return{kind:1,min:+i,max:+i};const e=t.exec(i);return e?{kind:1,min:+e[1],max:+e[2]}:{kind:0,text:i}}function s(n){return n.map(x).join()}function x(n){switch(n.kind){case 0:return n.text;case 1:return n.min===n.max?`${n.min}`:`${n.min}-${n.max}`}}function f(n,t){return function(n,t){n:for(let i=0;i<t.length;++i){const e=t[i];switch(e.kind){case 0:for(let t=0;t<n.length;++t){const i=n[t];if(0===i.kind&&i.text===e.text)continue n}return!1;case 1:for(let t=0;t<n.length;++t){const i=n[t];if(1===i.kind&&e.min>=i.min&&e.max<=i.max)continue n}return!1}}return!0}(d(o(n)),d(o(t)))}function l(n,t){const i=d(o(n)),e=d(o(t));return s(d(i.concat(e)))}function h(n,t){return 0!==n.length&&function(n,t){if(n.kind!==t.kind)return!1;switch(n.kind){case 0:return n.text===t.text;case 1:{const i=n.min<=t.max+1&&n.max>=t.min||t.min<=n.max+1&&t.max>=n.min;return i&&(n.min=Math.min(n.min,t.min),n.max=Math.max(n.max,t.max)),i}}}(n[n.length-1],t)||n.push(t),n}function d(n){return n.sort(m).reduce(h,[])}export{i as difference,e as expand,r as intersection,u as normalize,f as subset,l as union};
const n=/^\s*(?:0|[1-9]\d*)\s*$/,t=/^\s*(0|[1-9]\d*)\s*-\s*(0|[1-9]\d*)\s*$/;function i(n,t){return s(function(n,t){const i=[];n:for(let e=0;e<n.length;++e){const m=n[e];switch(m.kind){case 0:for(let n=0;n<t.length;++n){const i=t[n];if(0===i.kind&&i.text===m.text)continue n}i.push(m);break;case 1:for(let i=0;i<t.length;++i){const r=t[i];if(1===r.kind){if(m.min>=r.min&&m.max<=r.max)continue n;if(m.min<=r.min&&m.max>=r.max){m.max>r.max&&n.splice(e+1,0,{kind:1,min:r.max+1,max:m.max}),m.min<r.min&&n.splice(e+1,0,{kind:1,min:m.min,max:r.min-1});continue n}m.min>=r.min&&m.min<=r.max?m.min=r.max+1:m.max>=r.min&&m.max<=r.max&&(m.max=r.min-1)}}i.push(m)}}return i}(h(a(n)),h(a(t))))}function e(n){return function(n){const t=[];for(let i=0;i<n.length;++i){const e=n[i];switch(e.kind){case 0:t.push(e.text);break;case 1:for(let n=e.min;n<=e.max;++n)t.push(`${n}`)}}return t}(h(a(n)))}function m(n,t){return s(function(n,t){const i=[];for(let e=0;e<n.length;++e){const m=n[e];for(let n=0;n<t.length;++n){const e=r(m,t[n]);null!==e&&i.push(e)}}return i}(h(a(n)),h(a(t))))}function r(n,t){if(n.kind!==t.kind)return null;switch(n.kind){case 0:return n.text===t.text?n:null;case 1:{const i=Math.max(n.min,t.min),e=Math.min(n.max,t.max);return i>e?null:{kind:1,min:i,max:e}}}}function c(n){return s(h(a(n)))}function u(n,t){if(n.kind!==t.kind)return n.kind-t.kind;switch(n.kind){case 0:return n.text<t.text?-1:1;case 1:return n.min-t.min||n.max-t.max}}function a(n){return n.split(",").filter(Boolean).map(o)}function o(i){if(n.test(i))return{kind:1,min:+i,max:+i};const e=t.exec(i);return e?{kind:1,min:+e[1],max:+e[2]}:{kind:0,text:i}}function s(n){return n.map(x).join()}function x(n){switch(n.kind){case 0:return n.text;case 1:return n.min===n.max?`${n.min}`:`${n.min}-${n.max}`}}function f(n,t){return function(n,t){n:for(let i=0;i<t.length;++i){const e=t[i];switch(e.kind){case 0:for(let t=0;t<n.length;++t){const i=n[t];if(0===i.kind&&i.text===e.text)continue n}return!1;case 1:for(let t=0;t<n.length;++t){const i=n[t];if(1===i.kind&&e.min>=i.min&&e.max<=i.max)continue n}return!1}}return!0}(h(a(n)),h(a(t)))}function l(n,t){const i=h(a(n)),e=h(a(t));return s(h(i.concat(e)))}function d(n,t){return 0!==n.length&&function(n,t){if(n.kind!==t.kind)return!1;switch(n.kind){case 0:return n.text===t.text;case 1:{const i=n.min<=t.max+1&&n.max>=t.min||t.min<=n.max+1&&t.max>=n.min;return i&&(n.min=Math.min(n.min,t.min),n.max=Math.max(n.max,t.max)),i}}}(n[n.length-1],t)||n.push(t),n}function h(n){return n.sort(u).reduce(d,[])}export{i as difference,e as expand,m as intersection,c as normalize,f as subset,l as union};
//# sourceMappingURL=index.modern.js.map

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

var n=/^\s*(?:0|[1-9]\d*)\s*$/,t=/^\s*(0|[1-9]\d*)\s*-\s*(0|[1-9]\d*)\s*$/;function r(n,t){return f(function(n,t){var r=[];n:for(var i=0;i<n.length;++i){var e=n[i];switch(e.kind){case 0:for(var a=0;a<t.length;++a){var u=t[a];if(0===u.kind&&u.text===e.text)continue n}r.push(e);break;case 1:for(var m=0;m<t.length;++m){var c=t[m];if(1===c.kind){if(e.min>=c.min&&e.max<=c.max)continue n;e.min>=c.min&&e.min<=c.max?e.min=c.max+1:e.max>=c.min&&e.max<=c.max&&(e.max=c.min-1)}}r.push(e)}}return r}(k(c(n)),k(c(t))))}function i(n){return function(n){for(var t=[],r=0;r<n.length;++r){var i=n[r];switch(i.kind){case 0:t.push(i.text);break;case 1:for(var e=i.min;e<=i.max;++e)t.push(""+e)}}return t}(k(c(n)))}function e(n,t){return f(function(n,t){for(var r=[],i=0;i<n.length;++i)for(var e=n[i],u=0;u<t.length;++u){var m=a(e,t[u]);null!==m&&r.push(m)}return r}(k(c(n)),k(c(t))))}function a(n,t){if(n.kind!==t.kind)return null;switch(n.kind){case 0:return n.text===t.text?n:null;case 1:var r=Math.max(n.min,t.min),i=Math.min(n.max,t.max);return r>i?null:{kind:1,min:r,max:i}}}function u(n){return f(k(c(n)))}function m(n,t){if(n.kind!==t.kind)return n.kind-t.kind;switch(n.kind){case 0:return n.text<t.text?-1:1;case 1:return n.min-t.min||n.max-t.max}}function c(n){return n.split(",").filter(Boolean).map(x)}function x(r){if(n.test(r))return{kind:1,min:+r,max:+r};var i=t.exec(r);return i?{kind:1,min:+i[1],max:+i[2]}:{kind:0,text:r}}function f(n){return n.map(o).join()}function o(n){switch(n.kind){case 0:return n.text;case 1:return n.min===n.max?""+n.min:n.min+"-"+n.max}}function s(n,t){return function(n,t){n:for(var r=0;r<t.length;++r){var i=t[r];switch(i.kind){case 0:for(var e=0;e<n.length;++e){var a=n[e];if(0===a.kind&&a.text===i.text)continue n}return!1;case 1:for(var u=0;u<n.length;++u){var m=n[u];if(1===m.kind&&i.min>=m.min&&i.max<=m.max)continue n}return!1}}return!0}(k(c(n)),k(c(t)))}function h(n,t){var r=k(c(n)),i=k(c(t));return f(k(r.concat(i)))}function d(n,t){return 0!==n.length&&function(n,t){if(n.kind!==t.kind)return!1;switch(n.kind){case 0:return n.text===t.text;case 1:var r=n.min<=t.max+1&&n.max>=t.min||t.min<=n.max+1&&t.max>=n.min;return r&&(n.min=Math.min(n.min,t.min),n.max=Math.max(n.max,t.max)),r}}(n[n.length-1],t)||n.push(t),n}function k(n){return n.sort(m).reduce(d,[])}export{r as difference,i as expand,e as intersection,u as normalize,s as subset,h as union};
var n=/^\s*(?:0|[1-9]\d*)\s*$/,i=/^\s*(0|[1-9]\d*)\s*-\s*(0|[1-9]\d*)\s*$/;function t(n,i){return f(function(n,i){var t=[];n:for(var r=0;r<n.length;++r){var a=n[r];switch(a.kind){case 0:for(var e=0;e<i.length;++e){var m=i[e];if(0===m.kind&&m.text===a.text)continue n}t.push(a);break;case 1:for(var u=0;u<i.length;++u){var x=i[u];if(1===x.kind){if(a.min>=x.min&&a.max<=x.max)continue n;if(a.min<=x.min&&a.max>=x.max){a.max>x.max&&n.splice(r+1,0,{kind:1,min:x.max+1,max:a.max}),a.min<x.min&&n.splice(r+1,0,{kind:1,min:a.min,max:x.min-1});continue n}a.min>=x.min&&a.min<=x.max?a.min=x.max+1:a.max>=x.min&&a.max<=x.max&&(a.max=x.min-1)}}t.push(a)}}return t}(k(x(n)),k(x(i))))}function r(n){return function(n){for(var i=[],t=0;t<n.length;++t){var r=n[t];switch(r.kind){case 0:i.push(r.text);break;case 1:for(var a=r.min;a<=r.max;++a)i.push(""+a)}}return i}(k(x(n)))}function a(n,i){return f(function(n,i){for(var t=[],r=0;r<n.length;++r)for(var a=n[r],m=0;m<i.length;++m){var u=e(a,i[m]);null!==u&&t.push(u)}return t}(k(x(n)),k(x(i))))}function e(n,i){if(n.kind!==i.kind)return null;switch(n.kind){case 0:return n.text===i.text?n:null;case 1:var t=Math.max(n.min,i.min),r=Math.min(n.max,i.max);return t>r?null:{kind:1,min:t,max:r}}}function m(n){return f(k(x(n)))}function u(n,i){if(n.kind!==i.kind)return n.kind-i.kind;switch(n.kind){case 0:return n.text<i.text?-1:1;case 1:return n.min-i.min||n.max-i.max}}function x(n){return n.split(",").filter(Boolean).map(c)}function c(t){if(n.test(t))return{kind:1,min:+t,max:+t};var r=i.exec(t);return r?{kind:1,min:+r[1],max:+r[2]}:{kind:0,text:t}}function f(n){return n.map(o).join()}function o(n){switch(n.kind){case 0:return n.text;case 1:return n.min===n.max?""+n.min:n.min+"-"+n.max}}function s(n,i){return function(n,i){n:for(var t=0;t<i.length;++t){var r=i[t];switch(r.kind){case 0:for(var a=0;a<n.length;++a){var e=n[a];if(0===e.kind&&e.text===r.text)continue n}return!1;case 1:for(var m=0;m<n.length;++m){var u=n[m];if(1===u.kind&&r.min>=u.min&&r.max<=u.max)continue n}return!1}}return!0}(k(x(n)),k(x(i)))}function d(n,i){var t=k(x(n)),r=k(x(i));return f(k(t.concat(r)))}function h(n,i){return 0!==n.length&&function(n,i){if(n.kind!==i.kind)return!1;switch(n.kind){case 0:return n.text===i.text;case 1:var t=n.min<=i.max+1&&n.max>=i.min||i.min<=n.max+1&&i.max>=n.min;return t&&(n.min=Math.min(n.min,i.min),n.max=Math.max(n.max,i.max)),t}}(n[n.length-1],i)||n.push(i),n}function k(n){return n.sort(u).reduce(h,[])}export{t as difference,r as expand,a as intersection,m as normalize,s as subset,d as union};
//# sourceMappingURL=index.module.js.map

@@ -42,2 +42,22 @@ const KindLiteral = 0;

if (reprA.min <= reprB.min && reprA.max >= reprB.max) {
if (reprA.max > reprB.max) {
reprsA.splice(indexA + 1, 0, {
kind: KindRange,
min: reprB.max + 1,
max: reprA.max,
});
}
if (reprA.min < reprB.min) {
reprsA.splice(indexA + 1, 0, {
kind: KindRange,
min: reprA.min,
max: reprB.min - 1,
});
}
continue loop;
}
if (reprA.min >= reprB.min && reprA.min <= reprB.max) {

@@ -44,0 +64,0 @@ reprA.min = reprB.max + 1;

{
"name": "ranges-set",
"version": "1.0.1",
"version": "1.0.2",
"description": "Set operations on human-friendly ranges.",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -35,2 +35,7 @@ import test from 'ava';

['1-5', '1-2,4-5', '3'],
['1-6', '1,3,6', '2,4-5'],
['1-6', '1,4', '2-3,5-6'],
['1-6', '1,6', '2-5'],
['1-6', '2,4', '1,3,5-6'],
['1-6', '2-5', '1,6'],
['2', '1', '2'],

@@ -37,0 +42,0 @@ ['2-100', '1', '2-100'],

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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