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.1.1 to 0.1.2

7

package.json

@@ -18,7 +18,7 @@ {

"main": "patrun.js",
"version": "0.1.1",
"version": "0.1.2",
"scripts": {
"test": "./node_modules/.bin/jasmine-node ./test",
"browser": "phantomjs test/run-jasmine.js test/jasmine.html",
"build": "uglifyjs patrun.js -c \"evaluate=false\" --comments \"/ Copyright .*/\" -m --source-map patrun-min.map -o patrun-min.js"
"build": "./node_modules/.bin/jshint patrun.js; uglifyjs patrun.js -c \"evaluate=false\" --comments \"/ Copyright .*/\" -m --source-map patrun-min.map -o patrun-min.js"
},

@@ -33,3 +33,4 @@ "license": "MIT",

"devDependencies": {
"jasmine-node": "~1.11.0"
"jasmine-node": "~1.11.0",
"jshint": "~2.1.11"
},

@@ -36,0 +37,0 @@ "dependencies": {

/* Copyright (c) 2013 Richard Rodger, MIT License, https://github.com/rjrodger/patrun */
"use strict";(function(){var e=this,n=e.patrun,r="undefined"!=typeof require,t=e._,u=e.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=e.patrun=function(){var r={},i={};return r.noConflict=function(){return e.previous_patrun=n,r},r.add=function(e,n){for(var u,o=t.keys(e).sort(),s=i,v=0;v<o.length;v++){var d=o[v],f=e[d];if(null!==f&&void 0!==f)if(u=s.v,u&&d==s.k)s=u[f]||(u[f]={});else if(s.k)if(d<s.k){var a=s.v,l=s.s;s.v={},s.s={k:s.k,v:a,s:l},s.k=d,s=s.v[f]={}}else u=s.v,s=s.s||(s.s={}),v--;else s.k=d,s.v={},s=s.v[f]={}}return void 0!==n&&s&&(s.d=n),r},r.find=function(e){var n,r=i,u=null;do if(n=r.k,r.v){var o=r.v[e[n]];o?(u=o.d,r=o):r=r.s}else r=null;while(r);return null===u&&0===t.keys(e).length&&void 0!==i.d&&(u=i.d),u},r.remove=function(e){var n,r=i,t=null,u=[];do if(n=r.k,r.v){var o=r.v[e[n]];o?(u.push({km:r,v:e[n]}),t=o.d,r=o):r=r.s}else r=null;while(r);if(void 0!==t){var s=u[u.length-1];s&&s.km&&s.km.v&&delete s.km.v[s.v]}},r.findall=function(e){function n(r,i,o,s){if(r.v){var v=r.k,d=u(e[v]);for(var f in r.v){var a=t.extend({},i),l=t.extend({},o);if(d.on(f)){a[v]=f,delete l[v];var p=r.v[f];0==t.keys(l).length&&p&&p.d?s.push({match:a,data:p.d}):p&&p.v&&n(p,t.extend({},a),t.extend({},l),s)}}var p=r.s;p&&n(p,t.extend({},a),t.extend({},l),s)}}var r=[];return n(i,{},t.extend({},e),r),r},r.toString=function(e){function n(e,n){for(var r=0;n>r;r++)e.push(" ")}function r(t,u,i,o){if(void 0!==t.d&&(n(u,i),u.push(e(t.d))),t.k&&(u.push("\n"),n(u,i),u.push(t.k+":")),t.v){i++;for(var o in t.v)u.push("\n"),n(u,i),u.push(o+" ->"),r(t.v[o],u,i+1,o);t.s&&(u.push("\n"),n(u,i),u.push("* ->"),r(t.s,u,i+1,o))}}e=t.isFunction(e)?e:function(e){return t.isFunction(e)?"<"+e.name+">":"<"+e+">"};var u=[];return r(i,u,0,""),u.join("")},r.inspect=r.toString,r.toJSON=function(e){return JSON.stringify(i,function(e,n){return t.isFunction(n)?"[Function]":n},e)},r};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=i),exports.patrun=i):e.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(){var r={},i={};return r.noConflict=function(){return n.patrun=e,r},r.add=function(n,e){for(var u,o=t.keys(n).sort(),s=i,d=0;d<o.length;d++){var v=o[d],f=n[v];if(null!==f&&void 0!==f)if(u=s.v,u&&v==s.k)s=u[f]||(u[f]={});else if(s.k)if(v<s.k){var l=s.v,a=s.s;s.v={},s.s={k:s.k,v:l,s:a},s.k=v,s=s.v[f]={}}else u=s.v,s=s.s||(s.s={}),d--;else s.k=v,s.v={},s=s.v[f]={}}return void 0!==e&&s&&(s.d=e),r},r.find=function(n){var e,r=i,u=null,o=[];do{if(e=r.k,r.v){var s=r.v[n[e]];s?(r.s&&o.push(r.s),u=s.d||null,r=s):r=r.s}else r=null;null==r&&null===u&&0<o.length&&(r=o.pop())}while(r);return null===u&&0===t.keys(n).length&&void 0!==i.d&&(u=i.d),u},r.remove=function(n){var e,r=i,t=null,u=[];do if(e=r.k,r.v){var o=r.v[n[e]];o?(u.push({km:r,v:n[e]}),t=o.d,r=o):r=r.s}else r=null;while(r);if(void 0!==t){var s=u[u.length-1];s&&s.km&&s.km.v&&delete s.km.v[s.v].d}},r.findall=function(n){function e(r,i,o,s){if(r.v){var d,v,f,l=r.k,a=u(n[l]);for(var p in r.v)v=t.extend({},i),f=t.extend({},o),a.on(p)&&(v[l]=p,delete f[l],d=r.v[p],0===t.keys(f).length&&d&&d.d?s.push({match:v,data:d.d}):d&&d.v&&e(d,t.extend({},v),t.extend({},f),s));d=r.s,d&&e(d,t.extend({},v),t.extend({},f),s)}}var r=[];return e(i,{},t.extend({},n),r),r},r.toString=function(n,e){function r(n,e){for(var r=0;e>r;r++)n.push(" ")}function u(e,i,s,d){var v;if(void 0!==e.d&&(r(i,s),i.push(n(e.d)),o.push(d.join(", ")+" -> "+n(e.d))),e.k&&(i.push("\n"),r(i,s),i.push(e.k+":")),e.v){s++;for(var f in e.v)i.push("\n"),r(i,s),i.push(f+" ->"),v=t.clone(d),v.push(e.k+"="+f),u(e.v[f],i,s+1,v);e.s&&(i.push("\n"),r(i,s),i.push("* ->"),v=t.clone(d),u(e.s,i,s+1,v))}}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 o=[],s=[];return u(i,s,0,[]),e?s.join(""):o.join("\n")},r.inspect=r.toString,r.toJSON=function(n){return JSON.stringify(i,function(n,e){return t.isFunction(e)?"[Function]":e},n)},r};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=i),exports.patrun=i):n.patrun=i}).call(this);
//# sourceMappingURL=patrun-min.map
/* Copyright (c) 2013 Richard Rodger, MIT License, https://github.com/rjrodger/patrun */
"use strict";
(function() {
/* jshint node:true, asi:true, eqnull:true */
"use strict";
(function() {
var root = this

@@ -36,3 +37,3 @@ var previous_patrun = root.patrun

self.noConflict = function() {
root.previous_patrun = previous_patrun;
root.patrun = previous_patrun;
return self;

@@ -83,3 +84,3 @@ }

if( !(void 0 === data) && keymap ) {
if( void 0 !== data && keymap ) {
keymap.d = data

@@ -96,2 +97,3 @@ }

var key
var stars = []

@@ -104,7 +106,10 @@ do {

if( nextkeymap ) {
data = nextkeymap.d
if( keymap.s ) {
stars.push(keymap.s)
}
data = nextkeymap.d || null
keymap = nextkeymap
}
else {
//keymap = keymap.v['']
keymap = keymap.s

@@ -116,2 +121,6 @@ }

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

@@ -137,3 +146,3 @@ while( keymap )

key = keymap.k
if( keymap.v ) {

@@ -147,3 +156,2 @@ var nextkeymap = keymap.v[pat[key]]

else {
//keymap = keymap.v['']
keymap = keymap.s

@@ -158,7 +166,7 @@ }

if( !(void 0 === data) ) {
//console.dir(path)
if( void 0 !== data ) {
var part = path[path.length-1]
if( part && part.km && part.km.v ) {
delete part.km.v[part.v]
//delete part.km.v[part.v]
delete part.km.v[part.v].d
}

@@ -177,13 +185,7 @@ }

var gexval = gex( pat[key] )
var nextkeymap, itermatch, itermissing
//for( var val in keymap.v ) {
// eachval(val)
//}
//if( keymap.s) { eachval(keymap.s) }
//function eachval() {
for( var val in keymap.v ) {
var itermatch = _.extend({},match)
var itermissing = _.extend({},missing)
itermatch = _.extend({},match)
itermissing = _.extend({},missing)

@@ -194,5 +196,5 @@ if( gexval.on(val) ) {

var nextkeymap = keymap.v[ val ]
nextkeymap = keymap.v[ val ]
if( 0 == _.keys(itermissing).length && nextkeymap && nextkeymap.d ) {
if( 0 === _.keys(itermissing).length && nextkeymap && nextkeymap.d ) {
acc.push({match:itermatch,data:nextkeymap.d})

@@ -206,4 +208,3 @@ }

//var nextkeymap = keymap.v['']
var nextkeymap = keymap.s
nextkeymap = keymap.s
if( nextkeymap ) {

@@ -222,6 +223,9 @@ descend(nextkeymap, _.extend({},itermatch), _.extend({},itermissing), acc)

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

@@ -233,5 +237,8 @@ for(var i = 0; i < d; i++ ) {

function walk(n,o,d, p){
//console.log('walk',n.k,n.v,n.d,o.join('').replace(/\n/g,''),d,p)
if( !(void 0 === n.d) ) {
var str = []
function walk(n,o,d,vs){
var vsc
if( void 0 !== n.d ) {
indent(o,d)

@@ -242,2 +249,4 @@ o.push(dstr(n.d))

//}
str.push( vs.join(', ')+' -> '+dstr(n.d))
}

@@ -258,3 +267,7 @@ if( n.k ) {

//console.log('DESC',''+p,JSON.stringify(n.v[p]),JSON.stringify(n.v))
walk(n.v[p],o,d+1, p)
vsc = _.clone(vs)
vsc.push(n.k+'='+p)
walk(n.v[p],o,d+1,vsc)
}

@@ -266,3 +279,7 @@

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

@@ -273,4 +290,4 @@ }

var o = []
walk(top,o,0, '')
return o.join('')
walk(top,o,0,[])
return tree ? o.join('') : str.join('\n')
}

@@ -277,0 +294,0 @@

@@ -35,3 +35,3 @@ # patrun

Current Version: 0.1.0
Current Version: 0.1.2

@@ -175,3 +175,3 @@ Tested on: Node.js 0.10.19, Chrome 29

// print out decision tree, using a custom format function
// print out patterns, using a custom format function
console.log(salestax.toString( function(f){return f.name+':'+f.val} ))

@@ -181,27 +181,15 @@

// prints:
:0
city:
Montgomery ->
country:
US ->
state:
AL -> :0.1
* ->
country:
IE -> :0.25
type:
reduced -> :0.135
food -> :0.048
UK -> :0.2
type:
food -> :0
DE -> :0.19
type:
reduced -> :0.07
US -> :0
state:
AL -> :0.04
NY -> :0.07
type:
reduced -> under110:undefined
-> :0
city=Montgomery, country=US, state=AL -> :0.1
country=IE -> :0.25
country=IE, type=reduced -> :0.135
country=IE, type=food -> :0.048
country=UK -> :0.2
country=UK, type=food -> :0
country=DE -> :0.19
country=DE, type=reduced -> :0.07
country=US -> :0
country=US, state=AL -> :0.04
country=US, state=NY -> :0.07
country=US, state=NY, type=reduced -> under110:undefined
```

@@ -260,6 +248,8 @@

## .toString( func )
## .toString( func, tree )
Generate a string representation of the decision tree for debugging. Optionally provide a formatting function for objects.
* func: format function for data, optional
* tree: boolean flag, if true, print an indented tree rather than a list of patterns, default: false

@@ -266,0 +256,0 @@ ## .toJSON( indent )

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