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 0.4.3 to 0.4.4

9

package.json

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

"main": "patrun.js",
"version": "0.4.3",
"version": "0.4.4",
"scripts": {

@@ -32,5 +32,8 @@ "test": "./test.sh",

"dependencies": {
"lodash": "~2.4.1",
"gex": "~0.2.0"
"lodash": "3.10.0",
"gex": "0.2.1"
},
"devDependencies": {
"serve": "1.4.0"
}
}
/* Copyright (c) 2013-2015 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("lodash")}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){if(null==n)return null;var r=o,u=o.d||null,s=o.f,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 o.d&&i.push({match:{},data:o.d,find:o.f}),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);
(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("lodash")}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,d=t.keys(n).sort(),l=o,f=0;f<d.length;f++){var v=d[f],a=n[v];if(null!==a&&void 0!==a)if(s=l.v,s&&v==l.k)l=s[a]||(s[a]={});else if(l.k)if(v<l.k){var c=l.v,p=l.s;l.v={},l.s={k:l.k,v:c,s:p},l.k=v,l=l.v[a]={}}else s=l.v,l=l.s||(l.s={}),f--;else l.k=v,l.v={},l=l.v[a]={}}return void 0!==e&&l&&(l.d=e,u&&(l.f=t.isFunction(u)?u:u.find,l.r=t.isFunction(u.remove)?u.remove:void 0)),i},i.findexact=function(n){return i.find(n,!0)},i.find=function(n,e){if(null==n)return null;var r=o,u=void 0===o.d?null:o.d,s=o.f,d=null,l=[],f={},v=t.keys(n).length;do{if(d=r.k,r.v){var a=r.v[n[d]];a?(f[d]=!0,r.s&&l.push(r.s),u=void 0===a.d?null:a.d,s=a.f,r=a):r=r.s}else r=null;null==r&&null==u&&0<l.length&&(r=l.pop())}while(r);return 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 d=s.km.v[s.v];(!d.r||d.r(n,d.d))&&delete d.d}}},i.list=function(n,e){function r(i,o,s,d){if(i.v){var l,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 g=t.extend({},c);delete g[f],l=i.v[p],0===t.keys(g).length&&l&&l.d&&d.push({match:h,data:l.d,find:l.f}),l&&l.v&&r(l,t.extend({},h),t.extend({},g),d)}l=i.s,l&&r(l,t.extend({},a),t.extend({},c),d)}}var i=[];return o.d&&i.push({match:{},data:o.d,find:o.f}),r(o,{},t.extend({},n),i),i},i.toString=function(){function n(n,e){for(var r=0;e>r;r++)n.push(" ")}function e(r,o,s,d){var l;if(void 0!==r.d&&(n(o,s),o.push(u(r.d)),i.push(d.join(", ")+" -> "+u(r.d))),r.k&&(o.push("\n"),n(o,s),o.push(r.k+":")),r.v){s++;for(var f in r.v)o.push("\n"),n(o,s),o.push(f+" ->"),l=t.clone(d),l.push(r.k+"="+f),e(r.v[f],o,s+1,l);r.s&&(o.push("\n"),n(o,s),o.push("* ->"),l=t.clone(d),e(r.s,o,s+1,l))}}var r=t.isBoolean(arguments[0])?arguments[0]:!!arguments[1],u=t.isFunction(arguments[0])?arguments[0]:function(n){return t.isFunction(n)?"<"+n.name+">":"<"+n+">"},i=[],s=[];return e(o,s,0,[]),r?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

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

var keymap = top
var data = top.d || null
var data = void 0 === top.d ? null : top.d
var finalfind = top.f

@@ -132,3 +132,3 @@ var key = null

data = null == nextkeymap.d ? null : nextkeymap.d
data = void 0 === nextkeymap.d ? null : nextkeymap.d
finalfind = nextkeymap.f

@@ -145,3 +145,3 @@ keymap = nextkeymap

if( null == keymap && null === data && 0 < stars.length ) {
if( null == keymap && null == data && 0 < stars.length ) {
keymap = stars.pop()

@@ -152,8 +152,2 @@ }

// special case for default with no properties
if( null === data && 0 === patlen && void 0 !== top.d ) {
data = top.d
finalfind = top.f
}
if( exact && _.keys(foundkeys).length != patlen ) {

@@ -284,9 +278,10 @@ data = null

self.toString = function(dstr,tree) {
dstr = _.isFunction(dstr) ? dstr : function(d){
return _.isFunction(d) ? '<'+d.name+'>' : '<'+d+'>'}
self.toString = function() {
var tree = _.isBoolean( arguments[0] ) ? arguments[0] : !!arguments[1]
tree = _.isBoolean( arguments[0] ) ? arguments[0] : tree
tree = void 0 === tree ? false : tree
var dstr = _.isFunction( arguments[0] ) ? arguments[0] : function(d) {
return _.isFunction(d) ? '<'+d.name+'>' : '<'+d+'>'
}
function indent(o,d) {

@@ -293,0 +288,0 @@ for(var i = 0; i < d; i++ ) {

# patrun
### A fast pattern matcher on JavaScript object properties.
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/rjrodger/patrun?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
### A fast pattern matcher on JavaScript object properties.
Need to pick out an object based on a subset of its properties? Say you've got:

@@ -36,5 +38,5 @@

Current Version: 0.4.2
Current Version: 0.4.4
Tested on: Node.js 0.10.31, Chrome 38, Firefox 33, Safari 7, Opera 25
Tested on: node 0.10, 0.11, 0.12, iojs, Chrome 43, Safari 7, Firefox 38

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

// prints A
console.log( pm.find({a:1}) )
console.log( pm.find({a:1}) )
// prints null
console.log( pm.find({a:2}) )
console.log( pm.find({a:2}) )
// prints A, b:1 is ignored, it was never registered
console.log( pm.find({a:1,b:1}) )
console.log( pm.find({a:1,b:1}) )
// prints B, c:3 is ignored, it was never registered
console.log( pm.find({b:2,c:3}) )
console.log( pm.find({b:2,c:3}) )
```

@@ -78,3 +80,3 @@

```sh
npm install jsonic
npm install patrun
```

@@ -134,30 +136,30 @@

.add({ country:'US', state:'AL' }, I(0.04) )
.add({ country:'US', state:'AL', city:'Montgomery' }, I(0.10) )
.add({ country:'US', state:'AL' }, I(0.04) )
.add({ country:'US', state:'AL', city:'Montgomery' }, I(0.10) )
.add({ country:'US', state:'NY' }, I(0.07) )
.add({ country:'US', state:'NY' }, I(0.07) )
.add({ country:'US', state:'NY', type:'reduced' }, function under110(net){
return net < 110 ? 0.0 : salestax.find( {country:'US', state:'NY'} )
})
})
console.log('Default rate: ' +
console.log('Default rate: ' +
salestax.find({})(99) )
console.log('Standard rate in Ireland on E99: ' +
console.log('Standard rate in Ireland on E99: ' +
salestax.find({country:'IE'})(99) )
console.log('Food rate in Ireland on E99: ' +
console.log('Food rate in Ireland on E99: ' +
salestax.find({country:'IE',type:'food'})(99) )
console.log('Reduced rate in Germany on E99: ' +
console.log('Reduced rate in Germany on E99: ' +
salestax.find({country:'IE',type:'reduced'})(99) )
console.log('Standard rate in Alabama on $99: ' +
console.log('Standard rate in Alabama on $99: ' +
salestax.find({country:'US',state:'AL'})(99) )
console.log('Standard rate in Montgomery, Alabama on $99: ' +
console.log('Standard rate in Montgomery, Alabama on $99: ' +
salestax.find({country:'US',state:'AL',city:'Montgomery'})(99) )
console.log('Reduced rate in New York for clothes on $99: ' +
console.log('Reduced rate in New York for clothes on $99: ' +
salestax.find({country:'US',state:'NY',type:'reduced'})(99) )

@@ -208,3 +210,19 @@

OK, some examples might help! Let's say you have patterns:
* `a:0` -> `'A'`
* `b:1` -> `'B'`
* `c:2` -> `'C'`
* `a:0,b:1` -> `'AB'`
Then you'll get the following results
* `a:0` -> `'A'` as exact match
* `b:1` -> `'B'` as exact match
* `c:2` -> `'C'` as exact match
* `a:0,b:1` -> `'AB'` as more specific than `a:0`
* `a:0,c:2` -> `'A'` as `a` comes before `c`
* `b:1,c:2` -> `'B'` as `b` comes before `c`
# Customization

@@ -222,3 +240,3 @@

alwaysAddFoo.add( {a:1}, "bar" )
alwaysAddFoo.find( {a:1} ) // nothing!

@@ -241,3 +259,3 @@ alwaysAddFoo.find( {a:1,foo:true} ) // == "bar"

upperify.add( {a:1}, "bar" )
upperify.find( {a:1} ) // BAR

@@ -271,6 +289,6 @@ ```

many.remove( {a:1} )
many.remove( {a:1} )
many.find( {a:1} ) // [ 'A' ]
many.remove( {b:1} )
many.remove( {b:1} )
many.find( {b:1} ) // null

@@ -319,3 +337,5 @@ ```

// finds nothing: []
// finds:
// [ { match: { a: '1', b: '1' }, data: 'B1' },
// { match: { a: '1', b: '2' }, data: 'B2' } ]
console.log( pm.list({a:1}) )

@@ -327,2 +347,5 @@

console.log( pm.list({a:1,b:'*'}) )
// finds nothing: []
console.log( pm.list({a:1, c:1}) )
```

@@ -329,0 +352,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