Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update README and fix github release #7

Merged
merged 1 commit into from
Oct 27, 2024
Merged
Changes from all commits
Commits
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
28 changes: 17 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# expression-eval

[![Latest NPM release](https://img.shields.io/npm/v/expression-eval.svg)](https://www.npmjs.com/package/expression-eval)
[![Minzipped size](https://badgen.net/bundlephobia/minzip/expression-eval)](https://bundlephobia.com/result?p=expression-eval)
[![License](https://img.shields.io/badge/license-MIT-007ec6.svg)](https://github.com/donmccurdy/expression-eval/blob/master/LICENSE)
[![CI](https://github.com/donmccurdy/expression-eval/workflows/CI/badge.svg?branch=master&event=push)](https://github.com/donmccurdy/expression-eval/actions?query=workflow%3ACI)
[![NPM version][npm-image]][npm-url]
[![NPM download][download-image]][download-url]
[![ci](https://github.com/node-casbin/expression-eval/actions/workflows/ci.yml/badge.svg)](https://github.com/node-casbin/expression-eval/actions/workflows/ci.yml)
[![Coverage Status](https://coveralls.io/repos/github/node-casbin/expression-eval/badge.svg?branch=master)](https://coveralls.io/github/node-casbin/expression-eval?branch=master)
[![Discord](https://img.shields.io/discord/1022748306096537660?logo=discord&label=discord&color=5865F2)](https://discord.gg/S5UjpzGZjN)

[npm-image]: https://img.shields.io/npm/v/@casbin/expression-eval.svg?style=flat-square
[npm-url]: https://npmjs.org/package/@casbin/expression-eval
[download-image]: https://img.shields.io/npm/dm/@casbin/expression-eval.svg?style=flat-square
[download-url]: https://npmjs.org/package/@casbin/expression-eval

JavaScript expression parsing and evaluation.

@@ -14,26 +20,26 @@ Powered by [jsep](https://github.com/soney/jsep).
Install:

```
npm install --save expression-eval
npm install --save @casbin/expression-eval
```

Import:

```js
// ES6
import { parse, eval } from 'expression-eval';
import { parse, eval } from '@casbin/expression-eval';
// CommonJS
const { parse, eval } = require('expression-eval');
const { parse, eval } = require('@casbin/expression-eval');
// UMD / standalone script
const { parse, eval } = window.expressionEval;
const { parse, eval } = window['@casbin/expression-eval'];
```

## API

### Parsing

```javascript
import { parse } from 'expression-eval';
import { parse } from '@casbin/expression-eval';
const ast = parse('1 + foo');
```

@@ -58,7 +64,7 @@ The result of the parse is an AST (abstract syntax tree), like:
### Evaluation

```javascript
import { parse, eval } from 'expression-eval';
import { parse, eval } from '@casbin/expression-eval';
const ast = parse('a + b / c'); // abstract syntax tree (AST)
const value = eval(ast, {a: 2, b: 2, c: 5}); // 2.4
```
@@ -68,7 +74,7 @@ Alternatively, use `evalAsync` for asynchronous evaluation.
### Compilation

```javascript
import { compile } from 'expression-eval';
import { compile } from '@casbin/expression-eval';
const fn = compile('foo.bar + 10');
fn({foo: {bar: 'baz'}}); // 'baz10'
```
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -15,8 +15,8 @@
"dev": "microbundle watch",
"build": "microbundle",
"test": "jest",
"preversion": "npm run build && npm test",
"postversion": "git push && git push --tags && npm publish",
"prepublish": "yarn lint && yarn build",
"release": "standard-version",
"typecheck": "tsc --noEmit",
"lint": "eslint . --ext .ts",
"coverage": "jest --coverage"

Unchanged files with check annotations Beta

}
// Added functions to inject Custom Binary Operators (and override existing ones)
function addBinaryOp(operator: string, precedence_or_fn: number | binaryCallback, _function: binaryCallback): void {

Check warning on line 273 in index.ts

GitHub Actions / test (^16)

This line has a length of 116. Maximum allowed is 100

Check warning on line 273 in index.ts

GitHub Actions / test (^16)

This line has a length of 116. Maximum allowed is 100

Check warning on line 273 in index.ts

GitHub Actions / test (^18)

This line has a length of 116. Maximum allowed is 100

Check warning on line 273 in index.ts

GitHub Actions / test (^18)

This line has a length of 116. Maximum allowed is 100

Check warning on line 273 in index.ts

GitHub Actions / test (^20)

This line has a length of 116. Maximum allowed is 100

Check warning on line 273 in index.ts

GitHub Actions / test (^20)

This line has a length of 116. Maximum allowed is 100
if (_function) {
jsep.addBinaryOp(operator, precedence_or_fn as number);
binops[operator] = _function;