affinirum 1.2.7 → 1.3.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 CHANGED
@@ -58,6 +58,7 @@ A function is a callable code unit that produces a value.
58
58
  The set of built-in functions can be extended through configuration entries.
59
59
  Additionally, subroutines (functions defined in code) can be created.
60
60
 
61
+ ### Variables
61
62
  Valid variable and function names must start with a letter, number sign (**\#**), dollar sign (**\$**), or underscore (**\_**)
62
63
  and can be followed by any combination of alphanumeric characters, number signs, dollar signs, or underscores,
63
64
  like *x*, *\_a1$*, *abc25*.
@@ -77,7 +78,7 @@ Whitespace characters are ignored.
77
78
  - **function** for built-in, injected or script-defined subroutines
78
79
 
79
80
  Type modifier **?** can be used to make any type optional (nullable).
80
- <br>Examples: *float? optNumVar*, *array? optArrayVar*
81
+ <br>Examples: *float?*, *array?*
81
82
 
82
83
  Unknown or variant type is declared as **??**.
83
84
 
@@ -125,11 +126,11 @@ Unknown or variant type is declared as **??**.
125
126
  ### Predefined Constants
126
127
 
127
128
  #### Boolean
128
- - **boolean Boolean.Or(values:array...)** — Boolean disjunction
129
- - **boolean Boolean.And(values: array...)** — Boolean conjunction
129
+ - **boolean Boolean.Or(values:...array)** — Boolean disjunction
130
+ - **boolean Boolean.And(values: ...array)** — Boolean conjunction
130
131
  - **boolean Boolean.Not(value: boolean)** — Boolean negation
131
132
  - **boolean? Boolean.Decode(value: buffer, offset: integer?)** — Decode boolean from buffer
132
- - **boolean? Boolean.ParseBoolean()** — Parse boolean from string
133
+ - **boolean? Boolean.Parse()** — Parse boolean from string
133
134
 
134
135
  #### Timestamp
135
136
  - **timestamp Timestamp.Now()** — Current date and time
@@ -142,9 +143,9 @@ Unknown or variant type is declared as **??**.
142
143
  - **Float.PositiveInfinity** — Positive infinity
143
144
  - **Float.NegativeInfinity** — Negative infinity
144
145
  - **Float.Epsilon** — Smallest positive float
145
- - **float Float.Sum(values: array...)** — Numeric sum
146
- - **float Float.Min(values: array...)** — Numeric minimum
147
- - **float Float.Max(values: array...)** — Numeric maximum
146
+ - **float Float.Sum(values: ...array)** — Numeric sum
147
+ - **float Float.Min(values: ...array)** — Numeric minimum
148
+ - **float Float.Max(values: ...array)** — Numeric maximum
148
149
  - **float Float.Exponent()** — Exponent
149
150
  - **float Float.Logarithm()** — Logarithm
150
151
  - **float Float.Abs()** — Absolute value
@@ -157,9 +158,9 @@ Unknown or variant type is declared as **??**.
157
158
  - **float? Float.Parse(value: string)** — Parse float from string
158
159
 
159
160
  #### Integer
160
- - **integer Integer.Sum(values: array...)** — Numeric sum
161
- - **integer Integer.Min(values: array...)** — Numeric minimum
162
- - **integer Integer.Max(values: array...)** — Numeric maximum
161
+ - **integer Integer.Sum(values: ...array)** — Numeric sum
162
+ - **integer Integer.Min(values: ...array)** — Numeric minimum
163
+ - **integer Integer.Max(values: ...array)** — Numeric maximum
163
164
  - **integer Integer.Random(exclusiveTo: integer)** — Random integer up to value
164
165
  - **integer? Integer.Decode(value: buffer, encoding: string, offset: integer?)** — Decode integer from buffer
165
166
  - **integer? Integer.Parse(value: string)** — Parse integer from string
@@ -170,17 +171,17 @@ Unknown or variant type is declared as **??**.
170
171
 
171
172
  #### Buffer
172
173
  - **buffer Buffer.Random(length: integer)** — Buffer of given length filled with random bytes
173
- - **buffer? Buffer.ParseBuffer(value: string)** — Parse buffer from hexadecimal string
174
+ - **buffer? Buffer.Parse(value: string)** — Parse buffer from hexadecimal string
174
175
 
175
176
  #### Array
176
- - **array Array.Join(values: array...)** — Join arrays of any depths into a single array
177
+ - **array Array.Join(values: ...array)** — Join arrays of any depths into a single array
177
178
  - **array Array.Range(inclusiveFrom: integer, exclusiveTo: integer)** — New array filled with integers in range
178
179
  - **array Array.Unique()** — Array of unique values
179
180
  - **array Array.Intersection(a1: array, a2: array)** — Common values from two arrays
180
181
  - **array Array.Difference(a1: array, a2: array)** — Symmetrical difference between arrays
181
182
 
182
183
  #### Object
183
- - **object Object.Merge(values: array...)** — Merge multiple objects
184
+ - **object Object.Merge(values: ...array)** — Merge multiple objects
184
185
 
185
186
  #### AN
186
187
  - **string AN.Format(value: ??, whitespace: string?)** — Format string as AN
@@ -200,7 +201,7 @@ Unknown or variant type is declared as **??**.
200
201
  - **string ??.Format(formatting: integer? | string?)** — Format value to string
201
202
 
202
203
  #### Aggregable Functions
203
- - **float | integer | buffer | string | array float | integer | buffer | string | array.Add(values: array...)** — Add or concatenate values
204
+ - **float | integer | buffer | string | array float | integer | buffer | string | array.Add(values: ...array)** — Add or concatenate values
204
205
 
205
206
  #### Array Functions
206
207
  - **?? array.First(condition: function)** — First item satisfying condition
@@ -215,8 +216,8 @@ Unknown or variant type is declared as **??**.
215
216
  - **array array.Filter(condition: function)** — Filtered array
216
217
  - **?? array.Reduce(reducer: function)** — Reduced value
217
218
  - **object array.Compose(generator: function)** — Compose object from array
218
- - **array array.Prepend(items: array...)** — Prepend items
219
- - **array array.Append(items: array...)** — Append items
219
+ - **array array.Prepend(items: ...array)** — Prepend items
220
+ - **array array.Append(items: ...array)** — Append items
220
221
 
221
222
  #### Buffer Functions
222
223
  - **buffer buffer.Byte(pos: integer)** — Byte at position
@@ -224,8 +225,8 @@ Unknown or variant type is declared as **??**.
224
225
 
225
226
  #### Enumerable Functions
226
227
  - **buffer | string | array.Slice(start: integer?, end: integer?)** — Slice section
227
- - **buffer | string | array.Splice(start: integer, remove: integer, inject: array...)** — Splice section
228
- - **buffer | string | array.Inject(start: integer, inject: array...)** — Inject section
228
+ - **buffer | string | array.Splice(start: integer, remove: integer, inject: ...array)** — Splice section
229
+ - **buffer | string | array.Inject(start: integer, inject: ...array)** — Inject section
229
230
 
230
231
  #### Iterable Functions
231
232
  - **integer buffer | string | array | object.Length()** — Get length
@@ -240,7 +241,7 @@ Unknown or variant type is declared as **??**.
240
241
  - **boolean float | integer.LessOrEqual(value)** — Less or equal
241
242
  - **float | integer float | integer.Subtract(subtrahend)** — Subtract value
242
243
  - **float | integer float | integer.Negate()** — Negate number
243
- - **float | integer float | integer.Multiply(values: array...)** — Multiply values
244
+ - **float | integer float | integer.Multiply(values: ...array)** — Multiply values
244
245
  - **float | integer float | integer.Divide(divisor)** — Divide value
245
246
  - **float | integer float | integer.Remainder(divisor)** — Remainder
246
247
  - **float | integer float | integer.Modulo(divisor)** — Modulo
@@ -269,7 +270,7 @@ Unknown or variant type is declared as **??**.
269
270
  - **string string.LowerCase()** — To lowercase
270
271
  - **string string.UpperCase()** — To uppercase
271
272
  - **array string.Split(separator: string = ' ')** — Split into array
272
- - **string string.ReplaceWith(replacement: string, search: array...)** — Replace all instances of substring with another
273
+ - **string string.ReplaceWith(replacement: string, search: ...array)** — Replace all instances of substring with another
273
274
 
274
275
  #### Timestamp Functions
275
276
  - **integer timestamp.Year(utc: boolean?)** — Get year
package/dst/Affinirum.js CHANGED
@@ -361,7 +361,7 @@ export class Affinirum {
361
361
  }
362
362
  }
