subscript 7.4.3 → 7.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -41
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
_Subscript_ is expression evaluator / microlanguage with [common syntax](https://en.wikipedia.org/wiki/Comparison_of_programming_languages_(syntax)) (JavaScript, Java, C, C++, Rust, Go, Python, Kotlin etc).<br/>
|
|
4
4
|
|
|
5
|
-
* Tiny size <sub><a href="https://bundlephobia.com/package/subscript
|
|
5
|
+
* Tiny size <sub><a href="https://bundlephobia.com/package/subscript"><img alt="npm bundle size" src="https://img.shields.io/bundlephobia/minzip/subscript/latest?color=brightgreen&label=gzip"/></a></sub>
|
|
6
6
|
* :rocket: Fast [performance](#performance)
|
|
7
7
|
* Configurable & extensible
|
|
8
8
|
* Trivial to use
|
|
9
9
|
|
|
10
10
|
```js
|
|
11
|
-
import
|
|
11
|
+
import subscript, { parse, compile } from './subscript.js'
|
|
12
12
|
|
|
13
13
|
// create expression evaluator
|
|
14
|
-
let fn =
|
|
14
|
+
let fn = subscript('a.b + c(d - 1)')
|
|
15
15
|
fn({ a: { b:1 }, c: x => x * 2, d: 3 }) // 5
|
|
16
16
|
|
|
17
17
|
// or
|
|
@@ -33,12 +33,13 @@ _Subscript_ is designed to be useful for:
|
|
|
33
33
|
* configurable subsets of languages (eg. [justin](#justin))
|
|
34
34
|
* pluggable/mock language features (eg. pipe operator)
|
|
35
35
|
* sandboxes, playgrounds, safe eval
|
|
36
|
-
* custom DSL
|
|
36
|
+
* custom DSL (see [lino](https://github.com/dy/lino)) <!-- uneural -->
|
|
37
|
+
* preprocessors (see [prepr](https://github.com/dy/prepr))
|
|
37
38
|
|
|
38
|
-
_Subscript_ has [
|
|
39
|
+
_Subscript_ has [3.5kb](https://npmfs.com/package/subscript/7.4.3/subscript.min.js) footprint, compared to [11.4kb](https://npmfs.com/package/jsep/1.2.0/dist/jsep.min.js) _jsep_ + [4.5kb](https://npmfs.com/package/expression-eval/5.0.0/dist/expression-eval.module.js) _expression-eval_, with better test coverage and better performance.
|
|
39
40
|
|
|
40
41
|
|
|
41
|
-
## Operators
|
|
42
|
+
## Operators / literals
|
|
42
43
|
|
|
43
44
|
<small>↑ precedence order</small>
|
|
44
45
|
|
|
@@ -57,12 +58,38 @@ _Subscript_ has [2.8kb](https://npmfs.com/package/subscript/7.0.0/subscript.min.
|
|
|
57
58
|
* `a && b`
|
|
58
59
|
* `a || b`
|
|
59
60
|
* `a , b`
|
|
60
|
-
|
|
61
|
-
## Literals
|
|
62
|
-
|
|
63
61
|
* `"abc"` strings
|
|
64
62
|
* `1.2e+3` numbers
|
|
65
63
|
|
|
64
|
+
## Justin
|
|
65
|
+
|
|
66
|
+
_Justin_ is minimal JS subset − JSON with JS expressions (see original [thread](https://github.com/endojs/Jessie/issues/66)).<br/>
|
|
67
|
+
|
|
68
|
+
It extends _subscript_ with:
|
|
69
|
+
|
|
70
|
+
+ `===`, `!==` operators
|
|
71
|
+
+ `**` exponentiation operator (right-assoc)
|
|
72
|
+
+ `~` bit inversion operator
|
|
73
|
+
+ `'` strings
|
|
74
|
+
+ `?:` ternary operator
|
|
75
|
+
+ `?.` optional chain operator
|
|
76
|
+
+ `??` nullish coalesce operator
|
|
77
|
+
+ `[...]` Array literal
|
|
78
|
+
+ `{...}` Object literal
|
|
79
|
+
+ `in` binary
|
|
80
|
+
+ `;` expression separator
|
|
81
|
+
+ `//`, `/* */` comments
|
|
82
|
+
+ `true`, `false`, `null`, `undefined` literals
|
|
83
|
+
<!-- + `...x` unary operator -->
|
|
84
|
+
<!-- + strings interpolation -->
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
import jstin from 'subscript/justin.js'
|
|
88
|
+
|
|
89
|
+
let xy = jstin('{ x: 1, "y": 2+2 }["x"]')
|
|
90
|
+
xy() // 1
|
|
91
|
+
```
|
|
92
|
+
|
|
66
93
|
## Extending
|
|
67
94
|
|
|
68
95
|
Operators/tokens can be extended via:
|
|
@@ -99,11 +126,11 @@ Subscript exposes separate `./parse.js` and `./compile.js` entries. Parser build
|
|
|
99
126
|
|
|
100
127
|
AST has simplified lispy calltree structure (inspired by [frisk](https://ghub.io/frisk) / [nisp](https://github.com/ysmood/nisp)), opposed to [ESTree](https://github.com/estree/estree):
|
|
101
128
|
|
|
102
|
-
*
|
|
129
|
+
* not limited to particular language (JS), can be compiled to different targets;
|
|
103
130
|
* reflects execution sequence, rather than code layout;
|
|
104
|
-
* has minimal possible overhead, directly maps to operators;
|
|
131
|
+
* has minimal possible overhead (object wrappers, named properties), directly maps to operators;
|
|
105
132
|
* simplifies manual evaluation and debugging;
|
|
106
|
-
* has conventional form and one-
|
|
133
|
+
* has conventional form and one-line docs:
|
|
107
134
|
|
|
108
135
|
```js
|
|
109
136
|
import { compile } from 'subscript.js'
|
|
@@ -113,35 +140,6 @@ const fn = compile(['+', ['*', 'min', ['',60]], ['','sec']])
|
|
|
113
140
|
fn({min: 5}) // min*60 + "sec" == "300sec"
|
|
114
141
|
```
|
|
115
142
|
|
|
116
|
-
## Justin
|
|
117
|
-
|
|
118
|
-
_Justin_ is minimal JS subset − JSON with JS expressions (see original [thread](https://github.com/endojs/Jessie/issues/66)).<br/>
|
|
119
|
-
|
|
120
|
-
It extends _subscript_ with:
|
|
121
|
-
|
|
122
|
-
+ `===`, `!==` operators
|
|
123
|
-
+ `**` exponentiation operator (right-assoc)
|
|
124
|
-
+ `~` bit inversion operator
|
|
125
|
-
+ `'` strings
|
|
126
|
-
+ `?:` ternary operator
|
|
127
|
-
+ `?.` optional chain operator
|
|
128
|
-
+ `??` nullish coalesce operator
|
|
129
|
-
+ `[...]` Array literal
|
|
130
|
-
+ `{...}` Object literal
|
|
131
|
-
+ `in` binary
|
|
132
|
-
+ `;` expression separator
|
|
133
|
-
+ `//`, `/* */` comments
|
|
134
|
-
+ `true`, `false`, `null`, `undefined` literals
|
|
135
|
-
<!-- + `...x` unary operator -->
|
|
136
|
-
<!-- + strings interpolation -->
|
|
137
|
-
|
|
138
|
-
```js
|
|
139
|
-
import jstin from 'subscript/justin.js'
|
|
140
|
-
|
|
141
|
-
let xy = jstin('{ x: 1, "y": 2+2 }["x"]')
|
|
142
|
-
xy() // 1
|
|
143
|
-
```
|
|
144
|
-
|
|
145
143
|
<!--
|
|
146
144
|
## Ideas
|
|
147
145
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "subscript",
|
|
3
|
-
"version": "7.4.
|
|
4
|
-
"description": "Fast and tiny expression evaluator with
|
|
3
|
+
"version": "7.4.4",
|
|
4
|
+
"description": "Fast and tiny expression evaluator with minimal syntax.",
|
|
5
5
|
"main": "subscript.js",
|
|
6
6
|
"module": "subscript.js",
|
|
7
7
|
"browser": "subscript.js",
|