affinirum 1.3.1 → 1.4.0
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 +156 -126
- package/dst/Affinirum.d.ts +1 -1
- package/dst/Affinirum.js +43 -47
- package/dst/ParserState.js +2 -2
- package/dst/atom/ArrayAtom.d.ts +3 -3
- package/dst/atom/ArrayAtom.js +14 -13
- package/dst/atom/FunctionAtom.d.ts +1 -1
- package/dst/atom/FunctionAtom.js +10 -8
- package/dst/atom/ObjectAtom.d.ts +3 -3
- package/dst/atom/ObjectAtom.js +14 -18
- package/dst/atom/PrimitiveAtom.js +3 -3
- package/dst/cjs/Affinirum.js +43 -47
- package/dst/cjs/ParserState.js +2 -2
- package/dst/cjs/atom/ArrayAtom.js +14 -13
- package/dst/cjs/atom/FunctionAtom.js +10 -8
- package/dst/cjs/atom/ObjectAtom.js +14 -18
- package/dst/cjs/atom/PrimitiveAtom.js +3 -3
- package/dst/cjs/node/ArrayNode.js +7 -3
- package/dst/cjs/node/{FunctionNode.js → CallNode.js} +5 -4
- package/dst/cjs/node/ObjectNode.js +4 -2
- package/dst/node/ArrayNode.d.ts +2 -1
- package/dst/node/ArrayNode.js +7 -3
- package/dst/node/{FunctionNode.d.ts → CallNode.d.ts} +1 -1
- package/dst/node/{FunctionNode.js → CallNode.js} +3 -2
- package/dst/node/ObjectNode.d.ts +1 -1
- package/dst/node/ObjectNode.js +4 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -76,24 +76,28 @@ Whitespace characters are ignored.
|
|
|
76
76
|
- **array** for ordered sequences of values
|
|
77
77
|
- **object** for collections of named values
|
|
78
78
|
- **function** for built-in, injected or script-defined subroutines
|
|
79
|
-
|
|
80
|
-
Type
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
Unknown or variant type is declared as **??**.
|
|
79
|
+
- **??** for unknown or variant type
|
|
80
|
+
- Type grouping: **(...)**
|
|
81
|
+
- Type union: **|**
|
|
82
|
+
- Type optionality modifier: **?**
|
|
84
83
|
|
|
85
84
|
### Definitions
|
|
86
|
-
- Value grouping: **(...)**
|
|
87
85
|
- Unit grouping: **{...}**
|
|
88
|
-
-
|
|
86
|
+
- Unit separator: **;**
|
|
87
|
+
- Value grouping: **(...)**
|
|
88
|
+
- Value separator: **,**
|
|
89
89
|
- Array element at numeric index, or object property by string key: **[]**
|
|
90
90
|
- Object property by string key or method function call: **.**
|
|
91
91
|
- Array definiton: **[item1, ...]**
|
|
92
92
|
- Object definition: **[propery1-key: property1-value, ...]**
|
|
93
|
-
- Subroutine definition: **~
|
|
93
|
+
- Subroutine definition: **~(argument1-name: argument1-type, ...):return-type {...}**
|
|
94
94
|
- Conditional switch definition, returns first or second value if prefix is true or false: **if condition {value1} else {value2}**,
|
|
95
|
-
and if **else** clause is ommited second value deemed null
|
|
95
|
+
and if **else** clause is ommited second value deemed *null*
|
|
96
96
|
- Loop definition, iteratively evaluates suffix while prefix is true, returns last evaluated value: **while condition {...}**
|
|
97
|
+
- Stop iteration: **stop**
|
|
98
|
+
- Proceed to next iteration: **next**
|
|
99
|
+
- Function return operator: **~>value**
|
|
100
|
+
- Execution exit operator: **=>value**
|
|
97
101
|
|
|
98
102
|
### Operators
|
|
99
103
|
- Boolean negation (Logical NOT): **!**
|
|
@@ -112,8 +116,8 @@ Unknown or variant type is declared as **??**.
|
|
|
112
116
|
- Arithmetic division: **/**
|
|
113
117
|
- Arithmetic remainder: **%**
|
|
114
118
|
- Exponentiation operator: **^**
|
|
115
|
-
-
|
|
116
|
-
-
|
|
119
|
+
- Property access operator: **.**
|
|
120
|
+
- Property existance operator: **?**
|
|
117
121
|
- Assignment: **=**
|
|
118
122
|
- Boolean disjunction (Logical OR) assignment: **|=**
|
|
119
123
|
- Boolean conjunction (Logical AND) assignment: **&=**
|
|
@@ -123,166 +127,192 @@ Unknown or variant type is declared as **??**.
|
|
|
123
127
|
- Arithmetic division assignment: **/=**
|
|
124
128
|
- Arithmetic remainder assignment: **%=**
|
|
125
129
|
|
|
126
|
-
###
|
|
130
|
+
### Native Global Functions
|
|
127
131
|
|
|
128
132
|
#### Boolean
|
|
129
|
-
- **
|
|
130
|
-
- **
|
|
131
|
-
- **
|
|
132
|
-
- **
|
|
133
|
-
- **
|
|
133
|
+
- **Boolean.Or(values:...array):boolean** — Boolean disjunction
|
|
134
|
+
- **Boolean.And(values: ...array):boolean** — Boolean conjunction
|
|
135
|
+
- **Boolean.Not(value: boolean):boolean** — Boolean negation
|
|
136
|
+
- **Boolean.Decode(value: buffer, offset: integer?):boolean?** — Decode boolean from buffer
|
|
137
|
+
- **Boolean.Parse():boolean?** — Parse boolean from string
|
|
134
138
|
|
|
135
139
|
#### Timestamp
|
|
136
|
-
- **
|
|
137
|
-
- **
|
|
138
|
-
- **
|
|
139
|
-
- **
|
|
140
|
+
- **Timestamp.Now():timestamp** — Current date and time
|
|
141
|
+
- **Timestamp.Epoch(value: float | integer, epoch: timestamp?):timestamp** — Create timestamp from milliseconds
|
|
142
|
+
- **Timestamp.Decode(value: buffer, offset: integer?):timestamp?** — Decode timestamp from buffer
|
|
143
|
+
- **Timestamp.Parse(value: string):timestamp?** — Parse string to timestamp
|
|
140
144
|
|
|
141
145
|
#### Float
|
|
142
146
|
- **Float.NAN** — Not-a-number
|
|
143
147
|
- **Float.PositiveInfinity** — Positive infinity
|
|
144
148
|
- **Float.NegativeInfinity** — Negative infinity
|
|
145
149
|
- **Float.Epsilon** — Smallest positive float
|
|
146
|
-
- **
|
|
147
|
-
- **
|
|
148
|
-
- **
|
|
149
|
-
- **
|
|
150
|
-
- **
|
|
151
|
-
- **
|
|
152
|
-
- **
|
|
153
|
-
- **
|
|
154
|
-
- **
|
|
155
|
-
- **
|
|
156
|
-
- **
|
|
157
|
-
- **
|
|
158
|
-
- **
|
|
150
|
+
- **Float.Sum(values: ...array):float** — Numeric sum
|
|
151
|
+
- **Float.Min(values: ...array):float** — Numeric minimum
|
|
152
|
+
- **Float.Max(values: ...array):float** — Numeric maximum
|
|
153
|
+
- **Float.Exponent():float** — Exponent
|
|
154
|
+
- **Float.Logarithm():float** — Logarithm
|
|
155
|
+
- **Float.Abs():float** — Absolute value
|
|
156
|
+
- **Float.Ceil():float** — Ceil
|
|
157
|
+
- **Float.Floor():float** — Floor
|
|
158
|
+
- **Float.Round():float** — Rounded value
|
|
159
|
+
- **Float.Truncate():float** — Truncated value
|
|
160
|
+
- **Float.Random(exclusiveTo: float):float** — Random float up to value
|
|
161
|
+
- **Float.Decode(value: buffer, encoding: string, offset: integer?):float?** — Decode float from buffer
|
|
162
|
+
- **Float.Parse(value: string):float?** — Parse float from string
|
|
159
163
|
|
|
160
164
|
#### Integer
|
|
161
|
-
- **
|
|
162
|
-
- **
|
|
163
|
-
- **
|
|
164
|
-
- **
|
|
165
|
-
- **
|
|
166
|
-
- **
|
|
165
|
+
- **Integer.Sum(values: ...array):integer** — Numeric sum
|
|
166
|
+
- **Integer.Min(values: ...array):integer** — Numeric minimum
|
|
167
|
+
- **Integer.Max(values: ...array):integer** — Numeric maximum
|
|
168
|
+
- **Integer.Random(exclusiveTo: integer):integer** — Random integer up to value
|
|
169
|
+
- **Integer.Decode(value: buffer, encoding: string, offset: integer?):integer?** — Decode integer from buffer
|
|
170
|
+
- **Integer.Parse(value: string):integer?** — Parse integer from string
|
|
167
171
|
|
|
168
172
|
#### String
|
|
169
|
-
- **
|
|
170
|
-
- **
|
|
173
|
+
- **String.Random(length: integer):string** — Random alphanumeric string
|
|
174
|
+
- **String.Decode(value: buffer, encoding: string?, offset: integer?, length: integer?):string?** — Decode buffer to string
|
|
171
175
|
|
|
172
176
|
#### Buffer
|
|
173
|
-
- **
|
|
174
|
-
- **
|
|
177
|
+
- **Buffer.Random(length: integer):buffer** — Buffer of given length filled with random bytes
|
|
178
|
+
- **Buffer.Parse(value: string):buffer?** — Parse buffer from hexadecimal string
|
|
175
179
|
|
|
176
180
|
#### Array
|
|
177
|
-
- **
|
|
178
|
-
- **
|
|
179
|
-
- **
|
|
180
|
-
- **
|
|
181
|
-
- **
|
|
181
|
+
- **Array.Join(values: ...array):array** — Join arrays of any depths into a single array
|
|
182
|
+
- **Array.Range(inclusiveFrom: integer, exclusiveTo: integer):array** — New array filled with integers in range
|
|
183
|
+
- **Array.Unique():array** — Array of unique values
|
|
184
|
+
- **Array.Intersection(a1: array, a2: array):array** — Common values from two arrays
|
|
185
|
+
- **Array.Difference(a1: array, a2: array):array** — Symmetrical difference between arrays
|
|
182
186
|
|
|
183
187
|
#### Object
|
|
184
|
-
- **
|
|
188
|
+
- **Object.Merge(values: ...array):object** — Merge multiple objects
|
|
185
189
|
|
|
186
190
|
#### AN
|
|
187
|
-
- **
|
|
191
|
+
- **AN.Format(value: ??, whitespace: string?):string** — Format string as AN
|
|
188
192
|
|
|
189
193
|
#### JSON
|
|
190
|
-
- **
|
|
191
|
-
- **void | boolean | float | string | array | object
|
|
194
|
+
- **JSON.Format(value: (void | boolean | float | string | array | object), whitespace: string?):string** — Format as JSON string
|
|
195
|
+
- **JSON.Parse(value: string):(void | boolean | float | string | array | object)** — Parse JSON-formatted string
|
|
192
196
|
|
|
193
197
|
|
|
194
|
-
###
|
|
198
|
+
### Native Method Functions
|
|
195
199
|
|
|
196
200
|
#### General Functions
|
|
197
|
-
-
|
|
198
|
-
-
|
|
199
|
-
-
|
|
200
|
-
- **buffer
|
|
201
|
-
- **
|
|
201
|
+
- **??.Coalesce(otherwise: ??):??** — Null coalescence
|
|
202
|
+
- **??.Equal(value: ??):boolean** — Equals to
|
|
203
|
+
- **??.Unequal(value: ??):boolean** — Not equals to
|
|
204
|
+
- **(boolean | buffer | function).Encode():buffer** — Encode value to buffer
|
|
205
|
+
- **(timestamp | float | integer | string | array | object).Encode(encoding: string?):buffer** — Encode value to buffer
|
|
206
|
+
- **(boolean | string | function).Format():string** — Format value to string
|
|
207
|
+
- **(timestamp | float | integer | buffer | array | object).Format(formatting: string?):string** — Format value to string
|
|
202
208
|
|
|
203
209
|
#### Aggregable Functions
|
|
204
|
-
- **float
|
|
210
|
+
- **float.Add(values: ...array):float** — Add or concatenate values
|
|
211
|
+
- **integer.Add(values: ...array):integer** — Add or concatenate values
|
|
212
|
+
- **buffer.Add(values: ...array):buffer** — Add or concatenate values
|
|
213
|
+
- **string.Add(values: ...array):string** — Add or concatenate values
|
|
214
|
+
- **array.Add(values: ...array):array** — Add or concatenate values
|
|
205
215
|
|
|
206
216
|
#### Array Functions
|
|
207
|
-
-
|
|
208
|
-
-
|
|
209
|
-
- **
|
|
210
|
-
- **
|
|
211
|
-
- **
|
|
212
|
-
- **
|
|
213
|
-
- **array
|
|
214
|
-
- **array
|
|
215
|
-
- **array
|
|
216
|
-
- **array
|
|
217
|
-
-
|
|
218
|
-
- **
|
|
219
|
-
- **array
|
|
220
|
-
- **array
|
|
217
|
+
- **array.First(condition: function):??** — First item satisfying condition
|
|
218
|
+
- **array.Last(condition: function):??** — Last item satisfying condition
|
|
219
|
+
- **array.FirstIndex(condition: function):integer** — First index satisfying condition
|
|
220
|
+
- **array.LastIndex(condition: function):integer** — Last index satisfying condition
|
|
221
|
+
- **array.Every(condition: function):boolean** — All items satisfy condition
|
|
222
|
+
- **array.Any(condition: function):boolean** — Any item satisfies condition
|
|
223
|
+
- **array.Reverse():array** — Reversed array
|
|
224
|
+
- **array.Flatten(depth: integer = 1):array** — Flatten array
|
|
225
|
+
- **array.Derive(transformation: function):array** — Derived array
|
|
226
|
+
- **array.Filter(condition: function):array** — Filtered array
|
|
227
|
+
- **array.Reduce(reducer: function):??** — Reduced value
|
|
228
|
+
- **array.Compose(generator: function):object** — Compose object from array
|
|
229
|
+
- **array.Prepend(items: ...array):array** — Prepend items
|
|
230
|
+
- **array.Append(items: ...array):array** — Append items
|
|
221
231
|
|
|
222
232
|
#### Buffer Functions
|
|
223
|
-
- **buffer
|
|
224
|
-
- **
|
|
233
|
+
- **buffer.Byte(pos: integer):buffer** — Byte at position
|
|
234
|
+
- **Buffer.FormatBuffer(value: buffer):string** — Hexadecimal string from buffer
|
|
225
235
|
|
|
226
236
|
#### Enumerable Functions
|
|
227
|
-
- **buffer
|
|
228
|
-
- **
|
|
229
|
-
- **
|
|
237
|
+
- **buffer.Slice(start: integer?, end: integer?):buffer** — Slice section
|
|
238
|
+
- **string.Slice(start: integer?, end: integer?):string** — Slice section
|
|
239
|
+
- **array.Slice(start: integer?, end: integer?):array** — Slice section
|
|
240
|
+
- **buffer.Splice(start: integer, remove: integer, inject: ...array):buffer** — Splice section
|
|
241
|
+
- **string.Splice(start: integer, remove: integer, inject: ...array):string** — Splice section
|
|
242
|
+
- **array.Splice(start: integer, remove: integer, inject: ...array):array** — Splice section
|
|
243
|
+
- **buffer.Inject(start: integer, inject: ...array):buffer** — Inject section
|
|
244
|
+
- **string.Inject(start: integer, inject: ...array):string** — Inject section
|
|
245
|
+
- **array.Inject(start: integer, inject: ...array):array** — Inject section
|
|
230
246
|
|
|
231
247
|
#### Iterable Functions
|
|
232
|
-
- **
|
|
233
|
-
- **
|
|
234
|
-
-
|
|
235
|
-
-
|
|
248
|
+
- **(buffer | string | array | object).Length():integer** — Get length
|
|
249
|
+
- **buffer.Contains(search: buffer, startPos: integer?):boolean** — Check if buffer contains another buffer
|
|
250
|
+
- **string.Contains(search: string, startPos: integer?, ignoreCaseSpaceEtc: boolean?):boolean** — Check if string contains another string
|
|
251
|
+
- **array.Contains(search: ??, startPos: integer?):boolean** — Check if array contains value
|
|
252
|
+
- **object.Contains(search: ??):boolean** — Check if object contains value
|
|
253
|
+
- **array.At(index: integer):??** — Access item in array by index
|
|
254
|
+
- **object.At(index: string):??** — Access item in object by key
|
|
255
|
+
- **array.Has(index: integer):boolean** — Identify if array has index
|
|
256
|
+
- **object.Has(index: string):boolean** — Identify if object has key
|
|
236
257
|
|
|
237
258
|
#### Number Functions
|
|
238
|
-
- **
|
|
239
|
-
- **
|
|
240
|
-
- **
|
|
241
|
-
- **
|
|
242
|
-
- **float
|
|
243
|
-
- **
|
|
244
|
-
- **float
|
|
245
|
-
- **
|
|
246
|
-
- **float
|
|
247
|
-
- **
|
|
248
|
-
- **float
|
|
249
|
-
- **
|
|
250
|
-
- **float
|
|
251
|
-
- **
|
|
252
|
-
- **
|
|
259
|
+
- **(float | integer).GreaterThan(value):boolean** — Greater than
|
|
260
|
+
- **(float | integer).LessThan(value):boolean** — Less than
|
|
261
|
+
- **(float | integer).GreaterOrEqual(value):boolean** — Greater or equal
|
|
262
|
+
- **(float | integer).LessOrEqual(value):boolean** — Less or equal
|
|
263
|
+
- **float.Subtract(subtrahend):float** — Subtract value
|
|
264
|
+
- **integer.Subtract(subtrahend):integer** — Subtract value
|
|
265
|
+
- **float.Negate():float** — Negate number
|
|
266
|
+
- **integer.Negate():integer** — Negate number
|
|
267
|
+
- **float.Multiply(values: ...array):float** — Multiply values
|
|
268
|
+
- **integer.Multiply(values: ...array):integer** — Multiply values
|
|
269
|
+
- **float.Divide(divisor):float** — Divide value
|
|
270
|
+
- **integer.Divide(divisor):integer** — Divide value
|
|
271
|
+
- **float.Remainder(divisor):float** — Remainder
|
|
272
|
+
- **integer.Remainder(divisor):integer** — Remainder
|
|
273
|
+
- **float.Modulo(divisor):float** — Modulo
|
|
274
|
+
- **integer.Modulo(divisor):integer** — Modulo
|
|
275
|
+
- **float.Power(exponent):float** — Power
|
|
276
|
+
- **integer.Power(exponent):integer** — Power
|
|
277
|
+
- **float.Root(index):float** — Root
|
|
278
|
+
- **integer.Root(index):integer** — Root
|
|
279
|
+
- **float.Cast():integer** — Cast to integer
|
|
280
|
+
- **integer.Cast():float** — Cast to float
|
|
281
|
+
- **integer.CastToFloat():float** — Cast to float
|
|
282
|
+
- **float.CastToInteger():integer** — Cast to integer
|
|
253
283
|
|
|
254
284
|
#### Object Functions
|
|
255
|
-
- **
|
|
256
|
-
- **
|
|
257
|
-
- **
|
|
285
|
+
- **object.Entries():array** — Key-value pairs
|
|
286
|
+
- **object.Keys():array** — Object keys
|
|
287
|
+
- **object.Values():array** — Object values
|
|
258
288
|
|
|
259
289
|
#### String Functions
|
|
260
|
-
- **
|
|
261
|
-
- **
|
|
262
|
-
- **
|
|
263
|
-
- **
|
|
264
|
-
- **string
|
|
265
|
-
- **
|
|
266
|
-
- **string
|
|
267
|
-
- **string
|
|
268
|
-
- **string
|
|
269
|
-
- **string
|
|
270
|
-
- **string
|
|
271
|
-
- **string
|
|
272
|
-
- **
|
|
273
|
-
- **string
|
|
290
|
+
- **string.Like(value: string):boolean** — Alphanumeric equality
|
|
291
|
+
- **string.Unlike(value: string):boolean** — Alphanumeric inequality
|
|
292
|
+
- **string.StartsWith(search: string, startPos: integer?, ignoreCaseSpaceEtc: boolean?):boolean** — Prefix check
|
|
293
|
+
- **string.EndsWith(search: string, endPos: integer?, ignoreCaseSpaceEtc: boolean?):boolean** — Suffix check
|
|
294
|
+
- **string.Char(pos: integer):string** — Character at position
|
|
295
|
+
- **string.CharCode(pos: integer):integer** — Character code
|
|
296
|
+
- **string.Alphanum():string** — Alphanumeric digest
|
|
297
|
+
- **string.Trim():string** — Trim whitespace
|
|
298
|
+
- **string.TrimStart():string** — Trim leading whitespace
|
|
299
|
+
- **string.TrimEnd():string** — Trim trailing whitespace
|
|
300
|
+
- **string.LowerCase():string** — To lowercase
|
|
301
|
+
- **string.UpperCase():string** — To uppercase
|
|
302
|
+
- **string.Split(separator: string = ' '):array** — Split into array
|
|
303
|
+
- **string.ReplaceWith(replacement: string, search: ...array):string** — Replace all instances of substring with another
|
|
274
304
|
|
|
275
305
|
#### Timestamp Functions
|
|
276
|
-
- **
|
|
277
|
-
- **
|
|
278
|
-
- **
|
|
279
|
-
- **
|
|
280
|
-
- **
|
|
281
|
-
- **
|
|
282
|
-
- **
|
|
283
|
-
- **
|
|
284
|
-
- **
|
|
285
|
-
- **
|
|
306
|
+
- **timestamp.Year(utc: boolean?):integer** — Get year
|
|
307
|
+
- **timestamp.Month(utc: boolean?):integer** — Get month
|
|
308
|
+
- **timestamp.MonthIndex(utc: boolean?):integer** — Month index
|
|
309
|
+
- **timestamp.WeekdayIndex(utc: boolean?):integer** — Weekday index
|
|
310
|
+
- **timestamp.Day(utc: boolean?):integer** — Day of month
|
|
311
|
+
- **timestamp.Hour(utc: boolean?):integer** — Hour
|
|
312
|
+
- **timestamp.Minute(utc: boolean?):integer** — Minute
|
|
313
|
+
- **timestamp.Second(utc: boolean?):integer** — Second
|
|
314
|
+
- **timestamp.Millisecond(utc: boolean?):integer** — Millisecond
|
|
315
|
+
- **timestamp.EpochTime(epoch: timestamp?):integer** — Milliseconds since epoch or 1970-01-01 00:00:00 UTC
|
|
286
316
|
|
|
287
317
|
## Reference
|
|
288
318
|
|
|
@@ -306,7 +336,7 @@ const objExpr = new Affinirum( '[`prop1`:a,`prop2`:`abc`].prop1+10' );
|
|
|
306
336
|
const oValue = objExpr.evaluate( { a: 50 } ); // 60
|
|
307
337
|
...
|
|
308
338
|
const iteratorExpr = new Affinirum(
|
|
309
|
-
'Float.Sum(arr1.Derive(
|
|
339
|
+
'Float.Sum(arr1.Derive(~(a:float):float{a*2}).Filter(~(a:float):boolean{a>3}))'
|
|
310
340
|
);
|
|
311
341
|
const iValue = iteratorExpr.evaluate( { arr1: [ 1, 2, 3 ] } ); // 10
|
|
312
342
|
...
|
package/dst/Affinirum.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export declare class Affinirum {
|
|
|
13
13
|
protected readonly _script: string;
|
|
14
14
|
protected readonly _strict: boolean;
|
|
15
15
|
protected readonly _root: Node;
|
|
16
|
-
protected readonly
|
|
16
|
+
protected readonly _varframes: Map<string, ParserFrame>;
|
|
17
17
|
protected readonly _variables: Map<string, Variable>;
|
|
18
18
|
protected readonly _constants: Map<string, Record<string, Constant>>;
|
|
19
19
|
protected readonly _functions: Map<string, Constant>;
|