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

patrun

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

patrun - npm Package Compare versions

Comparing version 6.0.1 to 7.0.0

dist/lib/matchers.d.ts

3

dist/patrun.d.ts

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

declare const gex: any;
declare function Patrun(custom: any): any;
export {};

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

/* Copyright (c) 2013-2020 Richard Rodger, MIT License, https://github.com/rjrodger/patrun */
"use strict";
/* Copyright (c) 2013-2020 Richard Rodger, MIT License */
Object.defineProperty(exports, "__esModule", { value: true });
// TODO: matchers should accept string[] of key names - only operate on these keys
// TODO: expose walk as method for general purpose
const gex = require('gex');
const gex_1 = require("gex");
const matchers_1 = require("./lib/matchers");
module.exports = function (custom) {

@@ -11,2 +15,9 @@ return new Patrun(custom);

var top = {};
let matchers = [];
if (custom.gex) {
matchers.push(new matchers_1.GexMatcher());
}
if (custom.interval) {
matchers.push(new matchers_1.IntervalMatcher());
}
// Provide internal search order structure

@@ -19,57 +30,86 @@ self.top = function () {

var customizer = 'function' === typeof custom ? custom.call(self, pat, data) : null;
var keys = Object.keys(pat);
var plains = [];
var gexers = [];
var keys = Object.keys(pat)
.filter((key) => null != pat[key])
.sort();
keys.forEach(function (key) {
var val = pat[key];
if (null == val)
return;
val = String(val);
pat[key] = val;
(custom.gex && val.match(/[*?]/) ? gexers : plains).push(key);
pat[key] = String(pat[key]);
});
plains = plains.sort();
gexers = gexers.sort();
keys = plains.concat(gexers);
var keymap = top;
var valmap;
// Partial matches return next wider match - see partial-match test
// Partial matches return next wider match - see partial-match test.
// Traverse the key path (keys are ordered), insert preserves order.
for (var i = 0; i < keys.length; i++) {
// console.log('L', i, keys.length)
var key = keys[i];
var val = pat[key];
var gexer = custom.gex && val.match(/[*?]/) ? gex(val) : null;
if (gexer)
gexer.val$ = val;
var sort_prefix = (gexer ? '1' : '0') + '~';
var sort_key = sort_prefix + key;
var fix = pat[key];
let mv = matchers.reduce((m, t) => m || t.make(key, fix), undefined);
// if (mv) mv.val$ = fix
valmap = keymap.v;
if (valmap && sort_key == keymap.sk) {
add_gexer(keymap, key, gexer);
keymap = valmap[val] || (valmap[val] = {});
// console.log('S0',key,fix,keymap,valmap)
// An existing key
if (valmap && key == keymap.k) {
// console.log('S1-a')
// add_mv(keymap, key, mv)
if (mv) {
var g = (keymap.g = keymap.g || {});
var ga = (g[key] = g[key] || []);
mv = (ga.find((gmv) => gmv.same(mv)) ||
(ga.push(mv), mv));
keymap = mv.keymap || (mv.keymap = {});
}
else {
keymap = valmap[fix] || (valmap[fix] = {});
}
}
// End of key path reached, so this is a new key, ordered last
else if (!keymap.k) {
add_gexer(keymap, key, gexer);
keymap.k = key;
keymap.sk = sort_key;
keymap.v = {};
keymap = keymap.v[val] = {};
if (mv) {
var g = (keymap.g = keymap.g || {});
var ga = (g[key] = g[key] || []);
mv = (ga.find((gmv) => gmv.same(mv)) ||
(ga.push(mv), mv));
keymap = mv.keymap || (mv.keymap = {});
}
else {
keymap = keymap.v[fix] = {};
}
}
else if (sort_key < keymap.sk) {
var s = keymap.s, g = keymap.g;
keymap.s = { k: keymap.k, sk: keymap.sk, v: keymap.v };
if (s)
// Insert key orders before next existing key in path, so insert
else if (key < keymap.k) {
// console.log('S1-c', key, keymap.k)
var s = keymap.s;
var g = keymap.g;
keymap.s = {
k: keymap.k,
// sk: keymap.sk,
v: keymap.v,
};
if (s) {
keymap.s.s = s;
if (g)
}
if (g) {
keymap.s.g = g;
if (keymap.g)
}
if (keymap.g) {
keymap.g = {};
add_gexer(keymap, key, gexer);
}
keymap.k = key;
keymap.sk = sort_key;
keymap.v = {};
keymap = keymap.v[val] = {};
if (mv) {
var g = (keymap.g = keymap.g || {});
var ga = (g[key] = g[key] || []);
mv = (ga.find((gmv) => gmv.same(mv)) ||
(ga.push(mv), mv));
keymap = mv.keymap || (mv.keymap = {});
}
else {
keymap = keymap.v[fix] = {};
}
}
// Follow star path
else {
valmap = keymap.v;
keymap = keymap.s || (keymap.s = {});
// NOTE: current key is still not inserted
i--;

@@ -89,12 +129,2 @@ }

};
function add_gexer(keymap, key, gexer) {
if (!gexer)
return;
var g = (keymap.g = keymap.g || {});
var ga = (g[key] = g[key] || []);
ga.push(gexer);
ga.sort(function (a, b) {
return a.val$ < b.val$;
});
}
self.findexact = function (pat) {

@@ -124,7 +154,7 @@ return self.find(pat, true);

var nextkeymap = keymap.v[val];
if (!nextkeymap && custom.gex && keymap.g && keymap.g[key]) {
if (!nextkeymap && keymap.g && keymap.g[key]) {
var ga = keymap.g[key];
for (var gi = 0; gi < ga.length; gi++) {
if (null != ga[gi].on(val)) {
nextkeymap = keymap.v[ga[gi].val$];
if (ga[gi].match(val)) {
nextkeymap = ga[gi].keymap;
break;

@@ -183,7 +213,22 @@ }

key = keymap.k;
if (keymap.v) {
// TODO: equivalence match as per find
var nextkeymap = keymap.v[pat[key]];
// console.log('keymap v g', keymap.v, keymap.g)
if (keymap.v || keymap.g) {
if (keymap.v) {
var nextkeymap = keymap.v[pat[key]];
if (nextkeymap) {
path.push({ km: keymap, v: pat[key] });
}
}
if (null == nextkeymap && keymap.g) {
let mvs = keymap.g[key] || [];
for (let mvi = 0; mvi < mvs.length; mvi++) {
// TODO: should parse!
if (mvs[mvi].fix === pat[key]) {
path.push({ km: keymap, v: pat[key], mv: mvs[mvi] });
nextkeymap = mvs[mvi].keymap;
break;
}
}
}
if (nextkeymap) {
path.push({ km: keymap, v: pat[key] });
data = nextkeymap.d;

@@ -203,4 +248,4 @@ keymap = nextkeymap;

if (part && part.km && part.km.v) {
var point = part.km.v[part.v];
if (!point.r || point.r(pat, point.d)) {
var point = part.km.v[part.v] || (part.mv && part.mv.keymap);
if (point && (!point.r || point.r(pat, point.d))) {
delete point.d;

@@ -217,3 +262,3 @@ }

var key = keymap.k;
var gexval = gex(pat ? (null == pat[key] ? (exact ? null : '*') : pat[key]) : '*');
var gexval = gex_1.Gex(pat ? (null == pat[key] ? (exact ? null : '*') : pat[key]) : '*');
var itermatch = { ...match };

@@ -286,14 +331,8 @@ var itermissing = { ...missing };

}
if (n.v || n.s || n.g) {
d++;
}
if (n.v) {
d++;
var pa = Object.keys(n.v);
var pal = pa.filter(function (x) {
return !x.match(/[*?]/);
});
var pas = pa.filter(function (x) {
return x.match(/[*?]/);
});
pal.sort();
pas.sort();
pa = pal.concat(pas);
// d++
var pa = Object.keys(n.v).sort();
for (var pi = 0; pi < pa.length; pi++) {

@@ -308,10 +347,25 @@ var p = pa[pi];

}
if (n.s) {
o.push('\n');
indent(o, d);
o.push('|');
vsc = vs.slice();
walk(n.s, o, d + 1, vsc);
}
if (n.g) {
var pa = Object.keys(n.g).sort();
for (var pi = 0; pi < pa.length; pi++) {
var mvs = n.g[pa[pi]];
for (var mvi = 0; mvi < mvs.length; mvi++) {
var mv = mvs[mvi];
o.push('\n');
indent(o, d);
o.push(mv.fix + ' ~>');
vsc = vs.slice();
vsc.push(n.k + '~' + mv.fix);
walk(mv.keymap, o, d + 1, vsc);
}
}
}
if (n.s) {
o.push('\n');
indent(o, d);
o.push('|');
vsc = vs.slice();
walk(n.s, o, d + 1, vsc);
}
}

@@ -318,0 +372,0 @@ var o = [];

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

!function(n){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=n();else if("function"==typeof define&&define.amd)define([],n);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).Patrun=n()}}((function(){var n={exports:{}};function e(e){e=e||{};var t={},r={};function o(n,e,t){if(t){var r=n.g=n.g||{},o=r[e]=r[e]||[];o.push(t),o.sort((function(n,e){return n.val$<e.val$}))}}return t.top=function(){return r},t.add=function(u,i){u={...u};var f="function"==typeof e?e.call(t,u,i):null,l=Object.keys(u),s=[],c=[];l.forEach((function(n){var t=u[n];null!=t&&(t=String(t),u[n]=t,(e.gex&&t.match(/[*?]/)?c:s).push(n))})),s=s.sort(),c=c.sort(),l=s.concat(c);for(var a,v=r,d=0;d<l.length;d++){var p=l[d],g=u[p],h=e.gex&&g.match(/[*?]/)?n(g):null;h&&(h.val$=g);var y=(h?"1":"0")+"~"+p;if((a=v.v)&&y==v.sk)o(v,p,h),v=a[g]||(a[g]={});else if(v.k)if(y<v.sk){var k=v.s,b=v.g;v.s={k:v.k,sk:v.sk,v:v.v},k&&(v.s.s=k),b&&(v.s.g=b),v.g&&(v.g={}),o(v,p,h),v.k=p,v.sk=y,v.v={},v=v.v[g]={}}else a=v.v,v=v.s||(v.s={}),d--;else o(v,p,h),v.k=p,v.sk=y,v.v={},v=v.v[g]={}}return void 0!==i&&v&&(v.d=i,f&&(v.f="function"==typeof f?f:f.find,v.r="function"==typeof f.remove?f.remove:void 0)),t},t.findexact=function(n){return t.find(n,!0)},t.find=function(n,o,u){if(null==n)return null;var i=r,f=void 0===r.d?null:r.d,l=r.f,s=null,c=[],a={},v=Object.keys(n).length,d=[];void 0!==r.d&&d.push(r.d);do{if(s=i.k,i.v){var p=n[s],g=i.v[p];if(!g&&e.gex&&i.g&&i.g[s])for(var h=i.g[s],y=0;y<h.length;y++)if(null!=h[y].on(p)){g=i.v[h[y].val$];break}g?(a[s]=!0,i.s&&c.push(i.s),f=void 0===g.d?o?null:f:g.d,u&&void 0!==g.d&&d.push(g.d),l=g.f,i=g):i=i.s}else i=null;null==i&&0<c.length&&(null==f||u&&!o)&&(i=c.pop())}while(i);return o?Object.keys(a).length!==v&&(f=null):null==f&&void 0!==r.d&&(f=r.d),l&&(f=l.call(t,n,f)),u?d:f},t.remove=function(n){var e,t=r,o=null,u=[];do{if(e=t.k,t.v){var i=t.v[n[e]];i?(u.push({km:t,v:n[e]}),o=i.d,t=i):t=t.s}else t=null}while(t);if(void 0!==o){var f=u[u.length-1];if(f&&f.km&&f.km.v){var l=f.km.v[f.v];l.r&&!l.r(n,l.d)||delete l.d}}},t.list=function(e,t){e=e||{};var o=[];return r.d&&o.push({match:{},data:r.d,find:r.f}),function r(o,u,i,f){if(o.v){var l,s=o.k,c=n(e?null==e[s]?t?null:"*":e[s]:"*"),a={...u},v={...i};for(var d in o.v)if(d===e[s]||!t&&null==e[s]||c.on(d)){var p={...a};p[s]=d;var g={...v};delete g[s],l=o.v[d],0===Object.keys(g).length&&l&&l.d&&f.push({match:p,data:l.d,find:l.f}),l&&null!=l.v&&r(l,{...p},{...g},f)}(l=o.s)&&r(l,{...a},{...v},f)}}(r,{},{...e},o),o},t.toString=function(n,e){var t=!0===n||!!e,o="function"==typeof n?n:function(n){return"function"==typeof n?"<"+n.name+">":"<"+n+">"};function u(n,e){for(var t=0;t<e;t++)n.push(" ")}var i=[],f=[];return function n(e,t,r,f){var l;if(void 0!==e.d&&(t.push(" "+o(e.d)),i.push(f.join(", ")+" -> "+o(e.d))),e.k&&(t.push("\n"),u(t,r),t.push(e.k+":")),e.v){r++;var s=Object.keys(e.v),c=s.filter((function(n){return!n.match(/[*?]/)})),a=s.filter((function(n){return n.match(/[*?]/)}));c.sort(),a.sort(),s=c.concat(a);for(var v=0;v<s.length;v++){var d=s[v];t.push("\n"),u(t,r),t.push(d+" ->"),(l=f.slice()).push(e.k+"="+d),n(e.v[d],t,r+1,l)}e.s&&(t.push("\n"),u(t,r),t.push("|"),l=f.slice(),n(e.s,t,r+1,l))}}(r,f,0,[]),t?f.join(""):i.join("\n")},t.inspect=t.toString,t.toJSON=function(n){return JSON.stringify(r,(function(n,e){return"function"==typeof e?"[Function]":e}),n)},t}(function(e){!function(t){"object"==typeof n.exports?n.exports=t():("undefined"!=typeof window?window:void 0!==e?e:"undefined"!=typeof self?self:this).Gex=t()}((function(){var n;function e(n){return new t(n)}function t(n){var e=this;function t(n){return null==n||Number.isNaN(n)}function r(n){var e=""+n;return t(n)&&(e=""),e}function o(n){n=""+n;for(var e=!1,t=Object.keys(f),r=0;r<t.length&&!e;r++)e=!!f[t[r]].exec(n);return e}e.on=function(n){if(null==n)return null;var e=typeof n;if("string"===e||"number"===e||"boolean"===e||n instanceof Date||n instanceof RegExp)return o(n)?n:null;if(Array.isArray(n)){for(var r=[],u=0;u<n.length;u++)!t(n[u])&&o(n[u])&&r.push(n[u]);return r}var i={};for(var f in n)Object.prototype.hasOwnProperty.call(n,f)&&o(f)&&(i[f]=n[f]);return i},e.esc=function(n){var e=r(n);return(e=e.replace(/\*/g,"**")).replace(/\?/g,"*?")},e.re=function(n){if(""===n||n)return n="^"+(n=(n=(n=(n=(n=e.escregexp(n)).replace(/\\\*/g,"[\\s\\S]*")).replace(/\\\?/g,"[\\s\\S]")).replace(/\[\\s\\S\]\*\[\\s\\S\]\*/g,"\\*")).replace(/\[\\s\\S\]\*\[\\s\\S\]/g,"\\?"))+"$",new RegExp(n);var t=Object.keys(f);return 1==t.length?f[t[0]]:{...f}},e.escregexp=function(n){return n?(""+n).replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"):""},e.toString=function(){return null!=u?u:u="gex["+Object.keys(f)+"]"},e.inspect=function(){return e.toString()};var u,i=Array.isArray(n)?n:[n],f={};i.forEach((function(n){n=r(n);var t=e.re(n);f[n]=t}))}return n=e,e.Gex=t,n}))}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{}),n=n.exports;return function(n){return new e(n)}}));
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).Patrun=e()}}((function(){var e={exports:{}};(function(t){(function(){!function(n){"object"==typeof e.exports?e.exports=n():("undefined"!=typeof window?window:void 0!==t?t:"undefined"!=typeof self?self:this).Gex=n()}((function(){var e={};Object.defineProperty(e,"__esModule",{value:!0}),e.Gex=void 0;class t{constructor(e){this.desc="",this.gexmap={},(Array.isArray(e)?e:[e]).forEach(e=>{this.gexmap[e]=this.re(this.clean(e))})}dodgy(e){return null==e||Number.isNaN(e)}clean(e){let t=""+e;return this.dodgy(e)?"":t}match(e){e=""+e;let t=!1,n=Object.keys(this.gexmap);for(let r=0;r<n.length&&!t;r++)t=!!this.gexmap[n[r]].exec(e);return t}on(e){if(null==e)return null;let t=typeof e;if("string"===t||"number"===t||"boolean"===t||e instanceof Date||e instanceof RegExp)return this.match(e)?e:null;if(Array.isArray(e)){let t=[];for(let n=0;n<e.length;n++)!this.dodgy(e[n])&&this.match(e[n])&&t.push(e[n]);return t}{let t={};for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&this.match(n)&&(t[n]=e[n]);return t}}esc(e){let t=this.clean(e);return(t=t.replace(/\*/g,"**")).replace(/\?/g,"*?")}escregexp(e){return e?(""+e).replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"):""}re(e){if(""===e||e)return e="^"+(e=(e=(e=(e=(e=this.escregexp(e)).replace(/\\\*/g,"[\\s\\S]*")).replace(/\\\?/g,"[\\s\\S]")).replace(/\[\\s\\S\]\*\[\\s\\S\]\*/g,"\\*")).replace(/\[\\s\\S\]\*\[\\s\\S\]/g,"\\?"))+"$",new RegExp(e);{let e=Object.keys(this.gexmap);return 1==e.length?this.gexmap[e[0]]:{...this.gexmap}}}toString(){let e=this.desc;return""!=e?e:this.desc="Gex["+Object.keys(this.gexmap)+"]"}inspect(){return this.toString()}}return e.Gex=function(e){return new t(e)},e}))}).call(this)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{}),e=e.exports;var t,n,r,i,s,l,o,u,a,f={},h=this&&this.__classPrivateFieldGet||function(e,t){if(!t.has(e))throw new TypeError("attempted to get private field on non-instance");return t.get(e)};Object.defineProperty(f,"__esModule",{value:!0}),f.IntervalMatcher=f.GexMatcher=void 0,f.GexMatcher=class{constructor(){}make(t,n){if("string"==typeof n&&n.match(/[*?]/)){let t=e.Gex(n);return{kind:"gex",match:e=>null!=t.on(e),fix:n,meta:{},same(e){return null!=e&&e.kind===this.kind&&e.fix===this.fix}}}}scan(e,t){let n=e.filter(e=>"*"===e.fix).length>0;return{complete:n,sound:n,gaps:[],overs:[],why:"no-star"}}};const p=new RegExp(["^/s*","(=*[<>/(/[]?=*)?/s*([-+0-9a-fA-FeEoOxX]+(/.([0-9a-fA-FeEoOxX]+))?)([/)/]]?)(/s*(,|&+|/|+|/./.)/s*(=*[<>]?=*)/s*([-+.0-9a-fA-FeEoOxX]+)/s*([/)/]]?))?/s*$"].join("").replace(/\//g,"\\"));class c{constructor(){this.kind="interval",t.set(this,(e,t)=>function(n){return e(n)&&t(n)}),n.set(this,(e,t)=>function(n){return e(n)||t(n)}),r.set(this,e=>function(e){return!1}),i.set(this,e=>function(e){return!1}),s.set(this,e=>function(t){return t>e}),l.set(this,e=>function(t){return t>=e}),o.set(this,e=>function(t){return t<e}),u.set(this,e=>function(t){return t<=e}),a.set(this,e=>function(t){return t===e})}make(e,f){if("string"==typeof f&&f.match(/[=<>.[()\]]/)){let e=f.match(p),d={jo:"and",o0:"err",n0:NaN,o1:"err",n1:NaN},g=e=>!1;if(null!=e){let p=c.normop(e[1])||c.normop(e[5]),m=c.normop(e[8])||c.normop(e[10]),v=h(this,"="===p?a:"<"===p||")"===p?o:"<="===p||"]"===p?u:">"===p||"("===p?s:">="===p||"["===p?l:i),k=Number(e[2]),y=null==e[9]?NaN:Number(e[9]),x=e[7],N=null==x?h(this,n):"&"===x.substring(0,1)||","===x.substring(0,1)?h(this,t):h(this,n);".."===x&&(N=h(this,t),v=h(this,i)===v?h(this,l):v,m=""===m?"<=":m);let w=h(this,null==m?r:"="===m?a:"<"===m||")"===m?o:"<="===m||"]"===m?u:">"===m?s:">="===m?l:i);if(k===y&&("="===p&&null!=m?(y=NaN,w=h(this,r),v=m.includes("<")?h(this,u):m.includes(">")?h(this,l):m.includes("=")?h(this,a):h(this,i)):"="===m&&null!=p&&(y=NaN,w=h(this,r),v=p.includes("<")?h(this,u):p.includes(">")?h(this,l):h(this,i))),h(this,i)!==v&&h(this,r)===w&&(h(this,o)===v||h(this,u)===v?(w=v,y=k,v=h(this,l),k=Number.NEGATIVE_INFINITY,N=h(this,t)):h(this,s)!==v&&h(this,l)!==v||(w=h(this,u),y=Number.POSITIVE_INFINITY,N=h(this,t))),!isNaN(y)&&y<k){let e=w,t=y;y=k,k=t,".."!==x&&(w=v,v=e)}let b=v(k),O=w(y),j=N(b,O);return{kind:"interval",fix:f,meta:d={jo:j.name,o0:b.name,n0:k,o1:O.name,n1:y},match:g=e=>{let t=!1,n=parseFloat(e);return isNaN(n)||(t=j(n)),t},same(e){return null!=e&&e.kind===this.kind&&e.meta.jo===this.meta.jo&&e.meta.o0===this.meta.o0&&e.meta.n0===this.meta.n0&&e.meta.o1===this.meta.o1&&e.meta.n1===this.meta.n1}}}}}scan(e,t){let n={complete:!1,sound:!1,gaps:[],overs:[],lower:null,upper:null},r=Number.NEGATIVE_INFINITY,i=Number.POSITIVE_INFINITY,s=this.half_intervals(e);s.reduce((e,t)=>{let n="eq"===t.o,i="lt"===t.o,s="lte"===t.o,l="gt"===t.o,o="gte"===t.o,u=t.n;if(null==e.lower){let i={n:r,o:"gte"};e.lower=i,e.upper=t,r==u&&o||(l||o?e.gaps.push([i,{n:u,o:l?"lte":"lt",m:0}]):n&&e.gaps.push([i,{n:u,o:"lte",m:1}]))}else{let r="eq"===e.upper.o,a="lt"===e.upper.o,f="lte"===e.upper.o,h=(e.upper.o,e.upper.o,e.upper.n),p=e.upper;u===h?a&&(o||n)||(f||r)&&l||(r||a||f)&&e.gaps.push([{n:h,o:r||f?"gt":"gte",m:2,d:{u:p,h:t}},{n:u,o:n||o?"lt":"lte",m:3}]):h<u?i||s||(r||a||f)&&e.gaps.push([{n:h,o:r||f?"gt":"gte",m:4},{n:u,o:n||o?"lt":"lte",m:5}]):e.overs.push([{n:u,o:n||o?"gte":"gt",m:10},{n:h,o:r||f?"lte":"lt",m:11}]),e.upper=t}return e},n);let l=0<s.length&&s[s.length-1];return l&&i!==l.n&&"gt"!==l.o&&"gte"!==l.o&&n.gaps.push([{n:l.n,o:"eq"===l.o||"lte"===l.o?"gt":"gte",m:6},{n:i,o:"lte",m:7}]),n.complete=0===n.gaps.length,n.sound=0===n.overs.length,n}half_intervals(e){let t=[];for(let r of e)t.push([{n:r.meta.n0,o:r.meta.o0},{n:r.meta.n1,o:r.meta.o1}]);var n=["lt","lte","eq","gte","gt"];return t.map(e=>[isNaN(e[0].n)||null==e[0].n?null:e[0],isNaN(e[1].n)||null==e[1].n?null:e[1]].filter(e=>null!=e)).sort((e,t)=>{if(e[0].n<t[0].n)return-1;if(t[0].n<e[0].n)return 1;var r=n.indexOf(e[0].o),i=n.indexOf(t[0].o);if(r<i)return-1;if(i<r)return 1;if(e[1].n<t[1].n)return-1;if(t[1].n<e[1].n)return 1;var s=n.indexOf(e[1].o),l=n.indexOf(t[1].o);return s<l?-1:l<s?1:0}).reduce((e,t)=>e.concat(...t),[])}}f.IntervalMatcher=c,t=new WeakMap,n=new WeakMap,r=new WeakMap,i=new WeakMap,s=new WeakMap,l=new WeakMap,o=new WeakMap,u=new WeakMap,a=new WeakMap,c.normop=e=>null==e?null:((e.match(/([<>\(\)\[\]])/)||[])[1]||"")+((e.match(/(=)/)||[])[1]||"");var d={};function g(t){var n={},r={};let i=[];return(t=t||{}).gex&&i.push(new f.GexMatcher),t.interval&&i.push(new f.IntervalMatcher),n.top=function(){return r},n.add=function(e,s){e={...e};var l="function"==typeof t?t.call(n,e,s):null,o=Object.keys(e).filter(t=>null!=e[t]).sort();o.forEach((function(t){e[t]=String(e[t])}));for(var u,a=r,f=0;f<o.length;f++){var h=o[f],p=e[h];let t=i.reduce((e,t)=>e||t.make(h,p),void 0);if((u=a.v)&&h==a.k)if(t){var c=(g=a.g=a.g||{})[h]=g[h]||[];a=(t=c.find(e=>e.same(t))||(c.push(t),t)).keymap||(t.keymap={})}else a=u[p]||(u[p]={});else if(a.k)if(h<a.k){var d=a.s;g=a.g,a.s={k:a.k,v:a.v},d&&(a.s.s=d),g&&(a.s.g=g),a.g&&(a.g={}),a.k=h,a.v={},t?(c=(g=a.g=a.g||{})[h]=g[h]||[],a=(t=c.find(e=>e.same(t))||(c.push(t),t)).keymap||(t.keymap={})):a=a.v[p]={}}else a=a.s||(a.s={}),f--;else if(a.k=h,a.v={},t){var g;c=(g=a.g=a.g||{})[h]=g[h]||[];a=(t=c.find(e=>e.same(t))||(c.push(t),t)).keymap||(t.keymap={})}else a=a.v[p]={}}return void 0!==s&&a&&(a.d=s,l&&(a.f="function"==typeof l?l:l.find,a.r="function"==typeof l.remove?l.remove:void 0)),n},n.findexact=function(e){return n.find(e,!0)},n.find=function(e,t,i){if(null==e)return null;var s=r,l=void 0===r.d?null:r.d,o=r.f,u=null,a=[],f={},h=Object.keys(e).length,p=[];void 0!==r.d&&p.push(r.d);do{if(u=s.k,s.v){var c=e[u],d=s.v[c];if(!d&&s.g&&s.g[u])for(var g=s.g[u],m=0;m<g.length;m++)if(g[m].match(c)){d=g[m].keymap;break}d?(f[u]=!0,s.s&&a.push(s.s),l=void 0===d.d?t?null:l:d.d,i&&void 0!==d.d&&p.push(d.d),o=d.f,s=d):s=s.s}else s=null;null==s&&0<a.length&&(null==l||i&&!t)&&(s=a.pop())}while(s);return t?Object.keys(f).length!==h&&(l=null):null==l&&void 0!==r.d&&(l=r.d),o&&(l=o.call(n,e,l)),i?p:l},n.remove=function(e){var t,n=r,i=null,s=[];do{if(t=n.k,n.v||n.g){if(n.v){var l=n.v[e[t]];l&&s.push({km:n,v:e[t]})}if(null==l&&n.g){let r=n.g[t]||[];for(let i=0;i<r.length;i++)if(r[i].fix===e[t]){s.push({km:n,v:e[t],mv:r[i]}),l=r[i].keymap;break}}l?(i=l.d,n=l):n=n.s}else n=null}while(n);if(void 0!==i){var o=s[s.length-1];if(o&&o.km&&o.km.v){var u=o.km.v[o.v]||o.mv&&o.mv.keymap;!u||u.r&&!u.r(e,u.d)||delete u.d}}},n.list=function(t,n){t=t||{};var i=[];return r.d&&i.push({match:{},data:r.d,find:r.f}),function r(i,s,l,o){if(i.v){var u,a=i.k,f=e.Gex(t?null==t[a]?n?null:"*":t[a]:"*"),h={...s},p={...l};for(var c in i.v)if(c===t[a]||!n&&null==t[a]||f.on(c)){var d={...h};d[a]=c;var g={...p};delete g[a],u=i.v[c],0===Object.keys(g).length&&u&&u.d&&o.push({match:d,data:u.d,find:u.f}),u&&null!=u.v&&r(u,{...d},{...g},o)}(u=i.s)&&r(u,{...h},{...p},o)}}(r,{},{...t},i),i},n.toString=function(e,t){var n=!0===e||!!t,i="function"==typeof e?e:function(e){return"function"==typeof e?"<"+e.name+">":"<"+e+">"};function s(e,t){for(var n=0;n<t;n++)e.push(" ")}var l=[],o=[];return function e(t,n,r,o){var u;if(void 0!==t.d&&(n.push(" "+i(t.d)),l.push(o.join(", ")+" -> "+i(t.d))),t.k&&(n.push("\n"),s(n,r),n.push(t.k+":")),(t.v||t.s||t.g)&&r++,t.v)for(var a=Object.keys(t.v).sort(),f=0;f<a.length;f++){var h=a[f];n.push("\n"),s(n,r),n.push(h+" ->"),(u=o.slice()).push(t.k+"="+h),e(t.v[h],n,r+1,u)}if(t.g)for(a=Object.keys(t.g).sort(),f=0;f<a.length;f++)for(var p=t.g[a[f]],c=0;c<p.length;c++){var d=p[c];n.push("\n"),s(n,r),n.push(d.fix+" ~>"),(u=o.slice()).push(t.k+"~"+d.fix),e(d.keymap,n,r+1,u)}t.s&&(n.push("\n"),s(n,r),n.push("|"),u=o.slice(),e(t.s,n,r+1,u))}(r,o,0,[]),n?o.join(""):l.join("\n")},n.inspect=n.toString,n.toJSON=function(e){return JSON.stringify(r,(function(e,t){return"function"==typeof t?"[Function]":t}),e)},n}return Object.defineProperty(d,"__esModule",{value:!0}),d=function(e){return new g(e)}}));
{
"name": "patrun",
"version": "6.0.1",
"version": "7.0.0",
"main": "dist/patrun.js",

@@ -25,3 +25,3 @@ "browser": "dist/patrun.min.js",

"test-web": "browserify -o test-web/test-web.js -e test/patrun.test.js -s Patrun -im -i assert -i @hapi/lab && open test-web/index.html",
"coveralls": "lab -s -P test -r lcov -I URL,URLSearchParams | coveralls",
"coveralls": "lab -s -P test -r lcov | coveralls",
"prettier": "prettier --write --no-semi --single-quote *.ts test/*.js",

@@ -41,5 +41,2 @@ "build": "tsc -d && cp dist/patrun.js dist/patrun.min.js && browserify -o dist/patrun.min.js -e dist/patrun.js -s Patrun -im -i assert -p tinyify",

],
"engines": {
"node": ">=8"
},
"contributors": [

@@ -49,16 +46,18 @@ "Adrien Becchis (https://github.com/AdrieanKhisbe)"

"dependencies": {
"gex": "^2.1.0"
"gex": "^3.0.1"
},
"devDependencies": {
"@hapi/code": "^8.0.2",
"@hapi/lab": "^23.0.0",
"@hapi/lab": "^24.1.0",
"benchmark": "^2.1.4",
"coveralls": "^3.1.0",
"hapi-lab-shim": "0.0.2",
"prettier": "^2.1.1",
"jsonic": "^1.0.1",
"lab-transform-typescript": "^3.0.1",
"prettier": "^2.1.2",
"serve": "^11.3.2",
"browserify": "^17.0.0",
"tinyify": "^3.0.0",
"lab-transform-typescript": "^3.0.1",
"typescript": "^4.0.2"
"typescript": "^4.0.5"
}
}

@@ -1,7 +0,16 @@

/* Copyright (c) 2013-2020 Richard Rodger, MIT License, https://github.com/rjrodger/patrun */
/* Copyright (c) 2013-2020 Richard Rodger, MIT License */
// TODO: matchers should accept string[] of key names - only operate on these keys
// TODO: expose walk as method for general purpose
const gex = require('gex')
import { Gex } from 'gex'
import {
Matcher,
MatchValue,
GexMatcher,
IntervalMatcher,
} from './lib/matchers'
module.exports = function (custom: any) {

@@ -17,2 +26,12 @@ return new (Patrun as any)(custom)

let matchers: Matcher[] = []
if (custom.gex) {
matchers.push(new GexMatcher())
}
if (custom.interval) {
matchers.push(new IntervalMatcher())
}
// Provide internal search order structure

@@ -30,63 +49,105 @@ self.top = function () {

var keys = Object.keys(pat)
var plains: any[] = []
var gexers: any[] = []
.filter((key) => null != pat[key])
.sort()
keys.forEach(function (key) {
var val = pat[key]
if (null == val) return
val = String(val)
pat[key] = val
;(custom.gex && val.match(/[*?]/) ? gexers : plains).push(key)
pat[key] = String(pat[key])
})
plains = plains.sort()
gexers = gexers.sort()
keys = plains.concat(gexers)
var keymap: any = top
var valmap: any
// Partial matches return next wider match - see partial-match test
// Partial matches return next wider match - see partial-match test.
// Traverse the key path (keys are ordered), insert preserves order.
for (var i = 0; i < keys.length; i++) {
// console.log('L', i, keys.length)
for (var i = 0; i < keys.length; i++) {
var key = keys[i]
var val = pat[key]
var fix = pat[key]
var gexer = custom.gex && val.match(/[*?]/) ? gex(val) : null
if (gexer) gexer.val$ = val
let mv: MatchValue | undefined = matchers.reduce(
(m, t) => m || t.make(key, fix),
undefined
)
var sort_prefix = (gexer ? '1' : '0') + '~'
var sort_key = sort_prefix + key
// if (mv) mv.val$ = fix
valmap = keymap.v
if (valmap && sort_key == keymap.sk) {
add_gexer(keymap, key, gexer)
keymap = valmap[val] || (valmap[val] = {})
} else if (!keymap.k) {
add_gexer(keymap, key, gexer)
// console.log('S0',key,fix,keymap,valmap)
// An existing key
if (valmap && key == keymap.k) {
// console.log('S1-a')
// add_mv(keymap, key, mv)
if (mv) {
var g = (keymap.g = keymap.g || {})
var ga = (g[key] = g[key] || [])
mv = (ga.find((gmv: MatchValue) => gmv.same(mv)) ||
(ga.push(mv), mv)) as MatchValue
keymap = mv.keymap || (mv.keymap = {})
} else {
keymap = valmap[fix] || (valmap[fix] = {})
}
}
// End of key path reached, so this is a new key, ordered last
else if (!keymap.k) {
keymap.k = key
keymap.sk = sort_key
keymap.v = {}
keymap = keymap.v[val] = {}
} else if (sort_key < keymap.sk) {
var s = keymap.s,
g = keymap.g
keymap.s = { k: keymap.k, sk: keymap.sk, v: keymap.v }
if (s) keymap.s.s = s
if (g) keymap.s.g = g
if (keymap.g) keymap.g = {}
add_gexer(keymap, key, gexer)
if (mv) {
var g = (keymap.g = keymap.g || {})
var ga = (g[key] = g[key] || [])
mv = (ga.find((gmv: MatchValue) => gmv.same(mv)) ||
(ga.push(mv), mv)) as MatchValue
keymap = mv.keymap || (mv.keymap = {})
} else {
keymap = keymap.v[fix] = {}
}
}
// Insert key orders before next existing key in path, so insert
else if (key < keymap.k) {
// console.log('S1-c', key, keymap.k)
var s = keymap.s
var g = keymap.g
keymap.s = {
k: keymap.k,
// sk: keymap.sk,
v: keymap.v,
}
if (s) {
keymap.s.s = s
}
if (g) {
keymap.s.g = g
}
if (keymap.g) {
keymap.g = {}
}
keymap.k = key
keymap.sk = sort_key
keymap.v = {}
keymap = keymap.v[val] = {}
} else {
valmap = keymap.v
if (mv) {
var g = (keymap.g = keymap.g || {})
var ga = (g[key] = g[key] || [])
mv = (ga.find((gmv: MatchValue) => gmv.same(mv)) ||
(ga.push(mv), mv)) as MatchValue
keymap = mv.keymap || (mv.keymap = {})
} else {
keymap = keymap.v[fix] = {}
}
}
// Follow star path
else {
keymap = keymap.s || (keymap.s = {})
// NOTE: current key is still not inserted
i--

@@ -109,13 +170,2 @@ }

function add_gexer(keymap: any, key: any, gexer: any) {
if (!gexer) return
var g = (keymap.g = keymap.g || {})
var ga = (g[key] = g[key] || [])
ga.push(gexer)
ga.sort(function (a: any, b: any) {
return a.val$ < b.val$
})
}
self.findexact = function (pat: any) {

@@ -152,7 +202,7 @@ return self.find(pat, true)

if (!nextkeymap && custom.gex && keymap.g && keymap.g[key]) {
if (!nextkeymap && keymap.g && keymap.g[key]) {
var ga = keymap.g[key]
for (var gi = 0; gi < ga.length; gi++) {
if (null != ga[gi].on(val)) {
nextkeymap = keymap.v[ga[gi].val$]
if (ga[gi].match(val)) {
nextkeymap = ga[gi].keymap
break

@@ -224,8 +274,25 @@ }

if (keymap.v) {
// TODO: equivalence match as per find
var nextkeymap = keymap.v[pat[key]]
// console.log('keymap v g', keymap.v, keymap.g)
if (keymap.v || keymap.g) {
if (keymap.v) {
var nextkeymap = keymap.v[pat[key]]
if (nextkeymap) {
path.push({ km: keymap, v: pat[key] })
}
}
if (null == nextkeymap && keymap.g) {
let mvs: MatchValue[] = keymap.g[key] || []
for (let mvi = 0; mvi < mvs.length; mvi++) {
// TODO: should parse!
if (mvs[mvi].fix === pat[key]) {
path.push({ km: keymap, v: pat[key], mv: mvs[mvi] })
nextkeymap = mvs[mvi].keymap
break
}
}
}
if (nextkeymap) {
path.push({ km: keymap, v: pat[key] })
data = nextkeymap.d

@@ -244,4 +311,4 @@ keymap = nextkeymap

if (part && part.km && part.km.v) {
var point = part.km.v[part.v]
if (!point.r || point.r(pat, point.d)) {
var point = part.km.v[part.v] || (part.mv && part.mv.keymap)
if (point && (!point.r || point.r(pat, point.d))) {
delete point.d

@@ -260,3 +327,3 @@ }

var key = keymap.k
var gexval = gex(
var gexval = Gex(
pat ? (null == pat[key] ? (exact ? null : '*') : pat[key]) : '*'

@@ -352,2 +419,3 @@ )

}
if (n.k) {

@@ -358,15 +426,11 @@ o.push('\n')

}
if (n.v) {
if (n.v || n.s || n.g) {
d++
var pa = Object.keys(n.v)
var pal = pa.filter(function (x) {
return !x.match(/[*?]/)
})
var pas = pa.filter(function (x) {
return x.match(/[*?]/)
})
pal.sort()
pas.sort()
pa = pal.concat(pas)
}
if (n.v) {
// d++
var pa = Object.keys(n.v).sort()
for (var pi = 0; pi < pa.length; pi++) {

@@ -383,12 +447,33 @@ var p = pa[pi]

}
}
if (n.s) {
o.push('\n')
indent(o, d)
o.push('|')
if (n.g) {
var pa = Object.keys(n.g).sort()
vsc = vs.slice()
walk(n.s, o, d + 1, vsc)
for (var pi = 0; pi < pa.length; pi++) {
var mvs = n.g[pa[pi]]
for (var mvi = 0; mvi < mvs.length; mvi++) {
var mv = mvs[mvi]
o.push('\n')
indent(o, d)
o.push(mv.fix + ' ~>')
vsc = vs.slice()
vsc.push(n.k + '~' + mv.fix)
walk(mv.keymap, o, d + 1, vsc)
}
}
}
if (n.s) {
o.push('\n')
indent(o, d)
o.push('|')
vsc = vs.slice()
walk(n.s, o, d + 1, vsc)
}
}

@@ -395,0 +480,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