starlight-cli 1.1.13 → 1.1.15

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/dist/index.js CHANGED
@@ -10433,7 +10433,24 @@ this.global.define('random', (min, max) => {
10433
10433
  if (isNaN(min) || isNaN(max)) return 0;
10434
10434
  return Math.floor(Math.random() * (max - min)) + min;
10435
10435
  });
10436
+ this.global.define('JSONParse', arg => {
10437
+ if (typeof arg !== 'string') {
10438
+ throw new RuntimeError('JSONParse expects a string', null, evaluator.source);
10439
+ }
10440
+ try {
10441
+ return JSON.parse(arg);
10442
+ } catch (e) {
10443
+ throw new RuntimeError('Invalid JSON string: ' + e.message, null, evaluator.source);
10444
+ }
10445
+ });
10436
10446
 
10447
+ this.global.define('JSONStringify', arg => {
10448
+ try {
10449
+ return JSON.stringify(arg);
10450
+ } catch (e) {
10451
+ throw new RuntimeError('Cannot stringify value: ' + e.message, null, evaluator.source);
10452
+ }
10453
+ });
10437
10454
  this.global.define('map', async (array, fn) => {
10438
10455
  if (!Array.isArray(array)) {
10439
10456
  throw new RuntimeError('map() expects an array', null, evaluator.source);
@@ -10451,6 +10468,10 @@ this.global.define('random', (min, max) => {
10451
10468
  }
10452
10469
  return result;
10453
10470
  });
10471
+ this.global.define('encodeURLComponent', arg => {
10472
+ if (arg === null || arg === undefined) return '';
10473
+ return encodeURIComponent(String(arg));
10474
+ });
10454
10475
 
10455
10476
  this.global.define('filter', async (array, fn) => {
10456
10477
  if (!Array.isArray(array)) {
@@ -11607,7 +11628,7 @@ async evalUpdate(node, env) {
11607
11628
 
11608
11629
  }
11609
11630
 
11610
- module.exports = Evaluator;
11631
+ module.exports = Evaluator;
11611
11632
 
11612
11633
  /***/ }),
11613
11634
 
@@ -13730,7 +13751,7 @@ const Lexer = __nccwpck_require__(211);
13730
13751
  const Parser = __nccwpck_require__(222);
13731
13752
  const Evaluator = __nccwpck_require__(112);
13732
13753
 
13733
- const VERSION = '1.1.13';
13754
+ const VERSION = '1.1.15';
13734
13755
 
13735
13756
  const COLOR = {
13736
13757
  reset: '\x1b[0m',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-cli",
3
- "version": "1.1.13",
3
+ "version": "1.1.15",
4
4
  "description": "Starlight Programming Language CLI",
5
5
  "bin": {
6
6
  "starlight": "index.js"
package/src/evaluator.js CHANGED
@@ -223,7 +223,24 @@ this.global.define('random', (min, max) => {
223
223
  if (isNaN(min) || isNaN(max)) return 0;
224
224
  return Math.floor(Math.random() * (max - min)) + min;
225
225
  });
226
+ this.global.define('JSONParse', arg => {
227
+ if (typeof arg !== 'string') {
228
+ throw new RuntimeError('JSONParse expects a string', null, evaluator.source);
229
+ }
230
+ try {
231
+ return JSON.parse(arg);
232
+ } catch (e) {
233
+ throw new RuntimeError('Invalid JSON string: ' + e.message, null, evaluator.source);
234
+ }
235
+ });
226
236
 
237
+ this.global.define('JSONStringify', arg => {
238
+ try {
239
+ return JSON.stringify(arg);
240
+ } catch (e) {
241
+ throw new RuntimeError('Cannot stringify value: ' + e.message, null, evaluator.source);
242
+ }
243
+ });
227
244
  this.global.define('map', async (array, fn) => {
228
245
  if (!Array.isArray(array)) {
229
246
  throw new RuntimeError('map() expects an array', null, evaluator.source);
@@ -241,6 +258,10 @@ this.global.define('random', (min, max) => {
241
258
  }
242
259
  return result;
243
260
  });
261
+ this.global.define('encodeURLComponent', arg => {
262
+ if (arg === null || arg === undefined) return '';
263
+ return encodeURIComponent(String(arg));
264
+ });
244
265
 
245
266
  this.global.define('filter', async (array, fn) => {
246
267
  if (!Array.isArray(array)) {
@@ -1397,4 +1418,4 @@ async evalUpdate(node, env) {
1397
1418
 
1398
1419
  }
1399
1420
 
1400
- module.exports = Evaluator;
1421
+ module.exports = Evaluator;
package/src/starlight.js CHANGED
@@ -12,7 +12,7 @@ const Lexer = require('./lexer');
12
12
  const Parser = require('./parser');
13
13
  const Evaluator = require('./evaluator');
14
14
 
15
- const VERSION = '1.1.13';
15
+ const VERSION = '1.1.15';
16
16
 
17
17
  const COLOR = {
18
18
  reset: '\x1b[0m',