starlight-cli 1.1.7 → 1.1.9

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
@@ -4,7 +4,7 @@
4
4
  Starlight is a lightweight, developer-oriented programming language designed for **server-side scripting, automation, and general-purpose programming**. It combines a clean, readable syntax inspired by JavaScript and Python with powerful runtime features such as async/await, modules, and interactive I/O.
5
5
 
6
6
  **Official Reference:**
7
- https://starlight-learn-lang.pages.dev/
7
+ https://developerdominex.github.io/starlight-programming-language/
8
8
 
9
9
  ---
10
10
 
package/dist/index.js CHANGED
@@ -10477,12 +10477,26 @@ this.global.define('range', (...args) => {
10477
10477
  return readlineSync.question(prompt + ' ');
10478
10478
  });
10479
10479
  this.global.define('num', arg => {
10480
- const n = Number(arg);
10481
- if (Number.isNaN(n)) {
10482
- throw new RuntimeError('Cannot convert value to number', null, this.source);
10480
+ if (arg === null || arg === undefined) return 0;
10481
+
10482
+ const t = typeof arg;
10483
+
10484
+ if (t === 'number') return arg; // already a number
10485
+ if (t === 'boolean') return arg ? 1 : 0;
10486
+ if (t === 'string') {
10487
+ const n = Number(arg);
10488
+ if (!Number.isNaN(n)) return n; // numeric string
10489
+ return 0; // non-numeric string becomes 0
10483
10490
  }
10484
- return n;
10491
+ if (Array.isArray(arg)) return arg.length; // array → length
10492
+ if (t === 'object') return Object.keys(arg).length; // object → number of keys
10493
+
10494
+ // fallback for anything else
10495
+ const n = Number(arg);
10496
+ if (!Number.isNaN(n)) return n;
10497
+ return 0;
10485
10498
  });
10499
+
10486
10500
  this.global.define('fetch', async (url, options = {}) => {
10487
10501
  const res = await fetch(url, options);
10488
10502
  return {
@@ -10924,7 +10938,30 @@ async evalBinary(node, env) {
10924
10938
  }
10925
10939
 
10926
10940
  switch (node.operator) {
10927
- case 'PLUS': return l + r;
10941
+ case 'PLUS': {
10942
+ if (Array.isArray(l) && Array.isArray(r)) {
10943
+ return l.concat(r);
10944
+ }
10945
+
10946
+ if (typeof l === 'string' || typeof r === 'string') {
10947
+ return String(l) + String(r);
10948
+ }
10949
+
10950
+ if (typeof l === 'number' && typeof r === 'number') {
10951
+ return l + r;
10952
+ }
10953
+
10954
+ if (typeof l === 'object' && typeof r === 'object') {
10955
+ return { ...l, ...r };
10956
+ }
10957
+
10958
+ throw new RuntimeError(
10959
+ `Unsupported operands for +: ${typeof l} and ${typeof r}`,
10960
+ node,
10961
+ this.source
10962
+ );
10963
+ }
10964
+
10928
10965
  case 'MINUS': return l - r;
10929
10966
  case 'STAR': return l * r;
10930
10967
  case 'SLASH': return l / r;
@@ -12507,7 +12544,7 @@ const Lexer = __nccwpck_require__(211);
12507
12544
  const Parser = __nccwpck_require__(222);
12508
12545
  const Evaluator = __nccwpck_require__(112);
12509
12546
 
12510
- const VERSION = '1.1.7';
12547
+ const VERSION = '1.1.9';
12511
12548
 
12512
12549
  const COLOR = {
12513
12550
  reset: '\x1b[0m',
@@ -12804,18 +12841,20 @@ async function runFile(filePath, isTemp = false, callback) {
12804
12841
  try { fs.unlinkSync(filePath); } catch {}
12805
12842
  }
12806
12843
  }
12807
-
12808
-
12809
12844
  if (!args[0].startsWith('--')) {
12810
12845
  const file = path.resolve(args[0]);
12811
12846
  const ext = path.extname(file).toLowerCase();
12812
12847
 
12813
12848
  if (ext === '.md') {
12814
12849
  renderMarkdown(file);
12815
- } else {
12850
+ } else if (ext === '.sl') {
12816
12851
  runFile(file);
12852
+ } else {
12853
+ console.error(COLOR.red + 'Incorrect file extension. Create .sl or .md to be able to run correctly.' + COLOR.reset);
12854
+ waitAndExit(1);
12817
12855
  }
12818
12856
  }
12857
+
12819
12858
 
12820
12859
  module.exports = __webpack_exports__;
12821
12860
  /******/ })()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "starlight-cli",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
4
4
  "description": "Starlight Programming Language CLI",
5
5
  "bin": {
6
6
  "starlight": "index.js"
package/src/evaluator.js CHANGED
@@ -267,12 +267,26 @@ this.global.define('range', (...args) => {
267
267
  return readlineSync.question(prompt + ' ');
268
268
  });
269
269
  this.global.define('num', arg => {
270
- const n = Number(arg);
271
- if (Number.isNaN(n)) {
272
- throw new RuntimeError('Cannot convert value to number', null, this.source);
270
+ if (arg === null || arg === undefined) return 0;
271
+
272
+ const t = typeof arg;
273
+
274
+ if (t === 'number') return arg; // already a number
275
+ if (t === 'boolean') return arg ? 1 : 0;
276
+ if (t === 'string') {
277
+ const n = Number(arg);
278
+ if (!Number.isNaN(n)) return n; // numeric string
279
+ return 0; // non-numeric string becomes 0
273
280
  }
274
- return n;
281
+ if (Array.isArray(arg)) return arg.length; // array → length
282
+ if (t === 'object') return Object.keys(arg).length; // object → number of keys
283
+
284
+ // fallback for anything else
285
+ const n = Number(arg);
286
+ if (!Number.isNaN(n)) return n;
287
+ return 0;
275
288
  });
289
+
276
290
  this.global.define('fetch', async (url, options = {}) => {
277
291
  const res = await fetch(url, options);
278
292
  return {
@@ -714,7 +728,30 @@ async evalBinary(node, env) {
714
728
  }
715
729
 
716
730
  switch (node.operator) {
717
- case 'PLUS': return l + r;
731
+ case 'PLUS': {
732
+ if (Array.isArray(l) && Array.isArray(r)) {
733
+ return l.concat(r);
734
+ }
735
+
736
+ if (typeof l === 'string' || typeof r === 'string') {
737
+ return String(l) + String(r);
738
+ }
739
+
740
+ if (typeof l === 'number' && typeof r === 'number') {
741
+ return l + r;
742
+ }
743
+
744
+ if (typeof l === 'object' && typeof r === 'object') {
745
+ return { ...l, ...r };
746
+ }
747
+
748
+ throw new RuntimeError(
749
+ `Unsupported operands for +: ${typeof l} and ${typeof r}`,
750
+ node,
751
+ this.source
752
+ );
753
+ }
754
+
718
755
  case 'MINUS': return l - r;
719
756
  case 'STAR': return l * r;
720
757
  case 'SLASH': return l / r;
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.7';
15
+ const VERSION = '1.1.9';
16
16
 
17
17
  const COLOR = {
18
18
  reset: '\x1b[0m',
@@ -309,15 +309,17 @@ async function runFile(filePath, isTemp = false, callback) {
309
309
  try { fs.unlinkSync(filePath); } catch {}
310
310
  }
311
311
  }
312
-
313
-
314
312
  if (!args[0].startsWith('--')) {
315
313
  const file = path.resolve(args[0]);
316
314
  const ext = path.extname(file).toLowerCase();
317
315
 
318
316
  if (ext === '.md') {
319
317
  renderMarkdown(file);
320
- } else {
318
+ } else if (ext === '.sl') {
321
319
  runFile(file);
320
+ } else {
321
+ console.error(COLOR.red + 'Incorrect file extension. Create .sl or .md to be able to run correctly.' + COLOR.reset);
322
+ waitAndExit(1);
322
323
  }
323
324
  }
325
+