Backend half
This commit is contained in:
1 parent
fa868e7c1d
commit
8600fa7c1d
19426 files changed
+3750448
-8108
No files matched your search
+13
@@ -0,0 +1,13 @@
|
||||
Copyright 2014 James Saryerwinnie
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
# jmespath.js
|
||||
|
||||
[](https://travis-ci.org/jmespath/jmespath.js)
|
||||
|
||||
jmespath.js is a javascript implementation of JMESPath,
|
||||
which is a query language for JSON. It will take a JSON
|
||||
document and transform it into another JSON document
|
||||
through a JMESPath expression.
|
||||
|
||||
Using jmespath.js is really easy. There's a single function
|
||||
you use, `jmespath.search`:
|
||||
|
||||
|
||||
```
|
||||
> var jmespath = require('jmespath');
|
||||
> jmespath.search({foo: {bar: {baz: [0, 1, 2, 3, 4]}}}, "foo.bar.baz[2]")
|
||||
2
|
||||
```
|
||||
|
||||
In the example we gave the ``search`` function input data of
|
||||
`{foo: {bar: {baz: [0, 1, 2, 3, 4]}}}` as well as the JMESPath
|
||||
expression `foo.bar.baz[2]`, and the `search` function evaluated
|
||||
the expression against the input data to produce the result ``2``.
|
||||
|
||||
The JMESPath language can do a lot more than select an element
|
||||
from a list. Here are a few more examples:
|
||||
|
||||
```
|
||||
> jmespath.search({foo: {bar: {baz: [0, 1, 2, 3, 4]}}}, "foo.bar")
|
||||
{ baz: [ 0, 1, 2, 3, 4 ] }
|
||||
|
||||
> jmespath.search({"foo": [{"first": "a", "last": "b"},
|
||||
{"first": "c", "last": "d"}]},
|
||||
"foo[*].first")
|
||||
[ 'a', 'c' ]
|
||||
|
||||
> jmespath.search({"foo": [{"age": 20}, {"age": 25},
|
||||
{"age": 30}, {"age": 35},
|
||||
{"age": 40}]},
|
||||
"foo[?age > `30`]")
|
||||
[ { age: 35 }, { age: 40 } ]
|
||||
```
|
||||
|
||||
## More Resources
|
||||
|
||||
The example above only show a small amount of what
|
||||
a JMESPath expression can do. If you want to take a
|
||||
tour of the language, the *best* place to go is the
|
||||
[JMESPath Tutorial](http://jmespath.org/tutorial.html).
|
||||
|
||||
One of the best things about JMESPath is that it is
|
||||
implemented in many different programming languages including
|
||||
python, ruby, php, lua, etc. To see a complete list of libraries,
|
||||
check out the [JMESPath libraries page](http://jmespath.org/libraries.html).
|
||||
|
||||
And finally, the full JMESPath specification can be found
|
||||
on the [JMESPath site](http://jmespath.org/specification.html).
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
/*! jmespath 2016-03-22 */
|
||||
!function(a){"use strict";function b(a){return null!==a?"[object Array]"===Object.prototype.toString.call(a):!1}function c(a){return null!==a?"[object Object]"===Object.prototype.toString.call(a):!1}function d(a,e){if(a===e)return!0;var f=Object.prototype.toString.call(a);if(f!==Object.prototype.toString.call(e))return!1;if(b(a)===!0){if(a.length!==e.length)return!1;for(var g=0;g<a.length;g++)if(d(a[g],e[g])===!1)return!1;return!0}if(c(a)===!0){var h={};for(var i in a)if(hasOwnProperty.call(a,i)){if(d(a[i],e[i])===!1)return!1;h[i]=!0}for(var j in e)if(hasOwnProperty.call(e,j)&&h[j]!==!0)return!1;return!0}return!1}function e(a){if(""===a||a===!1||null===a)return!0;if(b(a)&&0===a.length)return!0;if(c(a)){for(var d in a)if(a.hasOwnProperty(d))return!1;return!0}return!1}function f(a){for(var b=Object.keys(a),c=[],d=0;d<b.length;d++)c.push(a[b[d]]);return c}function g(a){return a>="a"&&"z">=a||a>="A"&&"Z">=a||"_"===a}function h(a){return a>="0"&&"9">=a||"-"===a}function i(a){return a>="a"&&"z">=a||a>="A"&&"Z">=a||a>="0"&&"9">=a||"_"===a}function j(){}function k(){}function l(a){this.runtime=a}function m(a){this.a=a,this.functionTable={abs:{b:this.c,d:[{types:[r]}]},avg:{b:this.e,d:[{types:[z]}]},ceil:{b:this.f,d:[{types:[r]}]},contains:{b:this.g,d:[{types:[t,u]},{types:[s]}]},ends_with:{b:this.h,d:[{types:[t]},{types:[t]}]},floor:{b:this.i,d:[{types:[r]}]},length:{b:this.j,d:[{types:[t,u,v]}]},map:{b:this.k,d:[{types:[x]},{types:[u]}]},max:{b:this.l,d:[{types:[z,A]}]},merge:{b:this.m,d:[{types:[v],variadic:!0}]},max_by:{b:this.n,d:[{types:[u]},{types:[x]}]},sum:{b:this.o,d:[{types:[z]}]},starts_with:{b:this.p,d:[{types:[t]},{types:[t]}]},min:{b:this.q,d:[{types:[z,A]}]},min_by:{b:this.r,d:[{types:[u]},{types:[x]}]},type:{b:this.s,d:[{types:[s]}]},keys:{b:this.t,d:[{types:[v]}]},values:{b:this.u,d:[{types:[v]}]},sort:{b:this.v,d:[{types:[A,z]}]},sort_by:{b:this.w,d:[{types:[u]},{types:[x]}]},join:{b:this.x,d:[{types:[t]},{types:[A]}]},reverse:{b:this.y,d:[{types:[t,u]}]},to_array:{b:this.z,d:[{types:[s]}]},to_string:{b:this.A,d:[{types:[s]}]},to_number:{b:this.B,d:[{types:[s]}]},not_null:{b:this.C,d:[{types:[s],variadic:!0}]}}}function n(a){var b=new k,c=b.parse(a);return c}function o(a){var b=new j;return b.tokenize(a)}function p(a,b){var c=new k,d=new m,e=new l(d);d.a=e;var f=c.parse(b);return e.search(f,a)}var q;q="function"==typeof String.prototype.trimLeft?function(a){return a.trimLeft()}:function(a){return a.match(/^\s*(.*)/)[1]};var r=0,s=1,t=2,u=3,v=4,w=5,x=6,y=7,z=8,A=9,B="EOF",C="UnquotedIdentifier",D="QuotedIdentifier",E="Rbracket",F="Rparen",G="Comma",H="Colon",I="Rbrace",J="Number",K="Current",L="Expref",M="Pipe",N="Or",O="And",P="EQ",Q="GT",R="LT",S="GTE",T="LTE",U="NE",V="Flatten",W="Star",X="Filter",Y="Dot",Z="Not",$="Lbrace",_="Lbracket",aa="Lparen",ba="Literal",ca={".":Y,"*":W,",":G,":":H,"{":$,"}":I,"]":E,"(":aa,")":F,"@":K},da={"<":!0,">":!0,"=":!0,"!":!0},ea={" ":!0," ":!0,"\n":!0};j.prototype={tokenize:function(a){var b=[];this.D=0;for(var c,d,e;this.D<a.length;)if(g(a[this.D]))c=this.D,d=this.E(a),b.push({type:C,value:d,start:c});else if(void 0!==ca[a[this.D]])b.push({type:ca[a[this.D]],value:a[this.D],start:this.D}),this.D++;else if(h(a[this.D]))e=this.F(a),b.push(e);else if("["===a[this.D])e=this.G(a),b.push(e);else if('"'===a[this.D])c=this.D,d=this.H(a),b.push({type:D,value:d,start:c});else if("'"===a[this.D])c=this.D,d=this.I(a),b.push({type:ba,value:d,start:c});else if("`"===a[this.D]){c=this.D;var f=this.J(a);b.push({type:ba,value:f,start:c})}else if(void 0!==da[a[this.D]])b.push(this.K(a));else if(void 0!==ea[a[this.D]])this.D++;else if("&"===a[this.D])c=this.D,this.D++,"&"===a[this.D]?(this.D++,b.push({type:O,value:"&&",start:c})):b.push({type:L,value:"&",start:c});else{if("|"!==a[this.D]){var i=new Error("Unknown character:"+a[this.D]);throw i.name="LexerError",i}c=this.D,this.D++,"|"===a[this.D]?(this.D++,b.push({type:N,value:"||",start:c})):b.push({type:M,value:"|",start:c})}return b},E:function(a){var b=this.D;for(this.D++;this.D<a.length&&i(a[this.D]);)this.D++;return a.slice(b,this.D)},H:function(a){var b=this.D;this.D++;for(var c=a.length;'"'!==a[this.D]&&this.D<c;){var d=this.D;"\\"!==a[d]||"\\"!==a[d+1]&&'"'!==a[d+1]?d++:d+=2,this.D=d}return this.D++,JSON.parse(a.slice(b,this.D))},I:function(a){var b=this.D;this.D++;for(var c=a.length;"'"!==a[this.D]&&this.D<c;){var d=this.D;"\\"!==a[d]||"\\"!==a[d+1]&&"'"!==a[d+1]?d++:d+=2,this.D=d}this.D++;var e=a.slice(b+1,this.D-1);return e.replace("\\'","'")},F:function(a){var b=this.D;this.D++;for(var c=a.length;h(a[this.D])&&this.D<c;)this.D++;var d=parseInt(a.slice(b,this.D));return{type:J,value:d,start:b}},G:function(a){var b=this.D;return this.D++,"?"===a[this.D]?(this.D++,{type:X,value:"[?",start:b}):"]"===a[this.D]?(this.D++,{type:V,value:"[]",start:b}):{type:_,value:"[",start:b}},K:function(a){var b=this.D,c=a[b];return this.D++,"!"===c?"="===a[this.D]?(this.D++,{type:U,value:"!=",start:b}):{type:Z,value:"!",start:b}:"<"===c?Line truncated
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "jmespath.js",
|
||||
"main": "jmespath.js",
|
||||
"version": "0.11.0",
|
||||
"homepage": "https://github.com/jmespath/jmespath.js",
|
||||
"authors": [
|
||||
"James Saryerwinnie <js@jamesls.com>"
|
||||
],
|
||||
"description": "JMESPath implementation in javascript",
|
||||
"moduleType": [
|
||||
"node"
|
||||
],
|
||||
"keywords": [
|
||||
"jmespath"
|
||||
],
|
||||
"license": "MIT",
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
"node_modules",
|
||||
"bower_components",
|
||||
"test",
|
||||
"tests"
|
||||
]
|
||||
}
|
||||
+1672
File diff suppressed because it is too large.
Load diff
+23
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env node
|
||||
jmespath = require('./jmespath');
|
||||
|
||||
process.stdin.setEncoding('utf-8');
|
||||
|
||||
|
||||
if (process.argv.length < 2) {
|
||||
console.log("Must provide a jmespath expression.");
|
||||
process.exit(1);
|
||||
}
|
||||
var inputJSON = "";
|
||||
|
||||
process.stdin.on('readable', function() {
|
||||
var chunk = process.stdin.read();
|
||||
if (chunk !== null) {
|
||||
inputJSON += chunk;
|
||||
}
|
||||
});
|
||||
|
||||
process.stdin.on('end', function() {
|
||||
var parsedInput = JSON.parse(inputJSON);
|
||||
console.log(JSON.stringify(jmespath.search(parsedInput, process.argv[2])));
|
||||
});
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"name": "jmespath",
|
||||
"description": "JMESPath implementation in javascript",
|
||||
"version": "0.16.0",
|
||||
"author": {
|
||||
"name": "James Saryerwinnie",
|
||||
"email": "js@jamesls.com",
|
||||
"url": "http://jamesls.com/"
|
||||
},
|
||||
"homepage": "https://github.com/jmespath/jmespath.js",
|
||||
"contributors": [],
|
||||
"devDependencies": {
|
||||
"grunt": "^0.4.5",
|
||||
"grunt-contrib-jshint": "^0.11.0",
|
||||
"grunt-contrib-uglify": "^0.11.1",
|
||||
"grunt-eslint": "^17.3.1",
|
||||
"mocha": "^2.1.0"
|
||||
},
|
||||
"dependencies": {},
|
||||
"main": "jmespath.js",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6.0"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/jmespath/jmespath.js"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "http://github.com/jmespath/jmespath.js/issues",
|
||||
"mail": ""
|
||||
},
|
||||
"license": "Apache-2.0",
|
||||
"keywords": [
|
||||
"jmespath",
|
||||
"jsonpath",
|
||||
"json",
|
||||
"xpath"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "mocha test/"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user