kadence-lang 0.2.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.
Files changed (67) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +208 -0
  3. package/bin/kadence.js +806 -0
  4. package/package.json +64 -0
  5. package/src/compiler.js +2291 -0
  6. package/src/vite-plugin-kadence.js +39 -0
  7. package/stdlib/check-helpers.js +13 -0
  8. package/stdlib/check.js +57 -0
  9. package/stdlib/check.kade +21 -0
  10. package/stdlib/color-helpers.js +34 -0
  11. package/stdlib/color.js +60 -0
  12. package/stdlib/color.kade +24 -0
  13. package/stdlib/console.js +57 -0
  14. package/stdlib/console.kade +21 -0
  15. package/stdlib/crypto-helpers.js +17 -0
  16. package/stdlib/crypto.js +46 -0
  17. package/stdlib/crypto.kade +11 -0
  18. package/stdlib/datetime.js +68 -0
  19. package/stdlib/datetime.kade +32 -0
  20. package/stdlib/encoding.js +55 -0
  21. package/stdlib/encoding.kade +19 -0
  22. package/stdlib/env.js +46 -0
  23. package/stdlib/env.kade +11 -0
  24. package/stdlib/file.js +94 -0
  25. package/stdlib/file.kade +57 -0
  26. package/stdlib/html.js +65 -0
  27. package/stdlib/html.kade +29 -0
  28. package/stdlib/json.js +63 -0
  29. package/stdlib/json.kade +28 -0
  30. package/stdlib/list.js +109 -0
  31. package/stdlib/list.kade +75 -0
  32. package/stdlib/math.js +76 -0
  33. package/stdlib/math.kade +39 -0
  34. package/stdlib/network.js +66 -0
  35. package/stdlib/network.kade +38 -0
  36. package/stdlib/number.js +53 -0
  37. package/stdlib/number.kade +17 -0
  38. package/stdlib/object-helpers.js +44 -0
  39. package/stdlib/object.js +59 -0
  40. package/stdlib/object.kade +23 -0
  41. package/stdlib/path.js +58 -0
  42. package/stdlib/path.kade +23 -0
  43. package/stdlib/process-helpers.js +18 -0
  44. package/stdlib/process.js +62 -0
  45. package/stdlib/process.kade +29 -0
  46. package/stdlib/promise-helpers.js +21 -0
  47. package/stdlib/promise.js +54 -0
  48. package/stdlib/promise.kade +19 -0
  49. package/stdlib/random.js +82 -0
  50. package/stdlib/random.kade +46 -0
  51. package/stdlib/regex-helpers.js +18 -0
  52. package/stdlib/regex.js +46 -0
  53. package/stdlib/regex.kade +11 -0
  54. package/stdlib/stream.js +58 -0
  55. package/stdlib/stream.kade +22 -0
  56. package/stdlib/string-helpers.js +16 -0
  57. package/stdlib/string.js +101 -0
  58. package/stdlib/string.kade +66 -0
  59. package/stdlib/system.js +66 -0
  60. package/stdlib/system.kade +31 -0
  61. package/stdlib/test-helpers.js +18 -0
  62. package/stdlib/test.js +72 -0
  63. package/stdlib/test.kade +37 -0
  64. package/stdlib/url.js +50 -0
  65. package/stdlib/url.kade +14 -0
  66. package/stdlib/uuid.js +70 -0
  67. package/stdlib/uuid.kade +35 -0