363
363
  frame.ends(state);
364
- state.next();
364
+ state.closeBraces().next();
365
365
  return new BlockNode(frame, subnodes);
366
366
  }
367
367
  else if (state.isBracesClose) {
@@ -398,7 +398,7 @@ export class Affinirum {
398
398
  }
399
399
  }
400
400
  frame.ends(state);
401
- state.next();
401
+ state.closeBrackets().next();
402
402
  if (colon) {
403
403
  return new ObjectNode(frame, subnodes.map(([k, v]) => [typeof k === "number" ? new ConstantNode(v, new Constant(String(k))) : k, v]));
404
404
  }
@@ -480,13 +480,15 @@ export class Affinirum {
480
480
  }
481
481
  let argType = Type.Unknown;
482
482
  if (state.next().isColon) {
483
- argType = this._type(state.next(), scope);
483
+ variadic = state.next().isEllipsis;
484
+ if (variadic) {
485
+ state.next();
486
+ }
487
+ argType = this._type(state, scope);
484
488
  }
485
489
  variables.set(token, new Variable(argType));
486
- if (state.isEllipsis) {
490
+ if (variadic) {
487
491
  if (argType.isArray) {
488
- variadic = true;
489
- state.next();
490
492
  break;
491
493
  }
492
494
  else {
@@ -567,12 +569,14 @@ export class Affinirum {
567
569
  let variadic = false;
568
570
  const argTypes = [];
569
571
  while (!state.next().isParenthesesClose) {
572
+ variadic = state.isEllipsis;
573
+ if (variadic) {
574
+ state.next();
575
+ }
570
576
  const argType = this._type(state, scope);
571
577
  argTypes.push(argType);
572
- if (state.isEllipsis) {
578
+ if (variadic) {
573
579
  if (argType.isArray) {
574
- variadic = true;
575
- state.next();
576
580
  break;
577
581
  }
578
582
  else {
@@ -64,7 +64,10 @@ export class FunctionAtom {
64
64
  return 0x1000000000000 + (this._retType ? [this._retType, ...this._argTypes] : []).reduce((acc, i) => acc + i.weight(), 0);
65
65
  }
66
66
  toString() {
67
- const argTypes = this._argTypes.map((i) => i.toString()).join(",");
68
- return this._undefined ? "function" : `~${this._retType.toString()}(${argTypes}${this.isVariadic ? "..." : ""})`;
67
+ const argTypes = this._argTypes.map((i, ix) => {
68
+ const argType = i.toString();
69
+ return (ix === (this._argTypes.length - 1) && this.isVariadic) ? "..." + argType : argType;
70
+ }).join(",");
71
+ return this._undefined ? "function" : `~${this._retType.toString()}(${argTypes})`;
69
72
  }
70
73
  }
@@ -364,7 +364,7 @@ class Affinirum {
364
364
  }
365
365
  }
366
366
  frame.ends(state);
367
- state.next();
367
+ state.closeBraces().next();
368
368
  return new BlockNode_js_1.BlockNode(frame, subnodes);
369
369
  }
370
370
  else if (state.isBracesClose) {
@@ -401,7 +401,7 @@ class Affinirum {
401
401
  }
402
402
  }
403
403
  frame.ends(state);
404
- state.next();
404
+ state.closeBrackets().next();
405
405
  if (colon) {
406
406
  return new ObjectNode_js_1.ObjectNode(frame, subnodes.map(([k, v]) => [typeof k === "number" ? new ConstantNode_js_1.ConstantNode(v, new Constant_js_1.Constant(String(k))) : k, v]));
407
407
  }
@@ -483,13 +483,15 @@ class Affinirum {
483
483
  }
484
484
  let argType = Type_js_1.Type.Unknown;
485
485
  if (state.next().isColon) {
486
- argType = this._type(state.next(), scope);
486
+ variadic = state.next().isEllipsis;
487
+ if (variadic) {
488
+ state.next();
489
+ }
490
+ argType = this._type(state, scope);
487
491
  }
488
492
  variables.set(token, new Variable_js_1.Variable(argType));
489
- if (state.isEllipsis) {
493
+ if (variadic) {
490
494
  if (argType.isArray) {
491
- variadic = true;
492
- state.next();
493
495
  break;
494
496
  }
495
497
  else {
@@ -570,12 +572,14 @@ class Affinirum {
570
572
  let variadic = false;
571
573
  const argTypes = [];
572
574
  while (!state.next().isParenthesesClose) {
575
+ variadic = state.isEllipsis;
576
+ if (variadic) {
577
+ state.next();
578
+ }
573
579
  const argType = this._type(state, scope);
574
580
  argTypes.push(argType);
575
- if (state.isEllipsis) {
581
+ if (variadic) {
576
582
  if (argType.isArray) {
577
- variadic = true;
578
- state.next();
579
583
  break;
580
584
  }
581
585
  else {
@@ -67,8 +67,11 @@ class FunctionAtom {
67
67
  return 0x1000000000000 + (this._retType ? [this._retType, ...this._argTypes] : []).reduce((acc, i) => acc + i.weight(), 0);
68
68
  }
69
69
  toString() {
70
- const argTypes = this._argTypes.map((i) => i.toString()).join(",");
71
- return this._undefined ? "function" : `~${this._retType.toString()}(${argTypes}${this.isVariadic ? "..." : ""})`;
70
+ const argTypes = this._argTypes.map((i, ix) => {
71
+ const argType = i.toString();
72
+ return (ix === (this._argTypes.length - 1) && this.isVariadic) ? "..." + argType : argType;
73
+ }).join(",");
74
+ return this._undefined ? "function" : `~${this._retType.toString()}(${argTypes})`;
72
75
  }
73
76
  }
74
77
  exports.FunctionAtom = FunctionAtom;
@@ -30,12 +30,12 @@ const formatAN = (value, whitespace) => {
30
30
  if (Array.isArray(value)) {
31
31
  const [prefix, suffix] = whitespace ? ["\n" + whitespace, "\n"] : ["", ""];
32
32
  const lines = value.map((i) => `${prefix}${(0, exports.formatAN)(i, whitespace).split("\n").join(prefix)}`);
33
- return `[${lines.join(",")}${suffix}]`;
33
+ return lines.length ? `[${lines.join(",")}${suffix}]` : "[]";
34
34
  }
35
35
  if (typeof value === "object") {
36
36
  const [prefix, suffix, separator] = whitespace ? ["\n" + whitespace, "\n", ": "] : ["", "", ":"];
37
37
  const lines = Object.entries(value).map(([k, v]) => `${prefix}"${k}"${separator}${(0, exports.formatAN)(v, whitespace).split("\n").join(prefix)}`);
38
- return `[${lines.join(",")}${suffix}]`;
38
+ return lines.length ? `[${lines.join(",")}${suffix}]` : "[:]";
39
39
  }
40
40
  return "function";
41
41
  };
@@ -27,12 +27,12 @@ export const formatAN = (value, whitespace) => {
27
27
  if (Array.isArray(value)) {
28
28
  const [prefix, suffix] = whitespace ? ["\n" + whitespace, "\n"] : ["", ""];
29
29
  const lines = value.map((i) => `${prefix}${formatAN(i, whitespace).split("\n").join(prefix)}`);
30
- return `[${lines.join(",")}${suffix}]`;
30
+ return lines.length ? `[${lines.join(",")}${suffix}]` : "[]";
31
31
  }
32
32
  if (typeof value === "object") {
33
33
  const [prefix, suffix, separator] = whitespace ? ["\n" + whitespace, "\n", ": "] : ["", "", ":"];
34
34
  const lines = Object.entries(value).map(([k, v]) => `${prefix}"${k}"${separator}${formatAN(v, whitespace).split("\n").join(prefix)}`);
35
- return `[${lines.join(",")}${suffix}]`;
35
+ return lines.length ? `[${lines.join(",")}${suffix}]` : "[:]";
36
36
  }
37
37
  return "function";
38
38
  };
@@ -1,5 +1,5 @@
1
1
  import { Constant } from "../../Constant.js";
2
- import { Value } from "src/Value.js";
2
+ import { Value } from "../../Value.js";
3
3
  export declare const formatJSON: (value: Value, whitespace?: string) => string;
4
4
  export declare const constJSON: {
5
5
  Format: Constant;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "affinirum",
3
- "version": "1.2.7",
3
+ "version": "1.3.0",
4
4
  "description": "Affinirum Scripting Language",
5
5
  "main": "dst/cjs/index.js",
6
6
  "module": "dst/index.js",
@@ -56,12 +56,13 @@
56
56
  },
57
57
  "dependencies": {},
58
58
  "devDependencies": {
59
- "@types/jasmine": "~5.1.15",
59
+ "@eslint/js": "10.0.1",
60
+ "@types/jasmine": "~6.0.0",
60
61
  "copyfiles": "~2.4.1",
61
- "eslint": "~9.39.2",
62
- "jasmine": "~5.13.0",
63
- "rimraf": "~6.1.2",
64
- "typescript": "~5.9.3",
65
- "typescript-eslint": "~8.53.0"
62
+ "eslint": "~10.6.0",
63
+ "jasmine": "~6.3.0",
64
+ "rimraf": "~6.1.3",
65
+ "typescript": "~6.0.3",
66
+ "typescript-eslint": "~8.62.1"
66
67
  }
67
68
  }