expressionish 0.1.1 → 0.1.3

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 ADDED
@@ -0,0 +1,85 @@
1
+ # Expressinish
2
+ An expression-parsing middle ground library between find-and-replace and full js access
3
+
4
+ ### Installing
5
+ ```
6
+ npm install --save expressionish
7
+ ```
8
+
9
+ ### API
10
+ You can find the full API documentation at \[TODO: add link\]
11
+
12
+ ```js
13
+ import { evaluate } from 'expressionish';
14
+
15
+ const variables = new Map();
16
+ variables.set('sum', {
17
+ evaluate: async (meta, ...args) => {
18
+ return args.reduce((prev, curr) => prev + Number(curr), 0)
19
+ }
20
+ });
21
+
22
+ await evaluate({
23
+ variables,
24
+ expression: '\$sum[1,2,3]: $sum[1,2,3]'
25
+ }) // "$sum[1,2,3]: 6'
26
+ ```
27
+
28
+ ### Syntax
29
+ You can find the full Syntax documentation at \[TODO: add link\]
30
+
31
+ #### Text
32
+ Any text that is not seen as having significance is treated as plain text.
33
+
34
+ Concatenation is done simply by mixing insignificant and significant sequences: `v$var` is evaluated to "v" followed by result of evaluating `$var`
35
+
36
+
37
+ #### Character escapes
38
+ Character escapes treat characters that may have potential significance as literl text instead.
39
+
40
+ - `\\` - backslash
41
+ - `\"` - quote
42
+ - `\$` - dollar sign
43
+ - `\[` - opening bracket
44
+ - `\,` - comma
45
+ - `\]` - closing brackets
46
+ - `\r` - carriage return
47
+ - `\n` - line feed
48
+ - `\t` - tab
49
+
50
+ #### Double-Quoted Text
51
+ Text contained with in double quotes is treated as plain-text with the exception of character-escapes(of which get evaluated)
52
+
53
+ #### Double Backtick Text
54
+ Text contained within double backtick's is treated as plain-text with the exception of Variables
55
+
56
+ ### Variables & Lookups
57
+ Variables are the power behind expressions. They can take no arguments or a slew of them! An argument can even be an expression of itself, containing variables and the like!
58
+
59
+ Variables take the format of:
60
+ ```
61
+ "$" + [<lookup_prefix>] + <name> + [ "[" + <arg> + ["," + <arg>]... + "]" ]
62
+ ```
63
+
64
+ Examples:
65
+ ```
66
+ $name - variable
67
+ $name[1] - variable with one argument
68
+ $name[1,2,3] - variable with multiple arguments
69
+
70
+ $&name - variable lookup
71
+ $&name[1] - variable lookup with one argument
72
+ $&name[1,2,3] - variable lookup with multiple arguments
73
+ ```
74
+
75
+ When it comes to arguments, leading/trailing whitespace is insignificant
76
+ ```
77
+ These are all the same
78
+ $name[1]
79
+ $name[ 1]
80
+ $name[ 1 ]
81
+ $name[
82
+ 1
83
+ ]
84
+ ```
85
+