New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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 0.2.0 to 0.3.0

2

package.json

@@ -18,3 +18,3 @@ {

"main": "patrun.js",
"version": "0.2.0",
"version": "0.3.0",
"scripts": {

@@ -21,0 +21,0 @@ "test": "./node_modules/.bin/jasmine-node ./test",

/* Copyright (c) 2013 Richard Rodger, MIT License, https://github.com/rjrodger/patrun */
(function(){"use strict";var n=this,e=n.patrun,r="undefined"!=typeof require,t=n._,u=n.gex;if("undefined"==typeof t){if(!r)throw new Error("patrun requires underscore, see http://underscorejs.org");t=require("underscore")}if("undefined"==typeof u){if(!r)throw new Error("patrun requires gex, see https://github.com/rjrodger/gex");u=require("gex")}var i=n.patrun=function(r){var i={},o={};return i.noConflict=function(){return n.patrun=e,i},i.add=function(n,e){n=t.clone(n);var u;r&&(u=r.call(i,n,e));for(var s,l=t.keys(n).sort(),d=o,f=0;f<l.length;f++){var v=l[f],a=n[v];if(null!==a&&void 0!==a)if(s=d.v,s&&v==d.k)d=s[a]||(s[a]={});else if(d.k)if(v<d.k){var c=d.v,p=d.s;d.v={},d.s={k:d.k,v:c,s:p},d.k=v,d=d.v[a]={}}else s=d.v,d=d.s||(d.s={}),f--;else d.k=v,d.v={},d=d.v[a]={}}return void 0!==e&&d&&(d.d=e,u&&(d.f=t.isFunction(u)?u:u.find,d.r=t.isFunction(u.remove)?u.remove:void 0)),i},i.findexact=function(n){return i.find(n,!0)},i.find=function(n,e){var r=o,u=null,s=null,l=null,d=[],f={},v=t.keys(n).length;do{if(l=r.k,r.v){var a=r.v[n[l]];a?(f[l]=!0,r.s&&d.push(r.s),u=null==a.d?null:a.d,s=a.f,r=a):r=r.s}else r=null;null==r&&null===u&&0<d.length&&(r=d.pop())}while(r);return null===u&&0===v&&void 0!==o.d&&(u=o.d,s=o.f),e&&t.keys(f).length!=v&&(u=null),s&&(u=s.call(i,n,u)),u},i.remove=function(n){var e,r=o,t=null,u=[];do if(e=r.k,r.v){var i=r.v[n[e]];i?(u.push({km:r,v:n[e]}),t=i.d,r=i):r=r.s}else r=null;while(r);if(void 0!==t){var s=u[u.length-1];if(s&&s.km&&s.km.v){var l=s.km.v[s.v];(!l.r||l.r(n,l.d))&&delete l.d}}},i.list=function(n){function e(r,i,o,s){if(r.v){var l,d,f,v=r.k,a=u(n?n[v]:"*");for(var c in r.v)if(d=t.extend({},i),f=t.extend({},o),a.on(c)){var p=t.clone(d);p[v]=c,delete f[v],l=r.v[c],0===t.keys(f).length&&l&&l.d?s.push({match:p,data:l.d,find:l.f}):l&&l.v&&e(l,t.extend({},p),t.extend({},f),s)}l=r.s,l&&e(l,t.extend({},d),t.extend({},f),s)}}var r=[];return e(o,{},t.extend({},n),r),r},i.toString=function(n,e){function r(n,e){for(var r=0;e>r;r++)n.push(" ")}function u(e,o,s,l){var d;if(void 0!==e.d&&(r(o,s),o.push(n(e.d)),i.push(l.join(", ")+" -> "+n(e.d))),e.k&&(o.push("\n"),r(o,s),o.push(e.k+":")),e.v){s++;for(var f in e.v)o.push("\n"),r(o,s),o.push(f+" ->"),d=t.clone(l),d.push(e.k+"="+f),u(e.v[f],o,s+1,d);e.s&&(o.push("\n"),r(o,s),o.push("* ->"),d=t.clone(l),u(e.s,o,s+1,d))}}n=t.isFunction(n)?n:function(n){return t.isFunction(n)?"<"+n.name+">":"<"+n+">"},e=t.isBoolean(arguments[0])?arguments[0]:e,e=void 0===e?!1:e;var i=[],s=[];return u(o,s,0,[]),e?s.join(""):i.join("\n")},i.inspect=i.toString,i.toJSON=function(n){return JSON.stringify(o,function(n,e){return t.isFunction(e)?"[Function]":e},n)},i};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=i),exports.patrun=i):n.patrun=i}).call(this);
(function(){"use strict";var n=this,e=n.patrun,r="undefined"!=typeof require,t=n._,u=n.gex;if("undefined"==typeof t){if(!r)throw new Error("patrun requires underscore, see http://underscorejs.org");t=require("underscore")}if("undefined"==typeof u){if(!r)throw new Error("patrun requires gex, see https://github.com/rjrodger/gex");u=require("gex")}var i=n.patrun=function(r){var i={},o={};return i.noConflict=function(){return n.patrun=e,i},i.add=function(n,e){n=t.clone(n);var u;r&&(u=r.call(i,n,e));for(var s,l=t.keys(n).sort(),d=o,f=0;f<l.length;f++){var v=l[f],a=n[v];if(null!==a&&void 0!==a)if(s=d.v,s&&v==d.k)d=s[a]||(s[a]={});else if(d.k)if(v<d.k){var c=d.v,p=d.s;d.v={},d.s={k:d.k,v:c,s:p},d.k=v,d=d.v[a]={}}else s=d.v,d=d.s||(d.s={}),f--;else d.k=v,d.v={},d=d.v[a]={}}return void 0!==e&&d&&(d.d=e,u&&(d.f=t.isFunction(u)?u:u.find,d.r=t.isFunction(u.remove)?u.remove:void 0)),i},i.findexact=function(n){return i.find(n,!0)},i.find=function(n,e){var r=o,u=null,s=null,l=null,d=[],f={},v=t.keys(n).length;do{if(l=r.k,r.v){var a=r.v[n[l]];a?(f[l]=!0,r.s&&d.push(r.s),u=null==a.d?null:a.d,s=a.f,r=a):r=r.s}else r=null;null==r&&null===u&&0<d.length&&(r=d.pop())}while(r);return null===u&&0===v&&void 0!==o.d&&(u=o.d,s=o.f),e&&t.keys(f).length!=v&&(u=null),s&&(u=s.call(i,n,u)),u},i.remove=function(n){var e,r=o,t=null,u=[];do if(e=r.k,r.v){var i=r.v[n[e]];i?(u.push({km:r,v:n[e]}),t=i.d,r=i):r=r.s}else r=null;while(r);if(void 0!==t){var s=u[u.length-1];if(s&&s.km&&s.km.v){var l=s.km.v[s.v];(!l.r||l.r(n,l.d))&&delete l.d}}},i.list=function(n,e){function r(i,o,s,l){if(i.v){var d,f=i.k,v=u(n?null==n[f]?e?null:"*":n[f]:"*"),a=t.extend({},o),c=t.extend({},s);for(var p in i.v)if(v.on(p)){var h=t.clone(a);h[f]=p;var k=t.extend({},c);delete k[f],d=i.v[p],0===t.keys(k).length&&d&&d.d&&l.push({match:h,data:d.d,find:d.f}),d&&d.v&&r(d,t.extend({},h),t.extend({},k),l)}d=i.s,d&&r(d,t.extend({},a),t.extend({},c),l)}}var i=[];return r(o,{},t.extend({},n),i),i},i.toString=function(n,e){function r(n,e){for(var r=0;e>r;r++)n.push(" ")}function u(e,o,s,l){var d;if(void 0!==e.d&&(r(o,s),o.push(n(e.d)),i.push(l.join(", ")+" -> "+n(e.d))),e.k&&(o.push("\n"),r(o,s),o.push(e.k+":")),e.v){s++;for(var f in e.v)o.push("\n"),r(o,s),o.push(f+" ->"),d=t.clone(l),d.push(e.k+"="+f),u(e.v[f],o,s+1,d);e.s&&(o.push("\n"),r(o,s),o.push("* ->"),d=t.clone(l),u(e.s,o,s+1,d))}}n=t.isFunction(n)?n:function(n){return t.isFunction(n)?"<"+n.name+">":"<"+n+">"},e=t.isBoolean(arguments[0])?arguments[0]:e,e=void 0===e?!1:e;var i=[],s=[];return u(o,s,0,[]),e?s.join(""):i.join("\n")},i.inspect=i.toString,i.toJSON=function(n){return JSON.stringify(o,function(n,e){return t.isFunction(e)?"[Function]":e},n)},i};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=i),exports.patrun=i):n.patrun=i}).call(this);
//# sourceMappingURL=patrun-min.map

