Skip to content

Commit 562dbf9

Browse files
committedSep 27, 2016
first commit
0 parents  commit 562dbf9

13 files changed

+8092
-0
lines changed
 

‎.eslintignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
coverage/
2+
node_modules/
3+
doc/

‎.eslintrc

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
// This is a set of basic and sensible rules that should not change except at major ESLint versions
3+
"extends": "eslint:recommended",
4+
5+
// Environments that we run in
6+
"env": {
7+
"node": true,
8+
"mocha": true,
9+
"es6": true
10+
},
11+
12+
// Extra plugins required
13+
"plugins": [
14+
"ideal" // for tabs in file
15+
],
16+
17+
// Additional rules
18+
"rules": {
19+
"array-bracket-spacing": ["error", "never"],
20+
"dot-notation": "error",
21+
"ideal/no-tabs-in-file": "error",
22+
"indent": ["error", 4, {"SwitchCase": 1}],
23+
"max-len": ["error", 1000, {"ignoreComments": true}],
24+
"new-cap": ["error", {"capIsNewExceptions": ["Router"]}],
25+
"no-console": "off",
26+
"no-floating-decimal": "error",
27+
"no-lonely-if": "error",
28+
"no-spaced-func": "error",
29+
"no-throw-literal": "off",
30+
"no-trailing-spaces": "error",
31+
"no-use-before-define": ["error", {"functions": false}],
32+
"no-useless-call": "error",
33+
"no-with": "error",
34+
"operator-linebreak": ["error", "after"],
35+
"require-jsdoc": ["error", {
36+
"require": {
37+
"ClassDeclaration": true,
38+
"MethodDefinition": true,
39+
"FunctionDeclaration": true
40+
}
41+
}],
42+
"semi": ["error", "always"],
43+
"strict": ["error", "global"],
44+
"valid-jsdoc": ["error", {"requireReturn": false}]
45+
}
46+
}

‎.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/karma.conf.js
2+
node_modules/
3+
coverage/
4+
npm-debug.log
5+
doc/
6+
.idea

