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
package/stdlib/file.js ADDED
@@ -0,0 +1,94 @@
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 fsMod = require(`fs`);
36
+ function listDir (path) {
37
+ return fsMod.readdirSync(path);
38
+ }
39
+ if (typeof exports !== 'undefined') exports.listDir = listDir;
40
+ function exists (path) {
41
+ return fsMod.existsSync(path);
42
+ }
43
+ if (typeof exports !== 'undefined') exports.exists = exists;
44
+ function mkdir (path) {
45
+ fsMod.mkdirSync(path);
46
+ }
47
+ if (typeof exports !== 'undefined') exports.mkdir = mkdir;
48
+ function append (path, content) {
49
+ fsMod.appendFileSync(path, content);
50
+ }
51
+ if (typeof exports !== 'undefined') exports.append = append;
52
+ function unlink (path) {
53
+ fsMod.unlinkSync(path);
54
+ }
55
+ if (typeof exports !== 'undefined') exports.unlink = unlink;
56
+ function readFile (path) {
57
+ return fsMod.readFileSync(path, `utf8`);
58
+ }
59
+ if (typeof exports !== 'undefined') exports.readFile = readFile;
60
+ function writeFile (path, content) {
61
+ fsMod.writeFileSync(path, content);
62
+ }
63
+ if (typeof exports !== 'undefined') exports.writeFile = writeFile;
64
+ function copyFile (src, dest) {
65
+ fsMod.copyFileSync(src, dest);
66
+ }
67
+ if (typeof exports !== 'undefined') exports.copyFile = copyFile;
68
+ function removeDir (path) {
69
+ fsMod.rmSync(path);
70
+ { recursive: true, force: true };
71
+ }
72
+ if (typeof exports !== 'undefined') exports.removeDir = removeDir;
73
+ function copyDir (src, dest) {
74
+ fsMod.cpSync(src, dest);
75
+ { recursive: true };
76
+ }
77
+ if (typeof exports !== 'undefined') exports.copyDir = copyDir;
78
+ function stat (path) {
79
+ return fsMod.statSync(path);
80
+ }
81
+ if (typeof exports !== 'undefined') exports.stat = stat;
82
+ function isDirectory (path) {
83
+ let s = stat(path);
84
+ return s.isDirectory();
85
+ }
86
+ if (typeof exports !== 'undefined') exports.isDirectory = isDirectory;
87
+ function isFile (path) {
88
+ let s = stat(path);
89
+ return s.isFile();
90
+ }
91
+ if (typeof exports !== 'undefined') exports.isFile = isFile;
92
+ (async () => {
93
+
94
+ })().catch(err => { if (err) console.error("\x1b[31mRuntime Error:\x1b[0m", err.stack || err.message); });
@@ -0,0 +1,57 @@
1
+ note: File system utilities for Kadence (uses Node fs)
2
+
3
+ let fsMod = run require "fs"
4
+
5
+ export function listDir path
6
+ return run fsMod.readdirSync path
7
+ end
8
+
9
+ export function exists path
10
+ return run fsMod.existsSync path
11
+ end
12
+
13
+ export function mkdir path
14
+ run fsMod.mkdirSync path
15
+ end
16
+
17
+ export function append path content
18
+ run fsMod.appendFileSync path content
19
+ end
20
+
21
+ export function unlink path
22
+ run fsMod.unlinkSync path
23
+ end
24
+
25
+ export function readFile path
26
+ return run fsMod.readFileSync path "utf8"
27
+ end
28
+
29
+ export function writeFile path content
30
+ run fsMod.writeFileSync path content
31
+ end
32
+
33
+ export function copyFile src dest
34
+ run fsMod.copyFileSync src dest
35
+ end
36
+
37
+ export function removeDir path
38
+ run fsMod.rmSync path { recursive: true, force: true }
39
+ end
40
+
41
+ export function copyDir src dest
42
+ run fsMod.cpSync src dest { recursive: true }
43
+ end
44
+
45
+ export function stat path
46
+ return run fsMod.statSync path
47
+ end
48
+
49
+ export function isDirectory path
50
+ let s = run stat path
51
+ return s.isDirectory()
52
+ end
53
+
54
+ export function isFile path
55
+ let s = run stat path
56
+ return s.isFile()
57
+ end
package/stdlib/html.js ADDED
@@ -0,0 +1,65 @@
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 tag (name, content) {
36
+ return `<` + name + `>` + content + `</` + name + `>` ;
37
+ }
38
+ if (typeof exports !== 'undefined') exports.tag = tag;
39
+ function div (content) {
40
+ return tag(`div`, content);
41
+ }
42
+ if (typeof exports !== 'undefined') exports.div = div;
43
+ function span (content) {
44
+ return tag(`span`, content);
45
+ }
46
+ if (typeof exports !== 'undefined') exports.span = span;
47
+ function p (content) {
48
+ return tag(`p`, content);
49
+ }
50
+ if (typeof exports !== 'undefined') exports.p = p;
51
+ function h1 (content) {
52
+ return tag(`h1`, content);
53
+ }
54
+ if (typeof exports !== 'undefined') exports.h1 = h1;
55
+ function link (content) {
56
+ return tag(`a`, content);
57
+ }
58
+ if (typeof exports !== 'undefined') exports.link = link;
59
+ function img (content) {
60
+ return tag(`img`, content);
61
+ }
62
+ if (typeof exports !== 'undefined') exports.img = img;
63
+ (async () => {
64
+
65
+ })().catch(err => { if (err) console.error("\x1b[31mRuntime Error:\x1b[0m", err.stack || err.message); });
@@ -0,0 +1,29 @@
1
+ note: HTML tag helpers for Kadence
2
+
3
+ export function tag name content
4
+ return "<" plus name plus ">" plus content plus "</" plus name plus ">"
5
+ end
6
+
7
+ export function div content
8
+ return run tag "div" content
9
+ end
10
+
11
+ export function span content
12
+ return run tag "span" content
13
+ end
14
+
15
+ export function p content
16
+ return run tag "p" content
17
+ end
18
+
19
+ export function h1 content
20
+ return run tag "h1" content
21
+ end
22
+
23
+ export function link content
24
+ return run tag "a" content
25
+ end
26
+
27
+ export function img content
28
+ return run tag "img" content
29
+ end
package/stdlib/json.js ADDED
@@ -0,0 +1,63 @@
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 fsMod = require(`fs`);
36
+ function readJson (path) {
37
+ if (!((fsMod.existsSync(path)))) {
38
+ return null;
39
+ }
40
+ let content = fsMod.readFileSync(path, `utf8`);
41
+ return JSON.parse(content);
42
+ }
43
+ if (typeof exports !== 'undefined') exports.readJson = readJson;
44
+ function writeJson (path, data) {
45
+ let str = JSON.stringify(data);
46
+ fsMod.writeFileSync(path, str);
47
+ }
48
+ if (typeof exports !== 'undefined') exports.writeJson = writeJson;
49
+ function format (data) {
50
+ return JSON.stringify(data, null, 2);
51
+ }
52
+ if (typeof exports !== 'undefined') exports.format = format;
53
+ function parseSafe (text) {
54
+ try {
55
+ return JSON.parse(text);
56
+ } catch(e) {
57
+ return null;
58
+ }
59
+ }
60
+ if (typeof exports !== 'undefined') exports.parseSafe = parseSafe;
61
+ (async () => {
62
+
63
+ })().catch(err => { if (err) console.error("\x1b[31mRuntime Error:\x1b[0m", err.stack || err.message); });
@@ -0,0 +1,28 @@
1
+ note: JSON utilities for Kadence
2
+
3
+ let fsMod = run require "fs"
4
+
5
+ export function readJson path
6
+ if not (run fsMod.existsSync path)
7
+ return null
8
+ end
9
+ let content = run fsMod.readFileSync path "utf8"
10
+ return parse json from content
11
+ end
12
+
13
+ export function writeJson path data
14
+ let str = stringify data to json
15
+ run fsMod.writeFileSync path str
16
+ end
17
+
18
+ export function format data
19
+ return JSON.stringify(data, null, 2)
20
+ end
21
+
22
+ export function parseSafe text
23
+ try
24
+ return parse json from text
25
+ catch e
26
+ return null
27
+ end
28
+ end
package/stdlib/list.js ADDED
@@ -0,0 +1,109 @@
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 first (array) {
36
+ return array[0];
37
+ }
38
+ if (typeof exports !== 'undefined') exports.first = first;
39
+ function lastOf (array) {
40
+ let n = array.length;
41
+ let idx = n - 1 ;
42
+ return array[idx];
43
+ }
44
+ if (typeof exports !== 'undefined') exports.lastOf = lastOf;
45
+ function isEmpty (array) {
46
+ let len = array.length;
47
+ return len === 0 ;
48
+ }
49
+ if (typeof exports !== 'undefined') exports.isEmpty = isEmpty;
50
+ function length (array) {
51
+ return array.length;
52
+ }
53
+ if (typeof exports !== 'undefined') exports.length = length;
54
+ function contains (array, itemToFind) {
55
+ let found = false;
56
+ for (let x of array) {
57
+ if (x === itemToFind ) {
58
+ let found = true;
59
+ }
60
+ }
61
+ return found;
62
+ }
63
+ if (typeof exports !== 'undefined') exports.contains = contains;
64
+ function unique (array) {
65
+ let result = [];
66
+ for (let x of array) {
67
+ let found = false;
68
+ for (let r of result) {
69
+ if (r === x ) {
70
+ found = true;
71
+ }
72
+ }
73
+ if (!(found)) {
74
+ __kadence_add(result, x);
75
+ }
76
+ }
77
+ return result;
78
+ }
79
+ if (typeof exports !== 'undefined') exports.unique = unique;
80
+ function shuffle (array) {
81
+ let output = [];
82
+ for (let x of array) {
83
+ __kadence_add(output, x);
84
+ }
85
+ let i = (output.length) - 1 ;
86
+ while (i > 0 ) {
87
+ let rand = require(`./random.js`);
88
+ let j = rand.int(0, (i + 1 ));
89
+ let temp = output[i];
90
+ output[i] = output[j];
91
+ output[j] = temp;
92
+ i--;
93
+ }
94
+ return output;
95
+ }
96
+ if (typeof exports !== 'undefined') exports.shuffle = shuffle;
97
+ function makeRange (start, endNum) {
98
+ let result = [];
99
+ let current = start;
100
+ while (current < (endNum + 1 ) ) {
101
+ __kadence_add(result, current);
102
+ current++;
103
+ }
104
+ return result;
105
+ }
106
+ if (typeof exports !== 'undefined') exports.makeRange = makeRange;
107
+ (async () => {
108
+
109
+ })().catch(err => { if (err) console.error("\x1b[31mRuntime Error:\x1b[0m", err.stack || err.message); });
@@ -0,0 +1,75 @@
1
+ note: List utilities for Kadence
2
+
3
+ export function first array
4
+ return array[0]
5
+ end
6
+
7
+ export function lastOf array
8
+ let n = size of array
9
+ let idx = n minus 1
10
+ return array[idx]
11
+ end
12
+
13
+ export function isEmpty array
14
+ let len = size of array
15
+ return len equals 0
16
+ end
17
+
18
+ export function length array
19
+ return size of array
20
+ end
21
+
22
+ export function contains array itemToFind
23
+ let found = false
24
+ for each x in array
25
+ if x equals itemToFind
26
+ let found = true
27
+ end
28
+ end
29
+ return found
30
+ end
31
+
32
+ export function unique array
33
+ let result = list
34
+ for each x in array
35
+ let found = false
36
+ for each r in result
37
+ if r equals x
38
+ found = true
39
+ end
40
+ end
41
+ if not found
42
+ add x to result
43
+ end
44
+ end
45
+ return result
46
+ end
47
+ export function shuffle array
48
+ let output = list
49
+ for each x in array
50
+ add x to output
51
+ end
52
+
53
+ let i = (size of output) minus 1
54
+ while i more than 0
55
+ let rand = run require "./random.js"
56
+ let j = run rand.int 0 (i plus 1)
57
+
58
+ let temp = output[i]
59
+ output[i] = output[j]
60
+ output[j] = temp
61
+
62
+ decrement i
63
+ end
64
+ return output
65
+ end
66
+
67
+ export function makeRange start endNum
68
+ let result = list
69
+ let current = start
70
+ while current less than (endNum plus 1)
71
+ add current to result
72
+ increment current
73
+ end
74
+ return result
75
+ end
package/stdlib/math.js ADDED
@@ -0,0 +1,76 @@
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 hypotenuse (a, b) {
36
+ return Math.sqrt(((a * a ) + (b * b ) ));
37
+ }
38
+ if (typeof exports !== 'undefined') exports.hypotenuse = hypotenuse;
39
+ function areaOfCircle (radius) {
40
+ return Math.PI * radius * radius ;
41
+ }
42
+ if (typeof exports !== 'undefined') exports.areaOfCircle = areaOfCircle;
43
+ function isEven (n) {
44
+ if ((n / 2) * 2 === n ) {
45
+ return true;
46
+ } else {
47
+ return false;
48
+ }
49
+ }
50
+ if (typeof exports !== 'undefined') exports.isEven = isEven;
51
+ function clamp (val, minVal, maxVal) {
52
+ if (val < minVal ) {
53
+ return minVal;
54
+ } else if (val > maxVal ) {
55
+ return maxVal;
56
+ } else {
57
+ return val;
58
+ }
59
+ }
60
+ if (typeof exports !== 'undefined') exports.clamp = clamp;
61
+ function randomFloat (min, max) {
62
+ let r = Math.random();
63
+ return min + (r * (max - min ) ) ;
64
+ }
65
+ if (typeof exports !== 'undefined') exports.randomFloat = randomFloat;
66
+ function toRadians (deg) {
67
+ return deg * (Math.PI / 180) ;
68
+ }
69
+ if (typeof exports !== 'undefined') exports.toRadians = toRadians;
70
+ function toDegrees (rad) {
71
+ return rad * (180 / Math.PI) ;
72
+ }
73
+ if (typeof exports !== 'undefined') exports.toDegrees = toDegrees;
74
+ (async () => {
75
+
76
+ })().catch(err => { if (err) console.error("\x1b[31mRuntime Error:\x1b[0m", err.stack || err.message); });
@@ -0,0 +1,39 @@
1
+ note: Math utilities for Kadence
2
+
3
+ export function hypotenuse a b
4
+ return square root ((a * a) plus (b * b))
5
+ end
6
+
7
+ export function areaOfCircle radius
8
+ return pi * radius * radius
9
+ end
10
+
11
+ export function isEven n
12
+ if (n / 2) * 2 equals n
13
+ return true
14
+ else
15
+ return false
16
+ end
17
+ end
18
+
19
+ export function clamp val minVal maxVal
20
+ if val less than minVal
21
+ return minVal
22
+ elif val more than maxVal
23
+ return maxVal
24
+ else
25
+ return val
26
+ end
27
+ end
28
+ export function randomFloat min max
29
+ let r = random
30
+ return min plus (r * (max minus min))
31
+ end
32
+
33
+ export function toRadians deg
34
+ return deg * (pi / 180)
35
+ end
36
+
37
+ export function toDegrees rad
38
+ return rad * (180 / pi)
39
+ end
@@ -0,0 +1,66 @@
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 http = require(`http`);
36
+ function serve (port, handler) {
37
+ let server = http.createServer((req, res) => {
38
+ let response = { send: (body) => {
39
+ res.writeHead(200, { `Content-Type`: `text/plain` });
40
+ res.end(body);
41
+ } , json: (body) => {
42
+ res.writeHead(200, { `Content-Type`: `application/json` });
43
+ res.end(JSON.stringify(body));
44
+ } , html: (body) => {
45
+ res.writeHead(200, { `Content-Type`: `text/html` });
46
+ res.end(body);
47
+ } };
48
+ response.status = (code) => {
49
+ res.statusCode = code;
50
+ return response;
51
+ } ;
52
+ handler(req, response);
53
+ } );
54
+ server.listen(port, () => {
55
+ __kadence_echo(`Server running at http://localhost:${port}/`);
56
+ } );
57
+ }
58
+ if (typeof exports !== 'undefined') exports.serve = serve;
59
+ function fetchJson (url) {
60
+ let result = await fetch(url).then(r => r.json());
61
+ return result;
62
+ }
63
+ if (typeof exports !== 'undefined') exports.fetchJson = fetchJson;
64
+ (async () => {
65
+
66
+ })().catch(err => { if (err) console.error("\x1b[31mRuntime Error:\x1b[0m", err.stack || err.message); });