plainscript-lang 1.0.0 → 1.0.2-latest
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 +194 -729
- package/compiler/bundler.js +2 -2
- package/compiler/cli.js +182 -79
- package/compiler/dependency-detector.js +5 -0
- package/compiler/formatter.js +1 -1
- package/compiler/generator.js +1083 -206
- package/compiler/lexer.js +130 -54
- package/compiler/parser.js +1117 -156
- package/compiler/version.js +1 -1
- package/docs/CAPABILITY_GAP_AUDIT.md +98 -435
- package/docs/PLAINSCRIPT-SPEC.md +335 -0
- package/docs/index.html +103 -605
- package/docs/website/script.js +59 -943
- package/docs/website/style.css +74 -656
- package/examples/ai-providers.pln +7 -0
- package/examples/arrays.pln +4 -0
- package/examples/async-errors.pln +18 -0
- package/examples/auth-api.pln +9 -0
- package/examples/auth-sessions.pln +32 -0
- package/examples/basics.pln +14 -0
- package/examples/bots.pln +13 -0
- package/examples/cache-and-jobs.pln +7 -0
- package/examples/cache-schedule.pln +22 -0
- package/examples/collections.pln +15 -0
- package/examples/concurrency.pln +18 -0
- package/examples/conditions.pln +22 -0
- package/examples/database.pln +8 -0
- package/examples/day2.pln +7 -0
- package/examples/day3.pln +5 -0
- package/examples/deployment.pln +6 -0
- package/examples/email-send.pln +3 -0
- package/examples/error-handling.pln +7 -0
- package/examples/expressions.pln +7 -0
- package/examples/file-uploads.pln +10 -0
- package/examples/files-and-config.pln +6 -0
- package/examples/files.pln +12 -0
- package/examples/football-backend/{app.ps → app.pln} +22 -21
- package/examples/functions.pln +17 -0
- package/examples/hello.pln +2 -0
- package/examples/http-client.pln +3 -0
- package/examples/http.pln +11 -0
- package/examples/id-verification/{app.ps → app.pln} +5 -4
- package/examples/id-verification/make-sample-id.js +29 -42
- package/examples/json.pln +11 -0
- package/examples/loops.pln +18 -0
- package/examples/modules/app.pln +3 -0
- package/examples/modules/main.pln +4 -0
- package/examples/modules/math.pln +9 -0
- package/examples/mongo.pln +33 -0
- package/examples/objects.pln +4 -0
- package/examples/ocr.pln +22 -0
- package/examples/packages.pln +6 -0
- package/examples/record-kinds.pln +7 -0
- package/examples/records.pln +15 -0
- package/examples/rest-api-fetch.pln +10 -0
- package/examples/rest-api.pln +8 -0
- package/examples/scheduled-tasks.pln +4 -0
- package/examples/search-and-filter.pln +4 -0
- package/examples/server.pln +6 -0
- package/examples/sessions-and-cookies.pln +8 -0
- package/examples/sqlite.pln +23 -0
- package/examples/start.pln +2 -0
- package/examples/stdlib.pln +4 -0
- package/examples/telegram-ai-bot.pln +19 -0
- package/examples/telegram-bot.pln +6 -0
- package/examples/testing.pln +13 -0
- package/examples/web-api.pln +27 -0
- package/examples/web-app.pln +8 -0
- package/examples/websocket-server.pln +6 -0
- package/examples/websocket.pln +13 -0
- package/examples/whatsapp-bot/{pairing.ps → pairing.pln} +4 -5
- package/examples/whatsapp-bot/qr.pln +12 -0
- package/package.json +3 -2
- package/docs/PLINJS_SPEC.md +0 -1151
- package/examples/arrays.ps +0 -13
- package/examples/auth-api.ps +0 -56
- package/examples/cache-and-jobs.ps +0 -29
- package/examples/concurrency.ps +0 -49
- package/examples/database.ps +0 -41
- package/examples/day2.ps +0 -7
- package/examples/day3.ps +0 -11
- package/examples/deployment.ps +0 -12
- package/examples/email-send.ps +0 -22
- package/examples/error-handling.ps +0 -54
- package/examples/expressions.ps +0 -40
- package/examples/file-uploads.ps +0 -39
- package/examples/files-and-config.ps +0 -47
- package/examples/hello.ps +0 -3
- package/examples/http-client.ps +0 -44
- package/examples/loops.ps +0 -17
- package/examples/modules/app.ps +0 -16
- package/examples/modules/math.ps +0 -20
- package/examples/objects.ps +0 -12
- package/examples/record-kinds.ps +0 -43
- package/examples/rest-api-fetch.ps +0 -94
- package/examples/rest-api.ps +0 -68
- package/examples/scheduled-tasks.ps +0 -23
- package/examples/search-and-filter.ps +0 -34
- package/examples/server.ps +0 -25
- package/examples/sessions-and-cookies.ps +0 -54
- package/examples/start.ps +0 -2
- package/examples/stdlib.ps +0 -41
- package/examples/telegram-bot.ps +0 -42
- package/examples/web-app.ps +0 -20
- package/examples/websocket-server.ps +0 -27
- package/examples/whatsapp-bot/qr.ps +0 -8
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// PlainScript 1.0.2-latest: provider-backed AI works in ordinary programs.
|
|
2
|
+
|
|
3
|
+
remember answer as chatWith("groq", "llama-3.3-70b-versatile", "Explain PlainScript in one sentence")
|
|
4
|
+
show answer
|
|
5
|
+
|
|
6
|
+
remember embedding as embedWith("groq", "nomic-embed-text-v1.5", "PlainScript")
|
|
7
|
+
show length(embedding)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// PlainScript 1.0.2-latest: asynchronous work and error recovery.
|
|
2
|
+
|
|
3
|
+
make loadProfile(id)
|
|
4
|
+
wait for sleep(10)
|
|
5
|
+
give record with id id and ready true done
|
|
6
|
+
done
|
|
7
|
+
|
|
8
|
+
try
|
|
9
|
+
remember profile as wait for loadProfile(7)
|
|
10
|
+
show profile.ready
|
|
11
|
+
recover as err
|
|
12
|
+
show message of err
|
|
13
|
+
finally
|
|
14
|
+
show "request complete"
|
|
15
|
+
|
|
16
|
+
retry 3 times every 2 seconds
|
|
17
|
+
show "retrying"
|
|
18
|
+
done
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// PlainScript 1.0.2-latest: API keys, sessions, cookies, and auth helpers.
|
|
2
|
+
|
|
3
|
+
web app
|
|
4
|
+
enable sessions "development-only-session-secret"
|
|
5
|
+
require api key from "demo-key"
|
|
6
|
+
limit requests to 60 per minute
|
|
7
|
+
|
|
8
|
+
route post "/login"
|
|
9
|
+
remember passwordOk as checkPassword(password of body of request, hashPassword("secret"))
|
|
10
|
+
if passwordOk is true
|
|
11
|
+
user of session of request becomes "ada"
|
|
12
|
+
set cookie "theme" to "dark" expires in 7 days
|
|
13
|
+
reply json
|
|
14
|
+
authenticated is true
|
|
15
|
+
token is createToken("ada", "token-secret")
|
|
16
|
+
done
|
|
17
|
+
otherwise
|
|
18
|
+
status 401
|
|
19
|
+
reply json
|
|
20
|
+
authenticated is false
|
|
21
|
+
done
|
|
22
|
+
done
|
|
23
|
+
done
|
|
24
|
+
|
|
25
|
+
route get "/me"
|
|
26
|
+
reply json
|
|
27
|
+
user is user of session of request
|
|
28
|
+
theme is cookie("theme")
|
|
29
|
+
done
|
|
30
|
+
done
|
|
31
|
+
|
|
32
|
+
start 0
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// PlainScript 1.0.2-latest: variables, values, and output.
|
|
2
|
+
|
|
3
|
+
remember name as "Ada"
|
|
4
|
+
remember visitCount as 3
|
|
5
|
+
let greeting be `Hello, ${name}!`
|
|
6
|
+
|
|
7
|
+
show greeting
|
|
8
|
+
show visitCount + 1
|
|
9
|
+
|
|
10
|
+
if visitCount is at least 3
|
|
11
|
+
show "Returning visitor"
|
|
12
|
+
otherwise
|
|
13
|
+
show "First visit"
|
|
14
|
+
done
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// PlainScript 1.0.2-latest: cache values and scheduled work.
|
|
2
|
+
|
|
3
|
+
cache "redis://localhost:6379"
|
|
4
|
+
|
|
5
|
+
make refresh()
|
|
6
|
+
remember value as `updated at ${time()}`
|
|
7
|
+
cacheSet("status", value, 60)
|
|
8
|
+
give value
|
|
9
|
+
done
|
|
10
|
+
|
|
11
|
+
every 5 minutes
|
|
12
|
+
run background refresh()
|
|
13
|
+
done
|
|
14
|
+
|
|
15
|
+
schedule "0 * * * *"
|
|
16
|
+
remember status as cacheGet("status")
|
|
17
|
+
if status is empty
|
|
18
|
+
refresh()
|
|
19
|
+
otherwise
|
|
20
|
+
show status
|
|
21
|
+
done
|
|
22
|
+
done
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// PlainScript 1.0.2-latest: lists, objects, and collection helpers.
|
|
2
|
+
|
|
3
|
+
remember numbers as list with 4, 7, 2, 9
|
|
4
|
+
gather each number in numbers giving number * 2
|
|
5
|
+
filter each number in numbers when number is at least 8
|
|
6
|
+
show numbers
|
|
7
|
+
|
|
8
|
+
remember values as list with 3, 1, 3, 2
|
|
9
|
+
remember uniqueValues as unique(values)
|
|
10
|
+
remember ordered as sort(values)
|
|
11
|
+
show uniqueValues
|
|
12
|
+
show ordered
|
|
13
|
+
|
|
14
|
+
remember profile as {name: "Ada", active: true}
|
|
15
|
+
show profile.name
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// PlainScript 1.0.2-latest: parallel operations and timeouts.
|
|
2
|
+
|
|
3
|
+
make firstJob()
|
|
4
|
+
wait for sleep(10)
|
|
5
|
+
give "first"
|
|
6
|
+
done
|
|
7
|
+
|
|
8
|
+
make secondJob()
|
|
9
|
+
wait for sleep(20)
|
|
10
|
+
give "second"
|
|
11
|
+
done
|
|
12
|
+
|
|
13
|
+
remember results as allOf(list with firstJob(), secondJob())
|
|
14
|
+
show results
|
|
15
|
+
|
|
16
|
+
remember quick as withTimeout(firstJob(), 1000)
|
|
17
|
+
show quick
|
|
18
|
+
run background secondJob()
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// PlainScript 1.0.2-latest: conditions and string predicates.
|
|
2
|
+
|
|
3
|
+
remember score as 87
|
|
4
|
+
remember label as "PlainScript"
|
|
5
|
+
|
|
6
|
+
if score is at least 90
|
|
7
|
+
show "excellent"
|
|
8
|
+
otherwise
|
|
9
|
+
if score more than 70
|
|
10
|
+
show "good"
|
|
11
|
+
otherwise
|
|
12
|
+
show "keep practicing"
|
|
13
|
+
done
|
|
14
|
+
done
|
|
15
|
+
|
|
16
|
+
if label contains "Script" and label starts with "Plain"
|
|
17
|
+
show "language found"
|
|
18
|
+
done
|
|
19
|
+
|
|
20
|
+
if label ends as "Script"
|
|
21
|
+
show "suffix matched"
|
|
22
|
+
done
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// PlainScript 1.0.2-latest: file and path operations.
|
|
2
|
+
|
|
3
|
+
remember report as readFile("README.md")
|
|
4
|
+
show length(report)
|
|
5
|
+
|
|
6
|
+
remember outputPath as joinPath("tmp", "report.txt")
|
|
7
|
+
writeFile(outputPath, "PlainScript report")
|
|
8
|
+
appendFile(outputPath, "\nready")
|
|
9
|
+
show fileExists(outputPath)
|
|
10
|
+
|
|
11
|
+
remember parts as split(outputPath, "/")
|
|
12
|
+
show parts
|
|
@@ -1,29 +1,31 @@
|
|
|
1
|
+
// PlainScript 1.0.2-latest: a complete authenticated SQLite API.
|
|
2
|
+
|
|
1
3
|
web app
|
|
2
|
-
database ":memory:"
|
|
4
|
+
database ":memory:" using "wasm"
|
|
3
5
|
enable sessions "touchline-session-secret"
|
|
4
6
|
remember coachHash as hashPassword("touchline")
|
|
5
7
|
|
|
6
8
|
execute
|
|
7
|
-
|
|
8
|
-
id
|
|
9
|
-
name
|
|
10
|
-
played
|
|
11
|
-
won
|
|
12
|
-
drawn
|
|
13
|
-
lost
|
|
9
|
+
CREATE TABLE teams (
|
|
10
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
11
|
+
name TEXT NOT NULL,
|
|
12
|
+
played INTEGER DEFAULT 0,
|
|
13
|
+
won INTEGER DEFAULT 0,
|
|
14
|
+
drawn INTEGER DEFAULT 0,
|
|
15
|
+
lost INTEGER DEFAULT 0
|
|
14
16
|
)
|
|
15
17
|
done
|
|
16
18
|
|
|
17
19
|
insert
|
|
18
|
-
|
|
19
|
-
(
|
|
20
|
-
(
|
|
21
|
-
(
|
|
20
|
+
INSERT INTO teams (name, played, won, drawn, lost) VALUES
|
|
21
|
+
("Thunder FC", 3, 2, 1, 0),
|
|
22
|
+
("Harbor City", 3, 1, 1, 1),
|
|
23
|
+
("Old Dock", 3, 0, 2, 1)
|
|
22
24
|
done
|
|
23
25
|
|
|
24
26
|
route post "/login"
|
|
25
|
-
remember
|
|
26
|
-
if
|
|
27
|
+
remember valid as checkPassword(password of body of request, coachHash)
|
|
28
|
+
if valid is true
|
|
27
29
|
user of session of request becomes username of body of request
|
|
28
30
|
reply json
|
|
29
31
|
token is createToken(username of body of request, "touchline-secret")
|
|
@@ -47,7 +49,7 @@ require api key from "coach-key-42"
|
|
|
47
49
|
|
|
48
50
|
route get "/teams"
|
|
49
51
|
remember rows as query
|
|
50
|
-
|
|
52
|
+
SELECT id, name, played, won, drawn, lost FROM teams ORDER BY name
|
|
51
53
|
done
|
|
52
54
|
reply json
|
|
53
55
|
teams is rows
|
|
@@ -55,15 +57,14 @@ route get "/teams"
|
|
|
55
57
|
done
|
|
56
58
|
|
|
57
59
|
route post "/teams"
|
|
58
|
-
remember missing as validate(body of request,
|
|
59
|
-
|
|
60
|
-
if problems is greater than 0
|
|
60
|
+
remember missing as validate(body of request, list with "name")
|
|
61
|
+
if length(missing) more than 0
|
|
61
62
|
status 400
|
|
62
63
|
reply missing
|
|
63
64
|
otherwise
|
|
64
65
|
remember teamName as name of body of request
|
|
65
66
|
insert
|
|
66
|
-
|
|
67
|
+
INSERT INTO teams (name, played, won, drawn, lost) VALUES ({teamName}, 0, 0, 0, 0)
|
|
67
68
|
done
|
|
68
69
|
reply json
|
|
69
70
|
added is teamName
|
|
@@ -73,7 +74,7 @@ done
|
|
|
73
74
|
|
|
74
75
|
route get "/standings"
|
|
75
76
|
remember rows as query
|
|
76
|
-
|
|
77
|
+
SELECT name, won, drawn, lost FROM teams ORDER BY won DESC, name
|
|
77
78
|
done
|
|
78
79
|
reply json
|
|
79
80
|
standings is rows
|
|
@@ -87,4 +88,4 @@ when nothing matches
|
|
|
87
88
|
done
|
|
88
89
|
done
|
|
89
90
|
|
|
90
|
-
start 0
|
|
91
|
+
start 0
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// PlainScript 1.0.2-latest: functions, defaults, and returns.
|
|
2
|
+
|
|
3
|
+
make greet(name)
|
|
4
|
+
give `Hello, ${name}!`
|
|
5
|
+
done
|
|
6
|
+
|
|
7
|
+
make add(a, b)
|
|
8
|
+
give a + b
|
|
9
|
+
done
|
|
10
|
+
|
|
11
|
+
make label(name as "guest")
|
|
12
|
+
give `User: ${name}`
|
|
13
|
+
done
|
|
14
|
+
|
|
15
|
+
show greet("Ada")
|
|
16
|
+
show add(2, 3)
|
|
17
|
+
show label()
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// PlainScript 1.0.2-latest: HTTP client requests.
|
|
2
|
+
|
|
3
|
+
remember response as get "https://example.com/api/items" timeout 5000
|
|
4
|
+
if response.ok is true
|
|
5
|
+
show response.data
|
|
6
|
+
otherwise
|
|
7
|
+
show response.status
|
|
8
|
+
done
|
|
9
|
+
|
|
10
|
+
remember created as post "https://example.com/api/items" with {name: "Ada"} headers {contentType: "application/json"}
|
|
11
|
+
show created.status
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
// PlainScript 1.0.2-latest: upload and OCR verification service.
|
|
2
|
+
|
|
1
3
|
web app
|
|
2
|
-
accept uploads limit "5 MB" allow
|
|
4
|
+
accept uploads limit "5 MB" allow list with "image/png", "image/jpeg" folder "uploads"
|
|
3
5
|
|
|
4
6
|
route post "/verify"
|
|
5
7
|
remember found as uploads("id")
|
|
6
|
-
|
|
7
|
-
if count is 0
|
|
8
|
+
if length(found) is 0
|
|
8
9
|
status 400
|
|
9
10
|
reply json
|
|
10
11
|
error is "Attach the ID image in the id field"
|
|
@@ -26,4 +27,4 @@ route post "/verify"
|
|
|
26
27
|
done
|
|
27
28
|
done
|
|
28
29
|
|
|
29
|
-
start 0
|
|
30
|
+
start 0
|
|
@@ -1,22 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
// Encodes a name as crisp black-on-white pixel text inside a valid PNG
|
|
5
|
-
// (hand-rolled encoder: zlib deflate + CRC32, no external packages).
|
|
6
|
-
//
|
|
7
|
-
// Usage:
|
|
8
|
-
// node make-sample-id.js writes sample-id.png ("ADA LOVELACE")
|
|
9
|
-
// node make-sample-id.js out.png "IDA CARD"
|
|
10
|
-
//
|
|
11
|
-
// As a module: const { createIdPng } = require('./make-sample-id')
|
|
2
|
+
// Dependency-free PNG generator used by the acceptance test.
|
|
12
3
|
|
|
13
4
|
'use strict';
|
|
5
|
+
|
|
14
6
|
const fs = require('fs');
|
|
15
7
|
const path = require('path');
|
|
16
8
|
const zlib = require('zlib');
|
|
17
9
|
|
|
18
|
-
// 5x7 pixel font. Each glyph is 7 rows; each row is a 5-bit number
|
|
19
|
-
// (bit 4 = leftmost column). Only the characters this sample needs.
|
|
20
10
|
const FONT = {
|
|
21
11
|
A: [14, 17, 17, 31, 17, 17, 17],
|
|
22
12
|
C: [14, 17, 16, 16, 16, 17, 14],
|
|
@@ -33,7 +23,7 @@ const FONT = {
|
|
|
33
23
|
|
|
34
24
|
const WIDTH = 480;
|
|
35
25
|
const HEIGHT = 160;
|
|
36
|
-
const SCALE = 6;
|
|
26
|
+
const SCALE = 6;
|
|
37
27
|
const MARGIN_X = 24;
|
|
38
28
|
const LINE_HEIGHT = 60;
|
|
39
29
|
|
|
@@ -41,7 +31,10 @@ function drawText(pixels, text, x0, y0) {
|
|
|
41
31
|
let x = x0;
|
|
42
32
|
for (const ch of text.toUpperCase()) {
|
|
43
33
|
const glyph = FONT[ch];
|
|
44
|
-
if (!glyph) {
|
|
34
|
+
if (!glyph) {
|
|
35
|
+
x += 6 * SCALE;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
45
38
|
for (let row = 0; row < 7; row++) {
|
|
46
39
|
for (let col = 0; col < 5; col++) {
|
|
47
40
|
if ((glyph[row] >> (4 - col)) & 1) {
|
|
@@ -50,19 +43,19 @@ function drawText(pixels, text, x0, y0) {
|
|
|
50
43
|
const px = x + col * SCALE + dx;
|
|
51
44
|
const py = y0 + row * SCALE + dy;
|
|
52
45
|
if (px >= 0 && px < WIDTH && py >= 0 && py < HEIGHT) {
|
|
53
|
-
const
|
|
54
|
-
pixels[
|
|
46
|
+
const index = (py * WIDTH + px) * 3;
|
|
47
|
+
pixels[index] = pixels[index + 1] = pixels[index + 2] = 0;
|
|
55
48
|
}
|
|
56
49
|
}
|
|
57
50
|
}
|
|
58
51
|
}
|
|
59
52
|
}
|
|
60
53
|
}
|
|
61
|
-
x += 6 * SCALE;
|
|
54
|
+
x += 6 * SCALE;
|
|
62
55
|
}
|
|
63
56
|
}
|
|
64
57
|
|
|
65
|
-
function crc32(
|
|
58
|
+
function crc32(buffer) {
|
|
66
59
|
let table = crc32.table;
|
|
67
60
|
if (!table) {
|
|
68
61
|
table = crc32.table = new Int32Array(256);
|
|
@@ -73,41 +66,35 @@ function crc32(buf) {
|
|
|
73
66
|
}
|
|
74
67
|
}
|
|
75
68
|
let crc = -1;
|
|
76
|
-
for (
|
|
69
|
+
for (const byte of buffer) crc = (crc >>> 8) ^ table[(crc ^ byte) & 0xff];
|
|
77
70
|
return (crc ^ -1) >>> 0;
|
|
78
71
|
}
|
|
79
72
|
|
|
80
73
|
function chunk(type, data) {
|
|
81
|
-
const
|
|
82
|
-
|
|
74
|
+
const length = Buffer.alloc(4);
|
|
75
|
+
length.writeUInt32BE(data.length);
|
|
83
76
|
const body = Buffer.concat([Buffer.from(type, 'ascii'), data]);
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
return Buffer.concat([
|
|
77
|
+
const checksum = Buffer.alloc(4);
|
|
78
|
+
checksum.writeUInt32BE(crc32(body));
|
|
79
|
+
return Buffer.concat([length, body, checksum]);
|
|
87
80
|
}
|
|
88
81
|
|
|
89
82
|
function createIdPng(lines) {
|
|
90
|
-
const pixels = Buffer.alloc(WIDTH * HEIGHT * 3, 255);
|
|
91
|
-
lines.forEach((line, index) =>
|
|
92
|
-
drawText(pixels, line, MARGIN_X, 24 + index * LINE_HEIGHT);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
// PNG scanlines: one filter byte (0 = None) per row.
|
|
83
|
+
const pixels = Buffer.alloc(WIDTH * HEIGHT * 3, 255);
|
|
84
|
+
lines.forEach((line, index) => drawText(pixels, line, MARGIN_X, 24 + index * LINE_HEIGHT));
|
|
96
85
|
const raw = Buffer.alloc(HEIGHT * (WIDTH * 3 + 1));
|
|
97
86
|
for (let y = 0; y < HEIGHT; y++) {
|
|
98
87
|
raw[y * (WIDTH * 3 + 1)] = 0;
|
|
99
88
|
pixels.copy(raw, y * (WIDTH * 3 + 1) + 1, y * WIDTH * 3, (y + 1) * WIDTH * 3);
|
|
100
89
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
ihdr[9] = 2; // color type: truecolor RGB
|
|
107
|
-
|
|
90
|
+
const header = Buffer.alloc(13);
|
|
91
|
+
header.writeUInt32BE(WIDTH, 0);
|
|
92
|
+
header.writeUInt32BE(HEIGHT, 4);
|
|
93
|
+
header[8] = 8;
|
|
94
|
+
header[9] = 2;
|
|
108
95
|
return Buffer.concat([
|
|
109
96
|
Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]),
|
|
110
|
-
chunk('IHDR',
|
|
97
|
+
chunk('IHDR', header),
|
|
111
98
|
chunk('IDAT', zlib.deflateSync(raw)),
|
|
112
99
|
chunk('IEND', Buffer.alloc(0)),
|
|
113
100
|
]);
|
|
@@ -116,8 +103,8 @@ function createIdPng(lines) {
|
|
|
116
103
|
module.exports = { createIdPng, FONT, WIDTH, HEIGHT, SCALE, MARGIN_X, LINE_HEIGHT };
|
|
117
104
|
|
|
118
105
|
if (require.main === module) {
|
|
119
|
-
const
|
|
106
|
+
const output = process.argv[2] || path.join(__dirname, 'sample-id.png');
|
|
120
107
|
const lines = process.argv.length > 3 ? process.argv.slice(3) : ['ADA LOVELACE', 'ID CARD'];
|
|
121
|
-
fs.writeFileSync(
|
|
122
|
-
console.log(`wrote ${
|
|
123
|
-
}
|
|
108
|
+
fs.writeFileSync(output, createIdPng(lines));
|
|
109
|
+
console.log(`wrote ${output}`);
|
|
110
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// PlainScript 1.0.2-latest: JSON values and transformations.
|
|
2
|
+
|
|
3
|
+
remember person as record with name "Ada" and role "engineer" done
|
|
4
|
+
|
|
5
|
+
remember encoded as jsonEncode(person)
|
|
6
|
+
remember decoded as jsonDecode(encoded)
|
|
7
|
+
show decoded.name
|
|
8
|
+
show decoded.role
|
|
9
|
+
|
|
10
|
+
remember payload as {ok: true, count: 2}
|
|
11
|
+
show jsonEncode(payload)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// PlainScript 1.0.2-latest: collection and numeric loops.
|
|
2
|
+
|
|
3
|
+
remember colors as list with "red", "green", "blue"
|
|
4
|
+
|
|
5
|
+
for each color in colors
|
|
6
|
+
show color
|
|
7
|
+
done
|
|
8
|
+
|
|
9
|
+
for index position from 0 to 2
|
|
10
|
+
show position
|
|
11
|
+
show colors at position 1
|
|
12
|
+
done
|
|
13
|
+
|
|
14
|
+
remember count as 0
|
|
15
|
+
while count is less than 3
|
|
16
|
+
show count
|
|
17
|
+
count becomes count + 1
|
|
18
|
+
done
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// PlainScript 1.0.2-latest: MongoDB.
|
|
2
|
+
//
|
|
3
|
+
// The `mongo` statement binds a connection to a MongoDB instance using the
|
|
4
|
+
// official `mongodb` driver. Give it a connection string and an optional
|
|
5
|
+
// database name:
|
|
6
|
+
//
|
|
7
|
+
// mongo "<connection-string>" [db "<name>"]
|
|
8
|
+
//
|
|
9
|
+
// After connecting, the `remember ... as query` and `insert`/`update`/`delete`
|
|
10
|
+
// blocks run against the bound database. MongoDB understands a light SQL-like
|
|
11
|
+
// subset here:
|
|
12
|
+
//
|
|
13
|
+
// - SELECT <fields|*> FROM <collection> (query)
|
|
14
|
+
// - INSERT INTO <collection> (a, b) VALUES (?, ?) (insert)
|
|
15
|
+
//
|
|
16
|
+
// Swap the connection string below for your own server to run this file.
|
|
17
|
+
|
|
18
|
+
mongo "mongodb://localhost:27017" db "testdb"
|
|
19
|
+
|
|
20
|
+
// Fetch every user document. The result of the query block is stored in the
|
|
21
|
+
// `users` variable so it can be inspected or returned later.
|
|
22
|
+
remember users as query
|
|
23
|
+
SELECT * FROM users
|
|
24
|
+
done
|
|
25
|
+
show users
|
|
26
|
+
|
|
27
|
+
// Insert a new user document from a PlainScript variable. Field names and the
|
|
28
|
+
// order they appear in VALUES must match the column list.
|
|
29
|
+
remember name as "Ada"
|
|
30
|
+
remember email as "ada@example.com"
|
|
31
|
+
insert
|
|
32
|
+
INSERT INTO users (name, email) VALUES ({name}, {email})
|
|
33
|
+
done
|