Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@djthoms/simple-math-ast

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@djthoms/simple-math-ast - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

40

package.json
{
"name": "@djthoms/simple-math-ast",
"version": "1.0.0",
"version": "1.1.0",
"description": "Simple Math AST",

@@ -16,3 +16,3 @@ "keywords": [

"type": "git",
"url": "https://github.com/atomicpages/simple-math-ast"
"url": "git+https://github.com/atomicpages/simple-math-ast.git"
},

@@ -34,2 +34,7 @@ "license": "MIT",

"require": "./dist/cjs/tokenize/index.js"
},
"./parser": {
"types": "./dist/types/parse/parse.d.ts",
"import": "./dist/esm/parse/parse.js",
"require": "./dist/cjs/parse/parse.js"
}

@@ -43,2 +48,17 @@ },

],
"scripts": {
"prebuild": "rm -rf dist",
"build": "npm-run-all -p build:*",
"lint": "eslint --ext .ts,.js src",
"benchmark": "vitest bench --run",
"test": "vitest run",
"test:watch": "vitest",
"build:cjs": "esbuild --target=es2020 --outdir=dist/cjs --sourcemap --format=cjs $(./scripts/fd.sh)",
"build:esm": "esbuild --target=es2020 --outdir=dist/esm --sourcemap --format=esm $(./scripts/fd.sh)",
"build:types": "tsc -p tsconfig.build.json",
"check-types": "tsc --noEmit --emitDeclarationOnly false",
"prepare": "husky install",
"create-docs": "typedoc $(./scripts/fd.sh) --out docs",
"pre-push": "npm-run-all -p check-types lint test"
},
"devDependencies": {

@@ -60,2 +80,3 @@ "@commitlint/cli": "^17.7.1",

"ts-toolbelt": "^9.6.0",
"typedoc": "^0.25.1",
"typescript": "^5.2.2",

@@ -66,16 +87,3 @@ "vitest": "^0.34.4"

"ramda": "^0.29.0"
},
"scripts": {
"prebuild": "rm -rf dist",
"build": "npm-run-all -p build:*",
"lint": "eslint --ext .ts,.js src",
"benchmark": "vitest bench --run",
"test": "vitest run",
"test:watch": "vitest",
"build:cjs": "esbuild --target=es2020 --outdir=dist/cjs --sourcemap --format=cjs $(./scripts/fd.sh)",
"build:esm": "esbuild --target=es2020 --outdir=dist/esm --sourcemap --format=esm $(./scripts/fd.sh)",
"build:types": "tsc -p tsconfig.build.json",
"check-types": "tsc --noEmit --emitDeclarationOnly false",
"pre-push": "npm-run-all -p check-types lint test"
}
}
}

70

README.md

@@ -36,3 +36,2 @@ # simple-math-ast

const tree = build("2.5 * x + (sin(pi / 2) / cosx) ^ 3 - 4 * 2");
console.log(tree);

@@ -56,3 +55,49 @@

we can convert the tree to JSON as well:
```ts
const tree = build("2.5 * x + (sin(pi / 2) / cosx) ^ 3 - 4 * 2");
console.log(tree.toJSON());
/**
{
value: '-',
type: 'OPERATOR',
args: 2,
precedence: 1,
left: {
value: '+',
type: 'OPERATOR',
args: 2,
precedence: 1,
left: {
value: '*',
type: 'OPERATOR',
args: 2,
precedence: 2,
left: [Object],
right: [Object]
},
right: {
value: '^',
type: 'OPERATOR',
args: 2,
precedence: 3,
left: [Object],
right: [Object]
}
},
right: {
value: '*',
type: 'OPERATOR',
args: 2,
precedence: 2,
left: { value: '4', type: 'NUMBER', left: undefined, right: undefined },
right: { value: '2', type: 'NUMBER', left: undefined, right: undefined }
}
}
*/
```
```ts
import { tokenize } from "@djthoms/simple-math-ast/tokenize";

@@ -98,2 +143,25 @@

## Benchmarks
Benchmarks are powered by tinybench and vitest. Below are the benchmarks for the
tokenizer and parser. See
[parser benchmarks](./src/parse/__tests__/parse.bench.ts) and the
[tokenizer benchmarks](./src/tokenize/__tests__/tokenize.bench.ts) to see which
expressions are tested.
```sh
✓ src/tokenize/__tests__/tokenize.bench.ts (3) 1820ms
✓ tokenize benchmarks (3) 1817ms
name hz min max mean p75 p99 p995 p999 rme samples
· simple tokenize benchmarks 20,924.02 0.0427 0.2670 0.0478 0.0464 0.1438 0.1691 0.2065 ±0.59% 10464 fastest
· complex tokenize benchmarks 12,000.27 0.0751 0.2771 0.0833 0.0811 0.1883 0.2082 0.2478 ±0.54% 6001
· very complex tokenize benchmarks 6,033.61 0.1487 0.7075 0.1657 0.1616 0.3765 0.4024 0.4308 ±0.77% 3017 slowest
✓ src/parse/__tests__/parse.bench.ts (3) 1819ms
✓ parse benchmarks (3) 1817ms
name hz min max mean p75 p99 p995 p999 rme samples
· simple parse benchmarks 19,903.71 0.0450 0.2519 0.0502 0.0488 0.1416 0.1648 0.2069 ±0.56% 9952 fastest
· complex parse benchmarks 11,330.63 0.0796 0.2845 0.0883 0.0860 0.1935 0.2122 0.2535 ±0.52% 5666
· very complex parse benchmarks 5,569.83 0.1586 2.7357 0.1795 0.1725 0.3872 0.4268 0.6210 ±1.32% 2785 slowest
```
## Credits & Acknowledgements

@@ -100,0 +168,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc