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

Update to modern javascript #1

Merged
merged 33 commits into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
aa69be4
refactore: extract operations
AndyOGo Feb 21, 2019
d11373c
refactore: extracted helpers
AndyOGo Feb 21, 2019
535dd80
refactore: truthy and falsy operations
AndyOGo Feb 21, 2019
e6e627f
refactore: start extracting visitors
AndyOGo Feb 21, 2019
8ae7689
fix: added missing operator code
AndyOGo Feb 21, 2019
e84b724
refactore: naming of accessors
AndyOGo Feb 21, 2019
90da723
refactore: visitor names
AndyOGo Feb 21, 2019
e68d842
refactore: start applying visitors
AndyOGo Feb 21, 2019
b3c2426
fix: restored original API
AndyOGo Feb 21, 2019
65f7549
feat: also export jsonLogic creator
AndyOGo Feb 21, 2019
4656028
refactore: api
AndyOGo Feb 22, 2019
02e84a6
fix: grouped operations and visitors by kind
AndyOGo Feb 22, 2019
8bebfc1
fix: imports and exports
AndyOGo Feb 22, 2019
21bb46d
fix: cached isArray
AndyOGo Feb 22, 2019
7566f8a
fix: broken tests
AndyOGo Feb 22, 2019
859945b
refactore: enabled babel, rollup, tests,...
AndyOGo Feb 22, 2019
f68c165
fix: upgraded qunit
AndyOGo Feb 22, 2019
1518cb3
refactore: build
AndyOGo Feb 22, 2019
bb9cb75
feat: added module, browser and main field
AndyOGo Feb 22, 2019
4279063
feat: enable source maps
AndyOGo Feb 22, 2019
f605f04
chore: rebuild
AndyOGo Feb 22, 2019
330d37d
deleted bower.json
AndyOGo Feb 22, 2019
55987ff
feat: exclude src from npm
AndyOGo Feb 22, 2019
9f87e40
chore: updated package.json infos
AndyOGo Feb 22, 2019
8b00430
fix: removed duplicates
AndyOGo Feb 22, 2019
42a7a32
chore: added prettier with eslint
AndyOGo Feb 22, 2019
255539c
chore: fix eslint, prettier errors
AndyOGo Feb 22, 2019
108624c
chore: added commit hook for eslint/prettier
AndyOGo Feb 22, 2019
acc6858
chore: rebuild
AndyOGo Feb 22, 2019
c3f18df
docs: updated array notes
AndyOGo Feb 22, 2019
5450731
docs: added chrry picking docs
AndyOGo Feb 22, 2019
182447f
fix: removed old logic.js
AndyOGo Feb 22, 2019
5b5de10
chore: clean husky and lint-staged configuration
AndyOGo Feb 28, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"presets": [
[
"@babel/preset-env",
{
"modules": false,
"useBuiltIns": false
}
]
],
"plugins": [
"@babel/plugin-proposal-export-default-from"
]
}
33 changes: 4 additions & 29 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,8 @@
{
"extends": "google",

"extends": ["airbnb", "plugin:prettier/recommended"],
"rules": {
"no-var": "off",
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"double", {
"avoidEscape": true
}
],
"semi": [
"error",
"always"
],
"max-len": [
"warn", {
"ignoreComments": true
}
],
"prefer-spread": ["off"],
"prefer-rest-params": ["off"],
"camelcase" : ["off"]
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }],
"no-use-before-define": ["error", { "functions": false }],
"camelcase": "off"
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
node_modules
tests/*.json

package-lock.json

# editor and IDE remnants
*~
.idea/
5 changes: 5 additions & 0 deletions .huskyrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"hooks": {
"pre-commit": "lint-staged"
}
}
3 changes: 3 additions & 0 deletions .lintstagedrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"src/**/*.{js,jsx,json}": ["eslint --fix", "git add"]
}
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
tests/tests.json
src
play.html
bower.json

6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "es5",
"semi": true,
"singleQuote": true,
"bracketSpacing": true
}
31 changes: 20 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,33 @@ The same format can also be executed in PHP by the library [json-logic-php](http

## Installation

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

```bash
bower install --save json-logic-js
npm install @axa-ch/json-logic-js --save
```

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

```bash
npm install json-logic-js
```
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.

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

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.
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:

```bash
curl -O https://raw.githubusercontent.com/jwadhams/json-logic-js/master/logic.js
```js
import createJsonLogic from './createJsonLogic';

// pick just what you need, or create your own
import { equal } from './operations';
import { and, or } from './visitors';

const jsonLogic = createJsonLogic({ equal }, { and, or });

export default jsonLogic;
```

## Examples
Expand Down Expand Up @@ -122,7 +131,7 @@ jsonLogic.apply(false, i_wasnt_even_supposed_to_be_here);

## Compatibility

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

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).

Expand Down
26 changes: 0 additions & 26 deletions bower.json

This file was deleted.

Loading