@@ -0,0 +1,39 @@
1
+ const { compile } = require("./compiler");
2
+
3
+ /**
4
+ * Vite plugin for Kadence (.kade) files
5
+ */
6
+ function kadencePlugin() {
7
+ return {
8
+ name: "vite-plugin-kadence",
9
+
10
+ transform(code, id) {
11
+ if (!id.endsWith(".kade")) {
12
+ return null;
13
+ }
14
+
15
+ // Compile Kadence to JS with Source Maps
16
+ const result = compile(code, {
17
+ target: "browser",
18
+ sourcemap: true,
19
+ sourceFile: id
20
+ });
21
+
22
+ return {
23
+ code: result.code,
24
+ map: result.map
25
+ };
26
+ },
27
+
28
+ handleHotUpdate({ file, server, read: _read }) {
29
+ if (file.endsWith(".kade")) {
30
+ server.ws.send({
31
+ type: "full-reload",
32
+ path: "*"
33
+ });
34
+ }
35
+ }
36
+ };
37
+ }
38
+
39
+ module.exports = { kadencePlugin };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ function isDefined(val) {
4
+ return val !== undefined;
5
+ }
6
+
7
+ function isNull(val) {
8
+ return val === null;
9
+ }
10
+
11
+ if (typeof module !== "undefined" && module.exports) {
12
+ module.exports = { isDefined, isNull };
13
+ }
@@ -0,0 +1,57 @@
1
+ const fs = require("fs");
2
+
3
+ function __kadence_echo(val) {
4
+ const s = String(val);
5
+ const low = s.toLowerCase();
6
+ if (typeof process !== 'undefined' && process.stdout && process.stdout.isTTY) {
7
+ if (low.includes('error')) console.log("\x1b[31m" + s + "\x1b[0m");
8
+ else if (low.includes('warning')) console.log("\x1b[33m" + s + "\x1b[0m");
9
+ else if (low.includes('success')) console.log("\x1b[32m" + s + "\x1b[0m");
10
+ else console.log(s);
11
+ } else {
12
+ console.log(s);
13
+ }
14
+ }
15
+ function __kadence_min(val) {
16
+ if (Array.isArray(val)) return Math.min(...val);
17
+ return val;
18
+ }
19
+ function __kadence_max(val) {
20
+ if (Array.isArray(val)) return Math.max(...val);
21
+ return val;
22
+ }
23
+ function __kadence_add(parent, child) {
24
+ if (Array.isArray(parent)) {
25
+ parent.push(child);
26
+ return parent;
27
+ }
28
+ if (typeof parent === 'object' && parent !== null && typeof parent.appendChild === 'function') {
29
+ parent.appendChild(child);
30
+ return parent;
31
+ }
32
+ throw new Error("Runtime Error: Cannot add item to " + typeof parent);
33
+ }
34
+
35
+ function isNumber (val) {
36
+ return typeof val === 'number';
37
+ }
38
+ if (typeof exports !== 'undefined') exports.isNumber = isNumber;
39
+ function isString (val) {
40
+ return typeof val === 'string';
41
+ }
42
+ if (typeof exports !== 'undefined') exports.isString = isString;
43
+ function isEmail (text) {
44
+ let helper = require(`./check-helpers.js`);
45
+ return helper.isEmail(text);
46
+ }
47
+ if (typeof exports !== 'undefined') exports.isEmail = isEmail;
48
+ function between (val, min, max) {
49
+ if (!((typeof val === 'number'))) {
50
+ return false;
51
+ }
52
+ return val >= min && val <= max ;
53
+ }
54
+ if (typeof exports !== 'undefined') exports.between = between;
55
+ (async () => {
56
+
57
+ })().catch(err => { if (err) console.error("\x1b[31mRuntime Error:\x1b[0m", err.stack || err.message); });
@@ -0,0 +1,21 @@
1
+ note: Validation utilities for Kadence
2
+
3
+ export function isNumber val
4
+ return val is a number
5
+ end
6
+
7
+ export function isString val
8
+ return val is a string
9
+ end
10
+
11
+ export function isEmail text
12
+ let helper = run require "./check-helpers.js"
13
+ return helper.isEmail(text)
14
+ end
15
+
16
+ export function between val min max
17
+ if not (val is a number)
18
+ return false
19
+ end
20
+ return val at least min and val at most max
21
+ end
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ function hexToRgb(hex) {
4
+ let s = hex.startsWith("#") ? hex.slice(1) : hex;
5
+ if (s.length !== 6) return "rgb(0, 0, 0)";
6
+ const r = parseInt(s.slice(0, 2), 16);
7
+ const g = parseInt(s.slice(2, 4), 16);
8
+ const b = parseInt(s.slice(4, 6), 16);
9
+ return `rgb(${r}, ${g}, ${b})`;
10
+ }
11
+
12
+ function lighten(color, percent) {
13
+ const match = color.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);
14
+ if (!match) return color;
15
+ const f = 1 + percent / 100;
16
+ const r = Math.min(255, Math.round(parseInt(match[1], 10) * f));
17
+ const g = Math.min(255, Math.round(parseInt(match[2], 10) * f));
18
+ const b = Math.min(255, Math.round(parseInt(match[3], 10) * f));
19
+ return color.startsWith("rgba") ? `rgba(${r}, ${g}, ${b}, 1)` : `rgb(${r}, ${g}, ${b})`;
20
+ }
21
+
22
+ function darken(color, percent) {
23
+ const match = color.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);
24
+ if (!match) return color;
25
+ const f = Math.max(0, 1 - percent / 100);
26
+ const r = Math.round(parseInt(match[1], 10) * f);
27
+ const g = Math.round(parseInt(match[2], 10) * f);
28
+ const b = Math.round(parseInt(match[3], 10) * f);
29
+ return color.startsWith("rgba") ? `rgba(${r}, ${g}, ${b}, 1)` : `rgb(${r}, ${g}, ${b})`;
30
+ }
31
+
32
+ if (typeof module !== "undefined" && module.exports) {
33
+ module.exports = { hexToRgb, lighten, darken };
34
+ }
@@ -0,0 +1,60 @@
1
+ const fs = require("fs");
2
+
3
+ function __kadence_echo(val) {
4
+ const s = String(val);
5
+ const low = s.toLowerCase();
6
+ if (typeof process !== 'undefined' && process.stdout && process.stdout.isTTY) {
7
+ if (low.includes('error')) console.log("\x1b[31m" + s + "\x1b[0m");
8
+ else if (low.includes('warning')) console.log("\x1b[33m" + s + "\x1b[0m");
9
+ else if (low.includes('success')) console.log("\x1b[32m" + s + "\x1b[0m");
10
+ else console.log(s);
11
+ } else {
12
+ console.log(s);
13
+ }
14
+ }
15
+ function __kadence_min(val) {
16
+ if (Array.isArray(val)) return Math.min(...val);
17
+ return val;
18
+ }
19
+ function __kadence_max(val) {
20
+ if (Array.isArray(val)) return Math.max(...val);
21
+ return val;
22
+ }
23
+ function __kadence_add(parent, child) {
24
+ if (Array.isArray(parent)) {
25
+ parent.push(child);
26
+ return parent;
27
+ }
28
+ if (typeof parent === 'object' && parent !== null && typeof parent.appendChild === 'function') {
29
+ parent.appendChild(child);
30
+ return parent;
31
+ }
32
+ throw new Error("Runtime Error: Cannot add item to " + typeof parent);
33
+ }
34
+
35
+ function rgb (r, g, b) {
36
+ return `rgb(` + r + `,` + g + `,` + b + `)` ;
37
+ }
38
+ if (typeof exports !== 'undefined') exports.rgb = rgb;
39
+ function rgba (r, g, b, a) {
40
+ return `rgba(` + r + `,` + g + `,` + b + `,` + a + `)` ;
41
+ }
42
+ if (typeof exports !== 'undefined') exports.rgba = rgba;
43
+ function hex (hexStr) {
44
+ let helper = require(`./color-helpers.js`);
45
+ return helper.hexToRgb(hexStr);
46
+ }
47
+ if (typeof exports !== 'undefined') exports.hex = hex;
48
+ function randomHex () {
49
+ let rand = require(`./random.js`);
50
+ let chars = [`0`, `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `a`, `b`, `c`, `d`, `e`, `f`];
51
+ let parts = [`#`];
52
+ for (let __i = 0; __i < 6; __i++) {
53
+ __kadence_add(parts, (rand.choice(chars)));
54
+ }
55
+ return parts.join(``);
56
+ }
57
+ if (typeof exports !== 'undefined') exports.randomHex = randomHex;
58
+ (async () => {
59
+
60
+ })().catch(err => { if (err) console.error("\x1b[31mRuntime Error:\x1b[0m", err.stack || err.message); });
@@ -0,0 +1,24 @@
1
+ note: Color utilities for Kadence
2
+
3
+ export function rgb r g b
4
+ return "rgb(" plus r plus "," plus g plus "," plus b plus ")"
5
+ end
6
+
7
+ export function rgba r g b a
8
+ return "rgba(" plus r plus "," plus g plus "," plus b plus "," plus a plus ")"
9
+ end
10
+
11
+ export function hex hexStr
12
+ let helper = run require "./color-helpers.js"
13
+ return run helper.hexToRgb hexStr
14
+ end
15
+
16
+ export function randomHex
17
+ let rand = run require "./random.js"
18
+ let chars = list "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "a" "b" "c" "d" "e" "f"
19
+ let parts = list "#"
20
+ repeat 6 times
21
+ add (run rand.choice chars) to parts
22
+ end
23
+ return join parts with ""
24
+ end
@@ -0,0 +1,57 @@
1
+ const fs = require("fs");
2
+
3
+ function __kadence_echo(val) {
4
+ const s = String(val);
5
+ const low = s.toLowerCase();
6
+ if (typeof process !== 'undefined' && process.stdout && process.stdout.isTTY) {
7
+ if (low.includes('error')) console.log("\x1b[31m" + s + "\x1b[0m");
8
+ else if (low.includes('warning')) console.log("\x1b[33m" + s + "\x1b[0m");
9
+ else if (low.includes('success')) console.log("\x1b[32m" + s + "\x1b[0m");
10
+ else console.log(s);
11
+ } else {
12
+ console.log(s);
13
+ }
14
+ }
15
+ function __kadence_min(val) {
16
+ if (Array.isArray(val)) return Math.min(...val);
17
+ return val;
18
+ }
19
+ function __kadence_max(val) {
20
+ if (Array.isArray(val)) return Math.max(...val);
21
+ return val;
22
+ }
23
+ function __kadence_add(parent, child) {
24
+ if (Array.isArray(parent)) {
25
+ parent.push(child);
26
+ return parent;
27
+ }
28
+ if (typeof parent === 'object' && parent !== null && typeof parent.appendChild === 'function') {
29
+ parent.appendChild(child);
30
+ return parent;
31
+ }
32
+ throw new Error("Runtime Error: Cannot add item to " + typeof parent);
33
+ }
34
+
35
+ function log (message) {
36
+ console.log(message);
37
+ }
38
+ if (typeof exports !== 'undefined') exports.log = log;
39
+ function error (message) {
40
+ console.error(message);
41
+ }
42
+ if (typeof exports !== 'undefined') exports.error = error;
43
+ function red (text) {
44
+ return `\x1b[31m` + text + `\x1b[0m` ;
45
+ }
46
+ if (typeof exports !== 'undefined') exports.red = red;
47
+ function green (text) {
48
+ return `\x1b[32m` + text + `\x1b[0m` ;
49
+ }
50
+ if (typeof exports !== 'undefined') exports.green = green;
51
+ function bold (text) {
52
+ return `\x1b[1m` + text + `\x1b[0m` ;
53
+ }
54
+ if (typeof exports !== 'undefined') exports.bold = bold;
55
+ (async () => {
56
+
57
+ })().catch(err => { if (err) console.error("\x1b[31mRuntime Error:\x1b[0m", err.stack || err.message); });
@@ -0,0 +1,21 @@
1
+ note: Console and terminal styling for Kadence
2
+
3
+ export function log message
4
+ console.log(message)
5
+ end
6
+
7
+ export function error message
8
+ console.error(message)
9
+ end
10
+
11
+ export function red text
12
+ return "\x1b[31m" plus text plus "\x1b[0m"
13
+ end
14
+
15
+ export function green text
16
+ return "\x1b[32m" plus text plus "\x1b[0m"
17
+ end
18
+
19
+ export function bold text
20
+ return "\x1b[1m" plus text plus "\x1b[0m"
21
+ end
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ const crypto = typeof require !== "undefined" ? require("crypto") : null;
4
+
5
+ function hash(str, algorithm = "sha256") {
6
+ if (!crypto) throw new Error("crypto module requires Node.js");
7
+ return crypto.createHash(algorithm).update(String(str), "utf8").digest("hex");
8
+ }
9
+
10
+ function randomBytes(n) {
11
+ if (!crypto) throw new Error("crypto module requires Node.js");
12
+ return crypto.randomBytes(n).toString("hex");
13
+ }
14
+
15
+ if (typeof module !== "undefined" && module.exports) {
16
+ module.exports = { hash, randomBytes };
17
+ }
@@ -0,0 +1,46 @@
1
+ const fs = require("fs");
2
+
3
+ function __kadence_echo(val) {
4
+ const s = String(val);
5
+ const low = s.toLowerCase();
6
+ if (typeof process !== 'undefined' && process.stdout && process.stdout.isTTY) {
7
+ if (low.includes('error')) console.log("\x1b[31m" + s + "\x1b[0m");
8
+ else if (low.includes('warning')) console.log("\x1b[33m" + s + "\x1b[0m");
9
+ else if (low.includes('success')) console.log("\x1b[32m" + s + "\x1b[0m");
10
+ else console.log(s);
11
+ } else {
12
+ console.log(s);
13
+ }
14
+ }
15
+ function __kadence_min(val) {
16
+ if (Array.isArray(val)) return Math.min(...val);
17
+ return val;
18
+ }
19
+ function __kadence_max(val) {
20
+ if (Array.isArray(val)) return Math.max(...val);
21
+ return val;
22
+ }
23
+ function __kadence_add(parent, child) {
24
+ if (Array.isArray(parent)) {
25
+ parent.push(child);
26
+ return parent;
27
+ }
28
+ if (typeof parent === 'object' && parent !== null && typeof parent.appendChild === 'function') {
29
+ parent.appendChild(child);
30
+ return parent;
31
+ }
32
+ throw new Error("Runtime Error: Cannot add item to " + typeof parent);
33
+ }
34
+
35
+ let mod = require(`./crypto-helpers.js`);
36
+ function hash (str) {
37
+ return mod.hash(str);
38
+ }
39
+ if (typeof exports !== 'undefined') exports.hash = hash;
40
+ function randomBytes (n) {
41
+ return mod.randomBytes(n);
42
+ }
43
+ if (typeof exports !== 'undefined') exports.randomBytes = randomBytes;
44
+ (async () => {
45
+
46
+ })().catch(err => { if (err) console.error("\x1b[31mRuntime Error:\x1b[0m", err.stack || err.message); });
@@ -0,0 +1,11 @@
1
+ note: Crypto utilities for Kadence (uses crypto-helpers.js)
2
+
3
+ let mod = run require "./crypto-helpers.js"
4
+
5
+ export function hash str
6
+ return run mod.hash str
7
+ end
8
+
9
+ export function randomBytes n
10
+ return run mod.randomBytes n
11
+ end
@@ -0,0 +1,68 @@
1
+ const fs = require("fs");
2
+
3
+ function __kadence_echo(val) {
4
+ const s = String(val);
5
+ const low = s.toLowerCase();
6
+ if (typeof process !== 'undefined' && process.stdout && process.stdout.isTTY) {
7
+ if (low.includes('error')) console.log("\x1b[31m" + s + "\x1b[0m");
8
+ else if (low.includes('warning')) console.log("\x1b[33m" + s + "\x1b[0m");
9
+ else if (low.includes('success')) console.log("\x1b[32m" + s + "\x1b[0m");
10
+ else console.log(s);
11
+ } else {
12
+ console.log(s);
13
+ }
14
+ }
15
+ function __kadence_min(val) {
16
+ if (Array.isArray(val)) return Math.min(...val);
17
+ return val;
18
+ }
19
+ function __kadence_max(val) {
20
+ if (Array.isArray(val)) return Math.max(...val);
21
+ return val;
22
+ }
23
+ function __kadence_add(parent, child) {
24
+ if (Array.isArray(parent)) {
25
+ parent.push(child);
26
+ return parent;
27
+ }
28
+ if (typeof parent === 'object' && parent !== null && typeof parent.appendChild === 'function') {
29
+ parent.appendChild(child);
30
+ return parent;
31
+ }
32
+ throw new Error("Runtime Error: Cannot add item to " + typeof parent);
33
+ }
34
+
35
+ function currentTime () {
36
+ return new Date();
37
+ }
38
+ if (typeof exports !== 'undefined') exports.currentTime = currentTime;
39
+ function today () {
40
+ return new Date();
41
+ }
42
+ if (typeof exports !== 'undefined') exports.today = today;
43
+ function year (d) {
44
+ return d.getFullYear();
45
+ }
46
+ if (typeof exports !== 'undefined') exports.year = year;
47
+ function month (d) {
48
+ let m = d.getMonth();
49
+ return m + 1 ;
50
+ }
51
+ if (typeof exports !== 'undefined') exports.month = month;
52
+ function day (d) {
53
+ return d.getDate();
54
+ }
55
+ if (typeof exports !== 'undefined') exports.day = day;
56
+ function toIso (d) {
57
+ return d.toISOString();
58
+ }
59
+ if (typeof exports !== 'undefined') exports.toIso = toIso;
60
+ function addDays (d, n) {
61
+ let result = new Date(d);
62
+ result.setDate(result.getDate() + n );
63
+ return result;
64
+ }
65
+ if (typeof exports !== 'undefined') exports.addDays = addDays;
66
+ (async () => {
67
+
68
+ })().catch(err => { if (err) console.error("\x1b[31mRuntime Error:\x1b[0m", err.stack || err.message); });
@@ -0,0 +1,32 @@
1
+ note: Date and time utilities for Kadence
2
+
3
+ export function currentTime
4
+ return new Date()
5
+ end
6
+
7
+ export function today
8
+ return new Date()
9
+ end
10
+
11
+ export function year d
12
+ return d.getFullYear()
13
+ end
14
+
15
+ export function month d
16
+ let m = d.getMonth()
17
+ return m + 1
18
+ end
19
+
20
+ export function day d
21
+ return d.getDate()
22
+ end
23
+
24
+ export function toIso d
25
+ return d.toISOString()
26
+ end
27
+
28
+ export function addDays d n
29
+ let result = new Date(d)
30
+ result.setDate(result.getDate() + n)
31
+ return result
32
+ end
@@ -0,0 +1,55 @@
1
+ const fs = require("fs");
2
+
3
+ function __kadence_echo(val) {
4
+ const s = String(val);
5
+ const low = s.toLowerCase();
6
+ if (typeof process !== 'undefined' && process.stdout && process.stdout.isTTY) {
7
+ if (low.includes('error')) console.log("\x1b[31m" + s + "\x1b[0m");
8
+ else if (low.includes('warning')) console.log("\x1b[33m" + s + "\x1b[0m");
9
+ else if (low.includes('success')) console.log("\x1b[32m" + s + "\x1b[0m");
10
+ else console.log(s);
11
+ } else {
12
+ console.log(s);
13
+ }
14
+ }
15
+ function __kadence_min(val) {
16
+ if (Array.isArray(val)) return Math.min(...val);
17
+ return val;
18
+ }
19
+ function __kadence_max(val) {
20
+ if (Array.isArray(val)) return Math.max(...val);
21
+ return val;
22
+ }
23
+ function __kadence_add(parent, child) {
24
+ if (Array.isArray(parent)) {
25
+ parent.push(child);
26
+ return parent;
27
+ }
28
+ if (typeof parent === 'object' && parent !== null && typeof parent.appendChild === 'function') {
29
+ parent.appendChild(child);
30
+ return parent;
31
+ }
32
+ throw new Error("Runtime Error: Cannot add item to " + typeof parent);
33
+ }
34
+
35
+ function base64Encode (str) {
36
+ let buf = Buffer[`from`](str, `utf8`);
37
+ return buf.toString(`base64`);
38
+ }
39
+ if (typeof exports !== 'undefined') exports.base64Encode = base64Encode;
40
+ function base64Decode (str) {
41
+ let buf = Buffer[`from`](str, `base64`);
42
+ return buf.toString(`utf8`);
43
+ }
44
+ if (typeof exports !== 'undefined') exports.base64Decode = base64Decode;
45
+ function urlEncode (str) {
46
+ return encodeURIComponent(str);
47
+ }
48
+ if (typeof exports !== 'undefined') exports.urlEncode = urlEncode;
49
+ function urlDecode (str) {
50
+ return decodeURIComponent(str);
51
+ }
52
+ if (typeof exports !== 'undefined') exports.urlDecode = urlDecode;
53
+ (async () => {
54
+
55
+ })().catch(err => { if (err) console.error("\x1b[31mRuntime Error:\x1b[0m", err.stack || err.message); });
@@ -0,0 +1,19 @@
1
+ note: Encoding utilities for Kadence
2
+
3
+ export function base64Encode str
4
+ let buf = run Buffer["from"] str "utf8"
5
+ return run buf.toString "base64"
6
+ end
7
+
8
+ export function base64Decode str
9
+ let buf = run Buffer["from"] str "base64"
10
+ return run buf.toString "utf8"
11
+ end
12
+
13
+ export function urlEncode str
14
+ return run encodeURIComponent str
15
+ end
16
+
17
+ export function urlDecode str
18
+ return run decodeURIComponent str
19
+ end
package/stdlib/env.js ADDED
@@ -0,0 +1,46 @@
1
+ const fs = require("fs");
2
+
3
+ function __kadence_echo(val) {
4
+ const s = String(val);
5
+ const low = s.toLowerCase();
6
+ if (typeof process !== 'undefined' && process.stdout && process.stdout.isTTY) {
7
+ if (low.includes('error')) console.log("\x1b[31m" + s + "\x1b[0m");
8
+ else if (low.includes('warning')) console.log("\x1b[33m" + s + "\x1b[0m");
9
+ else if (low.includes('success')) console.log("\x1b[32m" + s + "\x1b[0m");
10
+ else console.log(s);
11
+ } else {
12
+ console.log(s);
13
+ }
14
+ }
15
+ function __kadence_min(val) {
16
+ if (Array.isArray(val)) return Math.min(...val);
17
+ return val;
18
+ }
19
+ function __kadence_max(val) {
20
+ if (Array.isArray(val)) return Math.max(...val);
21
+ return val;
22
+ }
23
+ function __kadence_add(parent, child) {
24
+ if (Array.isArray(parent)) {
25
+ parent.push(child);
26
+ return parent;
27
+ }
28
+ if (typeof parent === 'object' && parent !== null && typeof parent.appendChild === 'function') {
29
+ parent.appendChild(child);
30
+ return parent;
31
+ }
32
+ throw new Error("Runtime Error: Cannot add item to " + typeof parent);
33
+ }
34
+
35
+ let processMod = require(`process`);
36
+ function getEnv (name) {
37
+ return processMod.env[name];
38
+ }
39
+ if (typeof exports !== 'undefined') exports.getEnv = getEnv;
40
+ function hasEnv (name) {
41
+ return (getEnv(name)) !== undefined ;
42
+ }
43
+ if (typeof exports !== 'undefined') exports.hasEnv = hasEnv;
44
+ (async () => {
45
+
46
+ })().catch(err => { if (err) console.error("\x1b[31mRuntime Error:\x1b[0m", err.stack || err.message); });
@@ -0,0 +1,11 @@
1
+ note: Environment variable utilities
2
+
3
+ let processMod = run require "process"
4
+
5
+ export function getEnv name
6
+ return processMod.env[name]
7
+ end
8
+
9
+ export function hasEnv name
10
+ return (run getEnv name) not equals undefined
11
+ end