Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.

Commit 1fcfd7f

Browse files
authored
Merge pull request #1 from axa-ch/refactore/update-to-modern-js
Update to modern javascript
2 parents a15f528 + 5b5de10 commit 1fcfd7f

File tree

132 files changed

+2529
-772
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+2529
-772
lines changed

.babelrc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"presets": [
3+
[
4+
"@babel/preset-env",
5+
{
6+
"modules": false,
7+
"useBuiltIns": false
8+
}
9+
]
10+
],
11+
"plugins": [
12+
"@babel/plugin-proposal-export-default-from"
13+
]
14+
}

.eslintrc.json

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,8 @@
11
{
2-
"extends": "google",
3-
2+
"extends": ["airbnb", "plugin:prettier/recommended"],
43
"rules": {
5-
"no-var": "off",
6-
"indent": [
7-
"error",
8-
2
9-
],
10-
"linebreak-style": [
11-
"error",
12-
"unix"
13-
],
14-
"quotes": [
15-
"error",
16-
"double", {
17-
"avoidEscape": true
18-
}
19-
],
20-
"semi": [
21-
"error",
22-
"always"
23-
],
24-
"max-len": [
25-
"warn", {
26-
"ignoreComments": true
27-
}
28-
],
29-
"prefer-spread": ["off"],
30-
"prefer-rest-params": ["off"],
31-
"camelcase" : ["off"]
4+
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }],
5+
"no-use-before-define": ["error", { "functions": false }],
6+
"camelcase": "off"
327
}
338
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
node_modules
22
tests/*.json
33

4+
package-lock.json
5+
46
# editor and IDE remnants
57
*~
68
.idea/

.huskyrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"hooks": {
3+
"pre-commit": "lint-staged"
4+
}
5+
}

.lintstagedrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"src/**/*.{js,jsx,json}": ["eslint --fix", "git add"]
3+
}

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
tests/tests.json
2+
src
23
play.html
34
bower.json
45

.prettierrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"trailingComma": "es5",
3+
"semi": true,
4+
"singleQuote": true,
5+
"bracketSpacing": true
6+
}

README.md

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,33 @@ The same format can also be executed in PHP by the library [json-logic-php](http
88

99
## Installation
1010

11-
To parse JsonLogic rules in a JavaScript frontend, install this library is via [Bower](http://bower.io/):
11+
To parse JsonLogic rules in a JavaScript backend (like Node.js), install this library via [NPM](https://www.npmjs.com/):
1212

1313
```bash
14-
bower install --save json-logic-js
14+
npm install @axa-ch/json-logic-js --save
1515
```
1616

17-
To parse JsonLogic rules in a JavaScript backend (like Node.js), install this library via [NPM](https://www.npmjs.com/):
17+
Note that this project provides:
18+
- an ESM build for cherry picking
19+
- a [module loader](http://ricostacruz.com/cheatsheets/umdjs.html) that also makes it suitable for RequireJS projects.
20+
- a minified bundle ready for the browser
1821

19-
```bash
20-
npm install json-logic-js
21-
```
22+
If that doesn't suit you, and you want to manage updates yourself, the entire library is self-contained in `dist/jsonLogic.js` and you can download it straight into your project as you see fit.
2223

23-
Note that this project uses a [module loader](http://ricostacruz.com/cheatsheets/umdjs.html) that also makes it suitable for RequireJS projects.
24+
## Cherry-picked build
2425

25-
If that doesn't suit you, and you want to manage updates yourself, the entire library is self-contained in `logic.js` and you can download it straight into your project as you see fit.
26+
If the default bundle size is too big for you or you only need certain operations, just utilize the ESM build and create your customized `jsonLogic` object as follows:
2627

27-
```bash
28-
curl -O https://raw.githubusercontent.com/jwadhams/json-logic-js/master/logic.js
28+
```js
29+
import createJsonLogic from './createJsonLogic';
30+
31+
// pick just what you need, or create your own
32+
import { equal } from './operations';
33+
import { and, or } from './visitors';
34+
35+
const jsonLogic = createJsonLogic({ equal }, { and, or });
36+
37+
export default jsonLogic;
2938
```
3039

3140
## Examples
@@ -122,7 +131,7 @@ jsonLogic.apply(false, i_wasnt_even_supposed_to_be_here);
122131

123132
## Compatibility
124133

125-
This library makes use of `Array.map` and `Array.reduce`, so it's not *exactly* Internet Explorer 8 friendly.
134+
This library makes use of `Array.isArray`, `Array.forEach`, `Array.map` and `Array.reduce`, so it's not *exactly* Internet Explorer 8 friendly.
126135

127136
If you want to use JsonLogic *and* support deprecated browsers, you could easily use [BabelJS's polyfill](https://babeljs.io/docs/usage/polyfill/) or directly incorporate the polyfills documented on MDN for [map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) and [reduce](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce).
128137

bower.json

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)