starlight-cli 1.1.4 → 1.1.6

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
@@ -1,65 +1,53 @@
1
- # Starlight Language
1
+
2
+ # Starlight Programming Language
2
3
 
3
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.
4
5
 
5
- **Official Reference:** [
6
+ **Official Reference:**
7
+ https://starlight-learn-lang.pages.dev/
6
8
 
7
9
  ---
8
10
 
9
11
  ## Key Features
10
12
 
11
-
12
- - **Modern, Simple Syntax** – Familiar to JavaScript and Python developers
13
- - **Async / Await** – Native support for asynchronous operations
14
- - **Modules & Imports** – Import JavaScript packages or other `.sl` files
15
- - **Server-side Ready** – Built on Node.js, ideal for backend logic
16
- - **Interactive I/O** – Built-in `ask` and `sldeploy`
17
- - **Built-in Utilities** – `sleep`, `len`, `keys`, `values`, `fetch`, `get`, `post`
18
-
13
+ - **Modern, Simple Syntax** – Familiar to JavaScript and Python developers
14
+ - **Async / Await** – Native support for asynchronous operations
15
+ - **Modules & Imports** – Import JavaScript packages or other `.sl` files
16
+ - **Server-side Ready** – Built on Node.js, ideal for backend logic
17
+ - **Interactive I/O** – Built-in `ask` and `sldeploy`
18
+ - **Built-in Utilities** – `sleep`, `len`, `keys`, `values`, `fetch`, `get`, `post`
19
19
 
20
20
  ---
21
21
 
22
22
  ## Installation
23
23
 
24
+ 1. Install **Node.js** (v18+ recommended)
25
+ 2. Install the Starlight CLI:
24
26
 
25
- Install **Node.js** (v18+ recommended)1. $1
26
- Install Starlight CLI:1. $1
27
-
28
-
29
- ```
30
-
27
+ ```bash
31
28
  npm install -g starlight-cli
32
-
33
- ```
29
+ ````
34
30
 
35
31
  ---
36
32
 
37
33
  ## Your First Program (`hello.sl`)
38
34
 
39
- ```
40
-
35
+ ```sl
41
36
  let name = ask("What is your name?")
42
37
  sldeploy "Hello, " + name + "!"
43
-
44
38
  ```
45
39
 
46
40
  Run:
47
41
 
48
- ```
49
-
42
+ ```bash
50
43
  starlight hello.sl
51
-
52
44
  ```
53
45
 
54
- ---
55
-
56
- ## Output
57
-
58
- ```
46
+ ### Output
59
47
 
48
+ ```
60
49
  What is your name? Alice
61
50
  Hello, Alice!
62
-
63
51
  ```
64
52
 
65
53
  ---
@@ -68,68 +56,59 @@ Hello, Alice!
68
56
 
69
57
  ### Variables
70
58
 
71
- ```
72
-
59
+ ```sl
73
60
  let x = 10
74
61
  let text = "hello"
75
-
76
62
  ```
77
63
 
78
64
  ---
79
65
 
80
66
  ### Functions
81
67
 
82
- ```
83
-
68
+ ```sl
84
69
  func add(a, b) {
85
70
  return a + b
86
71
  }
87
72
 
88
73
  sldeploy add(2, 3)
89
-
90
74
  ```
91
75
 
92
- ### Async Functions
76
+ ---
93
77
 
94
- ```
78
+ ### Async Functions
95
79
 
80
+ ```sl
96
81
  async func load() {
97
82
  let data = await get("https://example.com/api")
98
83
  sldeploy data
99
84
  }
100
85
 
101
86
  load()
102
-
103
87
  ```
104
88
 
105
89
  ---
106
90
 
107
91
  ## Arrow Functions
108
92
 
109
- Arrow functions provide a **concise and expressive** way to define functions. They support expressions, block bodies, conditionals, loops, and `return` statements.
93
+ Arrow functions provide a **concise and expressive** way to define functions.
110
94
 
111
95
  ### Basic Arrow Function
112
96
 
113
- ```
114
-
97
+ ```sl
115
98
  let square = x => x * x
116
99
  sldeploy square(5)
117
-
118
100
  ```
119
101
 
120
102
  ### Multiple Parameters
121
103
 
122
- ```
123
-
104
+ ```sl
124
105
  let add = (a, b) => a + b
125
106
  sldeploy add(10, 20)
126
-
127
107
  ```
128
108
 
129
109
  ### Block Body with if / else
130
110
 
131
- ```
132
-
111
+ ```sl
133
112
  let label = p => {
134
113
  if (p.price > 1000) {
135
114
  return "Premium"
@@ -137,20 +116,17 @@ let label = p => {
137
116
  return "Standard"
138
117
  }
139
118
  }
140
-
141
119
  ```
142
120
 
143
121
  ### Arrow Functions with Objects
144
122
 
145
- ```
146
-
123
+ ```sl
147
124
  let summarize = p => {
148
125
  return {
149
126
  "name": p.name,
150
127
  "value": p.price * p.stock
151
128
  }
152
129
  }
153
-
154
130
  ```
155
131
 
156
132
  Arrow functions capture their surrounding scope and behave like standard functions while remaining lightweight and readable.
@@ -159,14 +135,12 @@ Arrow functions capture their surrounding scope and behave like standard functio
159
135
 
160
136
  ## Conditionals
161
137
 
162
- ```
163
-
138
+ ```sl
164
139
  if (x > 5) {
165
140
  sldeploy "Greater than 5"
166
141
  } else {
167
142
  sldeploy "5 or less"
168
143
  }
169
-
170
144
  ```
171
145
 
172
146
  ---
@@ -175,16 +149,12 @@ if (x > 5) {
175
149
 
176
150
  ### While Loop
177
151
 
178
- ```
179
-
152
+ ```sl
180
153
  let i = 0
181
- while (i {
182
- let response = await get("https://jsonplaceholder.typicode.com/todos/1")
183
- sldeploy response
154
+ while (i < 3) {
155
+ sldeploy i
156
+ i = i + 1
184
157
  }
185
-
186
- server()
187
-
188
158
  ```
189
159
 
190
160
  ---
@@ -195,8 +165,7 @@ Starlight includes a **start / race** control structure similar to a switch stat
195
165
 
196
166
  ### Syntax
197
167
 
198
- ```
199
-
168
+ ```sl
200
169
  start (value) {
201
170
  race (1) {
202
171
  # body
@@ -206,49 +175,210 @@ start (value) {
206
175
  # body
207
176
  }
208
177
  }
209
-
210
178
  ```
211
179
 
212
180
  ### Example
213
181
 
214
- ```
215
-
216
- define x = 2;
182
+ ```sl
183
+ define x = 2
217
184
 
218
185
  start (x) {
219
- race (1) { sldeploy("Race 1 executed"); }
220
- race (2) { sldeploy("Race 2 executed"); }
221
- race (3) { sldeploy("Race 3 executed"); }
186
+ race (1) { sldeploy("Race 1 executed") }
187
+ race (2) { sldeploy("Race 2 executed") }
188
+ race (3) { sldeploy("Race 3 executed") }
222
189
  }
223
190
 
224
- sldeploy("Done with start statement");
225
-
191
+ sldeploy("Done with start statement")
226
192
  ```
227
193
 
228
194
  ### Expected Output
229
195
 
230
- ```
231
-
196
+ ```
232
197
  Race 2 executed
233
198
  Race 3 executed
234
199
  Done with start statement
235
-
236
200
  ```
237
201
 
238
202
  ---
239
203
 
240
- ## Why Starlight?
204
+ ## Markdown Preview (`starlight filename.md`)
205
+
206
+ Starlight can also be used to **preview Markdown files** directly from the CLI.
207
+
208
+ ### Usage
209
+
210
+ ```bash
211
+ starlight README.md
212
+ ```
213
+
214
+ ### How It Works (Execution Flow)
215
+
216
+ 1. The CLI detects the `.md` file extension
217
+ 2. The Markdown file is read from disk
218
+ 3. Markdown is converted to HTML using a full-featured Markdown renderer
219
+ 4. A **temporary HTML file** is created in the system temp directory
220
+ 5. The file is opened in your default browser using `file://`
221
+ 6. After the browser loads, the temporary file is **automatically deleted**
222
+
223
+ This makes Starlight useful not only as a programming language, but also as a **developer productivity tool**.
224
+
225
+ ---
226
+
227
+ ## Array Helpers: map, filter, reduce
228
+
229
+ Starlight provides built-in **functional helpers** for working with arrays: `map`, `filter`, and `reduce`.
230
+ These helpers are **async-aware**, work seamlessly with **arrow functions**, and integrate fully with Starlight’s runtime and error handling.
231
+
232
+ Unlike JavaScript, these are **global functions** (not methods), keeping the language simple and consistent.
233
+
234
+ ---
235
+
236
+ ### map(array, fn)
237
+
238
+ Transforms each element of an array using a callback function and returns a **new array**.
239
+
240
+ **Syntax:**
241
+ ```
242
+
243
+ map(array, fn)
244
+
245
+ ```
246
+
247
+ **Example:**
248
+ ```
249
+
250
+ let numbers = [1, 2, 3, 4]
251
+
252
+ let squared = await map(numbers, x => x * x)
253
+
254
+ sldeploy squared
255
+
256
+ ```
257
+
258
+ **Output:**
259
+ ```
260
+
261
+ [ 1, 4, 9, 16 ]
262
+
263
+ ```
264
+
265
+ - `fn` receives `(value, index, array)`
266
+ - Does **not** modify the original array
267
+ - Supports `async` arrow functions
241
268
 
269
+ ---
270
+
271
+ ### filter(array, fn)
272
+
273
+ Selects elements from an array that satisfy a condition and returns a **new array**.
274
+
275
+ **Syntax:**
276
+ ```
277
+
278
+ filter(array, fn)
279
+
280
+ ```
281
+
282
+ **Example:**
283
+ ```
284
+
285
+ let numbers = [1, 2, 3, 4, 5, 6]
286
+
287
+ let evens = await filter(numbers, x => x % 2 == 0)
288
+
289
+ sldeploy evens
290
+
291
+ ```
292
+
293
+ **Output:**
294
+ ```
295
+
296
+ [ 2, 4, 6 ]
297
+
298
+ ```
299
+
300
+ - `fn` must return `true` or `false`
301
+ - `fn` receives `(value, index, array)`
302
+ - Original array remains unchanged
303
+
304
+ ---
305
+
306
+ ### reduce(array, fn, initial)
307
+
308
+ Reduces an array to a **single value** by accumulating results using a reducer function.
309
+
310
+ **Syntax:**
311
+ ```
312
+
313
+ reduce(array, fn, initial)
314
+
315
+ ```
316
+
317
+ **Example:**
318
+ ```
242
319
 
243
- - A **simple but powerful** scripting language
244
- - **Fast server-side automation**
245
- - Familiar syntax with **less boilerplate**
246
- - Full access to the **Node.js ecosystem**
320
+ let numbers = [1, 2, 3, 4, 5]
247
321
 
322
+ let total = await reduce(numbers, (acc, value) => acc + value, 0)
323
+
324
+ sldeploy total
325
+
326
+ ```
327
+
328
+ **Output:**
329
+ ```
330
+
331
+ 15
332
+
333
+ ```
334
+
335
+ - `fn` receives `(accumulator, value, index, array)`
336
+ - `initial` is optional, but recommended
337
+ - Throws a runtime error if used on an empty array without an initial value
338
+
339
+ ---
340
+
341
+ ### Async Support
342
+
343
+ All three helpers support `async` functions:
344
+
345
+ ```
346
+
347
+ let results = await map(items, async item => {
348
+ await sleep(100)
349
+ return item * 2
350
+ })
351
+
352
+ ```
353
+
354
+ ---
355
+
356
+ ### Why global helpers?
357
+
358
+ Starlight keeps `map`, `filter`, and `reduce` as **language-level utilities** instead of object methods to:
359
+
360
+ - Keep syntax minimal and readable
361
+ - Avoid prototype complexity
362
+ - Work consistently with all iterables
363
+ - Integrate cleanly with the evaluator and runtime
364
+
365
+ ---
366
+
367
+
368
+ ## Why Starlight?
369
+
370
+ * A **simple but powerful** scripting language
371
+ * **Fast server-side automation**
372
+ * Familiar syntax with **less boilerplate**
373
+ * Full access to the **Node.js ecosystem**
248
374
 
249
375
  ---
250
376
 
251
- 📘 Full documentation and tutorials:
252
- https://starlight-learn-lang.pages.dev/](https://starlight-learn-lang.pages.dev/>https://starlight-learn-lang.pages.dev/</link)
377
+ ## License
378
+
379
+ MIT License
380
+
381
+ ---
253
382
 
254
- **License:** MIT
383
+ ## Author and Developer
384
+ Dominex Macedon