‎CONTRIBUTING.md

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Contributing to JSONata
2+
3+
We welcome contributions, but request you follow these guidelines.
4+
5+
- [Raising issues](#raising-issues)
6+
- [Feature requests](#feature-requests)
7+
- [Pull-Requests](#pull-requests)
8+
9+
This project adheres to the [Contributor Covenant 1.4](http://contributor-covenant.org/version/1/4/).
10+
By participating, you are expected to uphold this code. Please report unacceptable
11+
behavior to any of the [project's core team](https://github.com/orgs/jsonata-js/teams/core).
12+
13+
## Raising issues
14+
15+
Please raise any bug reports on the relevant project's issue tracker. Be sure to
16+
search the list to see if your issue has already been raised.
17+
18+
A good bug report is one that make it easy for us to understand what you were
19+
trying to do and what went wrong.
20+
21+
Provide as much context as possible so we can try to recreate the issue.
22+
23+
At a minimum, please include:
24+
25+
- Version of JSONata - either release number if you downloaded a zip, or the first few lines of `git log` if you are cloning the repository directly.
26+
- Version of node.js (`node -v`), or browser vendor and version.
27+
28+
## Feature requests
29+
30+
tba
31+
32+
## Pull-Requests
33+
34+
tba
35+
36+
### Legal Stuff
37+
38+
We have tried to make it as easy as possible to make contributions.
39+
This applies to how we handle the legal aspects of contribution.
40+
We use the same approach—the [Developer's Certificate of Origin 1.1 (DCO)](DCO1.1.txt)—that the Linux® Kernel [community](http://elinux.org/Developer_Certificate_Of_Origin) uses to manage code contributions.
41+
We simply ask that when submitting a pull request, the developer must include a sign-off statement in the pull request description.
42+
43+
Here is an example Signed-off-by line, which indicates that the submitter accepts the DCO:
44+
45+
```
46+
Signed-off-by: John Doe <john.doe@hisdomain.com>
47+
```
48+
49+
### Coding standards
50+
51+
Please ensure you follow the coding standards used through-out the existing
52+
code base. Coding standards are checked by ESLint. 100% test coverage
53+
must be maintained at all times.
54+
Run the following command to check coding rules and test coverage:
55+
56+
- npm t

‎DCO1.1.txt

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Developer's Certificate of Origin 1.1
2+
3+
By making a contribution to this project, I certify that:
4+
5+
(a) The contribution was created in whole or in part by me and I
6+
have the right to submit it under the open source license
7+
indicated in the file; or
8+
9+
(b) The contribution is based upon previous work that, to the best
10+
of my knowledge, is covered under an appropriate open source
11+
license and I have the right under that license to submit that
12+
work with modifications, whether created in whole or in part
13+
by me, under the same open source license (unless I am
14+
permitted to submit under a different license), as indicated
15+
in the file; or
16+
17+
(c) The contribution was provided directly to me by some other
18+
person who certified (a), (b) or (c) and I have not modified
19+
it.
20+
21+
(d) I understand and agree that this project and the contribution
22+
are public and that a record of the contribution (including all
23+
personal information I submit with it, including my sign-off) is
24+
maintained indefinitely and may be redistributed consistent with
25+
this project or the open source license(s) involved.

‎LICENSE

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
MIT license
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

‎README.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# JSONata
2+
JSON query and transformation language
3+
4+
##Introduction
5+
The primary purpose of this language is to extract values from JSON documents, with the
6+
additional capabilities to combine these values using a set of basic functions
7+
and operators, and also the ability to format the output into any arbitrary JSON structure.
8+
9+
##Quick Start
10+
- `npm install jsonata`
11+
12+
13+
14+
##Tutorial
15+
A tutorial on the JSONata language is available [here](./tutorial.md)
16+
17+
##Errors
18+
19+
If an expression throws an error, e.g. syntax error or a runtime error (type error), then the object thrown
20+
has a consistent structure containing the column number of the error, the token that caused the error,
21+
and any other relevant information, including a meaningful message string.
22+
23+
For example:
24+
25+
`{ "position": 16, "token": "}", "value": "]", "message": "Syntax error: expected ']' got '}' at column 16" }`
26+
27+
##More Information
28+
Tutorial [tutorial.md](./tutorial.md)
29+
Function library [functions.md](./functions.md)
30+
31+
## Contributing changes
32+
See the [CONTRIBUTING.md](./CONTRIBUTING.md) for details of how to contribute to this repo.

‎functions.md

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
## JSONata Function Library
2+
The following is a proposed function library for use within JSONata expressions.
3+
This is work in progress. Some of these functions have been implemented, but mostly not.
4+
5+
6+
#### String functions
7+
- `$string(arg)`
8+
9+
Casts the `arg` parameter to a string
10+
11+
- `$length(str)`
12+
13+
Returns the number of characters in the string `str`
14+
15+
- `$substring(str, start[, length])`
16+
17+
Returns a string containing the characters in the first parameter `str`
18+
starting at position `start` (zero-offset). If `length` is specified, then
19+
the substring will contain maximum `length` characters. If `start` is negative
20+
then it indicates the number of characters from the end of `str`.
21+
See [substr](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/substr) for full definition.
22+
23+
- `$substringBefore(str, chars)`
24+
25+
Returns the substring before the first occurrence of the character sequence `chars` in `str`.
26+
If `str` does not contain `chars`, then it returns `str`.
27+
28+
29+
- `$substringAfter(str, chars)`
30+
31+
Returns the substring after the first occurrence of the character sequence `chars` in `str`.
32+
If `str` does not contain `chars`, then it returns `str`.
33+
34+
35+
- `$uppercase(str)`
36+
37+
Returns a string with all the characters of `str` converted to uppercase.
38+
39+
40+
- `$lowercase(str)`
41+
42+
Returns a string with all the characters of `str` converted to lowercase.
43+
44+
45+
- `$split(str, separator)`
46+
47+
- `$join(array[, separator])`
48+
49+
- `$format(pattern, ...)`
50+
51+
[printf style formatting](https://en.wikipedia.org/wiki/Printf_format_string#Format_placeholder_specification). Other formatting schemes are available.
52+
53+
#### Numerical functions
54+
55+
- `$number(arg)`
56+
57+
Cast the value of `arg` to a number
58+
59+
- `$sum(array)`
60+
- `$abs(number)`
61+
- `$max(array)`
62+
- `$min(array)`
63+
- `$round(number)`
64+
65+
Rounds up to the nearest integer
66+
67+
- `$roundHalfToEven(number)`
68+
69+
[Round half to even](https://en.wikipedia.org/wiki/Rounding#Round_half_to_even) Commonly used in financial calculations.
70+
71+
- `$average(array)`
72+
- `$power(base, exponent)`
73+
74+
#### Boolean functions
75+
76+
- `$boolean(arg)`
77+
78+
Casts the argument to a Boolean
79+
80+
- `$not(arg)`
81+
82+
Returns Boolean NOT on the argument. `arg` is first cast to a boolean
83+
84+
#### Date/Time functions
85+
86+
#### Array functions
87+
88+
- `$count(array)`
89+
90+
Returns the number of items in the array
91+
92+
- `$append(array, array)`
93+
94+
Appends two arrays
95+
96+
- `$flatten(array)`
97+
98+
Flattens nested array into flat array
99+
100+
- `$range(start, end, increment)`
101+
102+
Generates an array of numbers starting with `start`, not exceeding `end`, in increments of `increment` (defaults to 1)
103+
104+
#### Object functions
105+
106+
- `$keys(object)`
107+
108+
Returns an array containing the keys in the object
109+
110+
- `$lookup(object, key)`
111+
112+
Returns the value assosciated with `key` in `object`
113+
114+
- `$merge(object, object)`
115+
116+
Returns an object containing the union of the two `object` parameters. If an entry in the second object
117+
has the same key as an entry in the first, then the value will be overridden by the second.

‎jsdoc.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"tags": {
3+
"allowUnknownTags": true,
4+
"dictionaries": ["jsdoc","closure"]
5+
},
6+
"source": {
7+
"includePattern": ".+\\.js(doc)?$",
8+
"excludePattern": "(^|\\/|\\\\)_|node_modules|doc|coverage"
9+
},
10+
"plugins": [],
11+
"templates": {
12+
"cleverLinks": false,
13+
"monospaceLinks": false
14+
},
15+
"opts": {
16+
"encoding": "utf8",
17+
"destination": "doc",
18+
"recurse": true,
19+
"private": true,
20+
"pedantic": true
21+
}
22+
}

‎jsonata.js

+2,269
Large diffs are not rendered by default.

‎package.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "jsonata",
3+
"version": "1.0.0",
4+
"main": "jsonata.js",
5+
"scripts": {
6+
"pretest": "npm run lint",
7+
"test": "node ./node_modules/istanbul/lib/cli.js cover --report cobertura --report html ./node_modules/mocha/bin/_mocha -- --reporter mocha-jenkins-reporter \"test/**/*.js\"",
8+
"posttest": "istanbul check-coverage -statement 100 -branch 100 -function 100 -line 100",
9+
"licence-check": "license-checker --production --csv",
10+
"lint": "eslint .",
11+
"lint-checkstyle-XML-log": "eslint -f checkstyle . || true",
12+
"postlint": "npm run doc",
13+
"doc": "jsdoc --configure jsdoc.json ."
14+
},
15+
"author": "",
16+
"license": "",
17+
"devDependencies": {
18+
"chai": "^3.4.1",
19+
"eslint": "^3.6.0",
20+
"eslint-plugin-ideal": "^0.1.3",
21+
"istanbul": "^0.4.5",
22+
"jsdoc": "^3.4.0",
23+
"license-checker": "^6.0.0",
24+
"mocha": "^3.0.2",
25+
"mocha-jenkins-reporter": "^0.2.4"
26+
}
27+
}

‎test/jsonata-test.js

+4,973
Large diffs are not rendered by default.

‎tutorial.md

+497
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.