From d39532b6b20030db8e3f985bdfd6df0e2f25cd39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20D=C3=BCrrwald?= Date: Mon, 14 Mar 2016 10:46:34 +0100 Subject: [PATCH] Added bower.json and uglification --- Gulpfile.js | 10 +++++ bower.json | 27 ++++++++++++ lib/jsonpath-min.js | 1 + package.json | 101 +++++++++++++++++++++++--------------------- 4 files changed, 92 insertions(+), 47 deletions(-) create mode 100644 Gulpfile.js create mode 100644 bower.json create mode 100644 lib/jsonpath-min.js diff --git a/Gulpfile.js b/Gulpfile.js new file mode 100644 index 0000000..4d1f6b5 --- /dev/null +++ b/Gulpfile.js @@ -0,0 +1,10 @@ +var gulp = require('gulp'); +var minify = require('gulp-minify'); + +gulp.task('compress', function () { + gulp.src('lib/*.js') + .pipe(minify({ + ignore: ['-min.js'] + })) + .pipe(gulp.dest('lib')) +}); \ No newline at end of file diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..305aa6c --- /dev/null +++ b/bower.json @@ -0,0 +1,27 @@ +{ + "name": "jsonpath-plus", + "description": "A JS implementation of JSONPath with some additional operators", + "main": "./lib/jsonpath", + "authors": [ + "Stefan Goessner ", + "Subbu Allamaraju ", + "Mike Brevoort ", + "Robert Krahn ", + "Brett Zamir ", + "Richard Schneider " + ], + "license": "MIT", + "keywords": [ + "json", + "jsonpath" + ], + "moduleType": [], + "homepage": "https://github.com/mplabs/JSONPath.git", + "ignore": [ + "**/.*", + "node_modules", + "bower_components", + "test", + "tests" + ] +} diff --git a/lib/jsonpath-min.js b/lib/jsonpath-min.js new file mode 100644 index 0000000..f197088 --- /dev/null +++ b/lib/jsonpath-min.js @@ -0,0 +1 @@ +var module;!function(require){"use strict";function push(t,e){return t=t.slice(),t.push(e),t}function unshift(t,e){return e=e.slice(),e.unshift(t),e}function NewError(t){this.avoidNew=!0,this.value=t,this.message='JSONPath should not be called with "new" (it prevents return of (unwrapped) scalar values)'}function JSONPath(t,e,r,a,n){if(!(this instanceof JSONPath))try{return new JSONPath(t,e,r,a,n)}catch(i){if(!i.avoidNew)throw i;return i.value}"string"==typeof t&&(n=a,a=r,r=e,e=t,t={}),t=t||{};var o=t.hasOwnProperty("json")&&t.hasOwnProperty("path");if(this.json=t.json||r,this.path=t.path||e,this.resultType=t.resultType&&t.resultType.toLowerCase()||"value",this.flatten=t.flatten||!1,this.wrap=t.hasOwnProperty("wrap")?t.wrap:!0,this.sandbox=t.sandbox||{},this.preventEval=t.preventEval||!1,this.parent=t.parent||null,this.parentProperty=t.parentProperty||null,this.callback=t.callback||a||null,this.otherTypeCallback=t.otherTypeCallback||n||function(){throw new Error("You must supply an otherTypeCallback callback option with the @other() operator.")},t.autostart!==!1){var s=this.evaluate({path:o?t.path:e,json:o?t.json:r});if(!s||"object"!=typeof s)throw new NewError(s);return s}}var isNode=module&&!!module.exports,allowedResultTypes=["value","path","pointer","parent","parentProperty","all"],vm=isNode?require("vm"):{runInNewContext:function(expr,context){return eval(Object.keys(context).reduce(function(t,e){return"var "+e+"="+JSON.stringify(context[e]).replace(/\u2028|\u2029/g,function(t){return"\\u202"+("\u2028"===t?"8":"9")})+";"+t},expr))}};JSONPath.prototype.evaluate=function(t,e,r,a){var n=this,i=this.flatten,o=this.wrap,s=this.parent,p=this.parentProperty;if(this.currResultType=this.resultType,this.currPreventEval=this.preventEval,this.currSandbox=this.sandbox,r=r||this.callback,this.currOtherTypeCallback=a||this.otherTypeCallback,e=e||this.json,t=t||this.path,t&&"object"==typeof t){if(!t.path)throw new Error('You must supply a "path" property when providing an object argument to JSONPath.evaluate().');e=t.hasOwnProperty("json")?t.json:e,i=t.hasOwnProperty("flatten")?t.flatten:i,this.currResultType=t.hasOwnProperty("resultType")?t.resultType:this.currResultType,this.currSandbox=t.hasOwnProperty("sandbox")?t.sandbox:this.currSandbox,o=t.hasOwnProperty("wrap")?t.wrap:o,this.currPreventEval=t.hasOwnProperty("preventEval")?t.preventEval:this.currPreventEval,r=t.hasOwnProperty("callback")?t.callback:r,this.currOtherTypeCallback=t.hasOwnProperty("otherTypeCallback")?t.otherTypeCallback:this.currOtherTypeCallback,s=t.hasOwnProperty("parent")?t.parent:s,p=t.hasOwnProperty("parentProperty")?t.parentProperty:p,t=t.path}if(s=s||null,p=p||null,Array.isArray(t)&&(t=JSONPath.toPathString(t)),t&&e&&-1!==allowedResultTypes.indexOf(this.currResultType)){this._obj=e;var h=JSONPath.toPathArray(t);"$"===h[0]&&h.length>1&&h.shift();var l=this._trace(h,e,["$"],s,p,r);return l=l.filter(function(t){return t&&!t.isParentSelector}),l.length?1!==l.length||o||Array.isArray(l[0].value)?l.reduce(function(t,e){var r=n._getPreferredOutput(e);return i&&Array.isArray(r)?t=t.concat(r):t.push(r),t},[]):this._getPreferredOutput(l[0]):o?[]:void 0}},JSONPath.prototype._getPreferredOutput=function(t){var e=this.currResultType;switch(e){case"all":return t.path="string"==typeof t.path?t.path:JSONPath.toPathString(t.path),t;case"value":case"parent":case"parentProperty":return t[e];case"path":return JSONPath.toPathString(t[e]);case"pointer":return JSONPath.toPointer(t.path)}},JSONPath.prototype._handleCallback=function(t,e,r){if(e){var a=this._getPreferredOutput(t);t.path="string"==typeof t.path?t.path:JSONPath.toPathString(t.path),e(a,r,t)}},JSONPath.prototype._trace=function(t,e,r,a,n,i){function o(t){c=c.concat(t)}var s,p=this;if(!t.length)return s={path:r,value:e,parent:a,parentProperty:n},this._handleCallback(s,i,"value"),s;var h=t[0],l=t.slice(1),c=[];if(e&&Object.prototype.hasOwnProperty.call(e,h))o(this._trace(l,e[h],push(r,h),e,h,i));else if("*"===h)this._walk(h,l,e,r,a,n,i,function(t,e,r,a,n,i,s,h){o(p._trace(unshift(t,r),a,n,i,s,h))});else if(".."===h)o(this._trace(l,e,r,a,n,i)),this._walk(h,l,e,r,a,n,i,function(t,e,r,a,n,i,s,h){"object"==typeof a[t]&&o(p._trace(unshift(e,r),a[t],push(n,t),a,t,h))});else if("("===h[0]){if(this.currPreventEval)throw new Error("Eval [(expr)] prevented in JSONPath expression.");o(this._trace(unshift(this._eval(h,e,r[r.length-1],r.slice(0,-1),a,n),l),e,r,a,n,i))}else{if("^"===h)return r.length?{path:r.slice(0,-1),expr:l,isParentSelector:!0}:[];if("~"===h)return s={path:push(r,h),value:n,parent:a,parentProperty:null},this._handleCallback(s,i,"property"),s;if("$"===h)o(this._trace(l,e,r,null,null,i));else if(0===h.indexOf("?(")){if(this.currPreventEval)throw new Error("Eval [?(expr)] prevented in JSONPath expression.");this._walk(h,l,e,r,a,n,i,function(t,e,r,a,n,i,s,h){p._eval(e.replace(/^\?\((.*?)\)$/,"$1"),a[t],t,n,i,s)&&o(p._trace(unshift(t,r),a,n,i,s,h))})}else if(h.indexOf(",")>-1){var u,f;for(u=h.split(","),f=0;fp;p++)s(p,t,e,r,a,n,i,o);else if("object"==typeof r)for(l in r)Object.prototype.hasOwnProperty.call(r,l)&&s(l,t,e,r,a,n,i,o)},JSONPath.prototype._slice=function(t,e,r,a,n,i,o){if(Array.isArray(r)){var s,p=r.length,h=t.split(":"),l=h[0]&&parseInt(h[0],10)||0,c=h[1]&&parseInt(h[1],10)||p,u=h[2]&&parseInt(h[2],10)||1;l=0>l?Math.max(0,l+p):Math.min(p,l),c=0>c?Math.max(0,c+p):Math.min(p,c);var f=[];for(s=l;c>s;s+=u)f=f.concat(this._trace(unshift(s,e),r,a,n,i,o));return f}},JSONPath.prototype._eval=function(t,e,r,a,n,i){if(!this._obj||!e)return!1;t.indexOf("@parentProperty")>-1&&(this.currSandbox._$_parentProperty=i,t=t.replace(/@parentProperty/g,"_$_parentProperty")),t.indexOf("@parent")>-1&&(this.currSandbox._$_parent=n,t=t.replace(/@parent/g,"_$_parent")),t.indexOf("@property")>-1&&(this.currSandbox._$_property=r,t=t.replace(/@property/g,"_$_property")),t.indexOf("@path")>-1&&(this.currSandbox._$_path=JSONPath.toPathString(a.concat([r])),t=t.replace(/@path/g,"_$_path")),t.match(/@([\.\s\)\[])/)&&(this.currSandbox._$_v=e,t=t.replace(/@([\.\s\)\[])/g,"_$_v$1"));try{return vm.runInNewContext(t,this.currSandbox)}catch(o){throw console.log(o),new Error("jsonPath: "+o.message+": "+t)}},JSONPath.cache={},JSONPath.toPathString=function(t){var e,r,a=t,n="$";for(e=1,r=a.length;r>e;e++)/^(~|\^|@.*?\(\))$/.test(a[e])||(n+=/^[0-9*]+$/.test(a[e])?"["+a[e]+"]":"['"+a[e]+"']");return n},JSONPath.toPointer=function(t){var e,r,a=t,n="";for(e=1,r=a.length;r>e;e++)/^(~|\^|@.*?\(\))$/.test(a[e])||(n+="/"+a[e].toString().replace(/\~/g,"~0").replace(/\//g,"~1"));return n},JSONPath.toPathArray=function(t){var e=JSONPath.cache;if(e[t])return e[t];var r=[],a=t.replace(/@(?:null|boolean|number|string|integer|undefined|nonFinite|scalar|array|object|function|other)\(\)/g,";$&;").replace(/[\['](\??\(.*?\))[\]']/g,function(t,e){return"[#"+(r.push(e)-1)+"]"}).replace(/\['([^'\]]*)'\]/g,function(t,e){return"['"+e.replace(/\./g,"%@%").replace(/~/g,"%%@@%%")+"']"}).replace(/~/g,";~;").replace(/'?\.'?(?![^\[]*\])|\['?/g,";").replace(/%@%/g,".").replace(/%%@@%%/g,"~").replace(/(?:;)?(\^+)(?:;)?/g,function(t,e){return";"+e.split("").join(";")+";"}).replace(/;;;|;;/g,";..;").replace(/;$|'?\]|'$/g,""),n=a.split(";").map(function(t){var e=t.match(/#([0-9]+)/);return e&&e[1]?r[e[1]]:t});return e[t]=n,e[t]},JSONPath.eval=function(t,e,r){return JSONPath(r,e,t)},"function"==typeof define&&define.amd?define(function(){return JSONPath}):isNode?module.exports=JSONPath:(self.jsonPath={eval:JSONPath.eval},self.JSONPath=JSONPath)}("undefined"==typeof require?null:require); \ No newline at end of file diff --git a/package.json b/package.json index 69136a1..a32213b 100644 --- a/package.json +++ b/package.json @@ -1,52 +1,59 @@ { - "author": "Stefan Goessner", - "name": "jsonpath-plus", - "description": "A JS implementation of JSONPath with some additional operators", - "contributors": [ - { - "name": "Prof. Gössner", - "email": "stefan.goessner@fh-dortmund.de" - }, - { - "name": "Subbu Allamaraju", - "email": "subbu@subbu.org" - }, - { - "name": "Mike Brevoort", - "email": "mike@brevoort.com" - }, - { - "name": "Robert Krahn", - "email": "robert.krahn@gmail.com" - }, - { - "name": "Brett Zamir", - "email": "brettz9@yahoo.com" - }, - { - "name": "Richard Schneider", - "email": "makaretu@gmail.com" - } - ], - "license": "MIT", - "version": "0.14.0", - "repository": { - "type": "git", - "url": "git://github.com/s3u/JSONPath.git" + "author": "Stefan Goessner", + "name": "jsonpath-plus", + "description": "A JS implementation of JSONPath with some additional operators", + "contributors": [ + { + "name": "Prof. Gössner", + "email": "stefan.goessner@fh-dortmund.de" }, - "bugs": "https://github.com/s3u/JSONPath/issues/", - "homepage": "https://github.com/s3u/JSONPath", - "main": "./lib/jsonpath", - "dependencies": {}, - "engines": { - "node": ">=0.8" + { + "name": "Subbu Allamaraju", + "email": "subbu@subbu.org" }, - "devDependencies": { - "nodeunit": "0.9.0", - "eslint": "^1.10.3", - "eslint-config-standard": "^4.4.0", - "eslint-plugin-standard": "^1.3.1" + { + "name": "Mike Brevoort", + "email": "mike@brevoort.com" }, - "keywords": ["json", "jsonpath"], - "scripts": {"test": "./node_modules/.bin/eslint test lib && \"./node_modules/.bin/nodeunit\" test"} + { + "name": "Robert Krahn", + "email": "robert.krahn@gmail.com" + }, + { + "name": "Brett Zamir", + "email": "brettz9@yahoo.com" + }, + { + "name": "Richard Schneider", + "email": "makaretu@gmail.com" + } + ], + "license": "MIT", + "version": "0.14.0", + "repository": { + "type": "git", + "url": "https://github.com/mplabs/JSONPath.git" + }, + "bugs": "https://github.com/s3u/JSONPath/issues/", + "homepage": "https://github.com/s3u/JSONPath", + "main": "./lib/jsonpath", + "dependencies": {}, + "engines": { + "node": ">=0.8" + }, + "devDependencies": { + "eslint": "^1.10.3", + "eslint-config-standard": "^4.4.0", + "eslint-plugin-standard": "^1.3.1", + "gulp": "^3.9.1", + "gulp-minify": "0.0.5", + "nodeunit": "0.9.0" + }, + "keywords": [ + "json", + "jsonpath" + ], + "scripts": { + "test": "./node_modules/.bin/eslint test lib && \"./node_modules/.bin/nodeunit\" test" + } }