@@ -205,4 +205,4 @@ /* Copyright (c) 2013 Richard Rodger, MIT License, https://github.com/rjrodger/patrun */

// values can be veratim, glob, or array of globs
self.list = function( pat ) {
// values can be verbatim, glob, or array of globs
self.list = function( pat, exact ) {
function descend(keymap,match,missing,acc) {

@@ -212,21 +212,38 @@

var key = keymap.k
var gexval = gex( pat ? pat[key] : '*' )
var nextkeymap, itermatch, itermissing
var gexval = gex( pat ?
(null==pat[key] ?
( exact ? null : '*' )
: pat[key])
: '*' )
var itermatch = _.extend({},match)
var itermissing = _.extend({},missing)
var nextkeymap
for( var val in keymap.v ) {
itermatch = _.extend({},match)
itermissing = _.extend({},missing)
if( gexval.on(val) ) {
var valitermatch = _.clone(itermatch)
valitermatch[key]=val
delete itermissing[key]
var valitermissing = _.extend({},itermissing)
delete valitermissing[key]
nextkeymap = keymap.v[ val ]
if( 0 === _.keys(itermissing).length && nextkeymap && nextkeymap.d ) {
acc.push({match:valitermatch,data:nextkeymap.d,find:nextkeymap.f})
if( 0 === _.keys(valitermissing).length &&
nextkeymap &&
nextkeymap.d )
{
acc.push({
match:valitermatch,
data:nextkeymap.d,
find:nextkeymap.f
})
}
else if( nextkeymap && nextkeymap.v ) {
descend(nextkeymap, _.extend({},valitermatch), _.extend({},itermissing), acc)
if( nextkeymap && nextkeymap.v ) {
descend(
nextkeymap,
_.extend({},valitermatch),
_.extend({},valitermissing),
acc)
}

@@ -238,3 +255,7 @@ }

if( nextkeymap ) {
descend(nextkeymap, _.extend({},itermatch), _.extend({},itermissing), acc)
descend(
nextkeymap,
_.extend({},itermatch),
_.extend({},itermissing),
acc)
}

@@ -272,5 +293,2 @@ }

o.push(dstr(n.d))
//if( 0 === d ) {
// o.push('\n')
//}

@@ -289,7 +307,4 @@ str.push( vs.join(', ')+' -> '+dstr(n.d))

indent(o,d)
//o.push( (''===p?'*':p)+' ->')
o.push( p+' ->')
//console.log('DESC',''+p,JSON.stringify(n.v[p]),JSON.stringify(n.v))
vsc = _.clone(vs)

@@ -307,4 +322,2 @@ vsc.push(n.k+'='+p)

vsc = _.clone(vs)
//vsc.push(n.k+'=*')
walk(n.s,o,d+1,vsc)

@@ -311,0 +324,0 @@ }

@@ -5,3 +5,3 @@ # patrun

Need to pick out an object based on a subset of it's properties? Say you've got:
Need to pick out an object based on a subset of its properties? Say you've got:

@@ -37,5 +37,5 @@ ```JavaScript

Current Version: 0.2.0
Current Version: 0.3.0
Tested on: Node.js 0.10.26, Chrome 35, Firefox 29, Safari 5.1.10, Opera 12.16
Tested on: Node.js 0.10.31, Chrome 38, Firefox 33, Safari 7, Opera 25

@@ -227,3 +227,3 @@ [![Build Status](https://travis-ci.org/rjrodger/patrun.png?branch=master)](https://travis-ci.org/rjrodger/patrun)

Here's a example that modifies found data:
Here's an example that modifies found data:

@@ -274,3 +274,5 @@ ```JavaScript

Check out the [_custom-gex_ test case](https://github.com/rjrodger/patrun/blob/master/test/patrun.spec.js#L324) for some really funky pattern matching using * globs.
# API

@@ -288,11 +290,20 @@

## .find( {...pattern...} )
## .find( {...subject...}, exact )
Return the unique match for this pattern, or null if not found
Return the unique match for this subject, or null if not found. The
properties of the subject are matched against the patterns previously
added, and the most specifc pattern wins. Unknown properties in the
subject are ignored. You can optionally provide a second boolean
parameter, _exact_. If true, then all properties of the subject must
match.
## .list( {...pattern...} )
## .list( {...pattern-partial...}, exact )
Return the list of matches for this pattern. You can use wildcards for property values.
Omitted values are *not* equivalent to a wildcard of _"*"_, you must specify each property explicitly.
Return the list of registered patterns that contain this partial
pattern. You can use wildcards for property values. Omitted values
are *not* equivalent to a wildcard of _"*"_, you must specify each
property explicitly. You can optionally provide a second boolean
parameter, _exact_. If true, then only those patterns matching the
pattern-partial exactly are returned.

@@ -299,0 +310,0 @@ ```JavaScript

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