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,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(`./regex-helpers.js`);
36
+ function test (pattern, str) {
37
+ return mod.test(pattern, str);
38
+ }
39
+ if (typeof exports !== 'undefined') exports.test = test;
40
+ function replaceAll (pattern, str, replacement) {
41
+ return mod.replaceAll(pattern, str, replacement);
42
+ }
43
+ if (typeof exports !== 'undefined') exports.replaceAll = replaceAll;
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: Regex utilities for Kadence (uses regex-helpers.js)
2
+
3
+ let mod = run require "./regex-helpers.js"
4
+
5
+ export function test pattern str
6
+ return run mod.test pattern str
7
+ end
8
+
9
+ export function replaceAll pattern str replacement
10
+ return run mod.replaceAll pattern str replacement
11
+ end
@@ -0,0 +1,58 @@
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 createReader (stream) {
36
+ return stream.getReader();
37
+ }
38
+ if (typeof exports !== 'undefined') exports.createReader = createReader;
39
+ async function readAll (stream) {
40
+ let reader = createReader(stream);
41
+ let result = [];
42
+ while (true) {
43
+ let { done, value } = await reader.read();
44
+ if (done) {
45
+ break;
46
+ }
47
+ __kadence_add(result, value);
48
+ }
49
+ return result;
50
+ }
51
+ if (typeof exports !== 'undefined') exports.readAll = readAll;
52
+ function pipe (source, to, target) {
53
+ return source.pipeTo(target);
54
+ }
55
+ if (typeof exports !== 'undefined') exports.pipe = pipe;
56
+ (async () => {
57
+
58
+ })().catch(err => { if (err) console.error("\x1b[31mRuntime Error:\x1b[0m", err.stack || err.message); });
@@ -0,0 +1,22 @@
1
+ note: Stream utilities for Kadence.
2
+
3
+ export function createReader stream
4
+ return stream.getReader()
5
+ end
6
+
7
+ export async function readAll stream
8
+ let reader = run createReader stream
9
+ let result = list
10
+ while true
11
+ let { done, value } = await reader.read()
12
+ if done
13
+ break
14
+ end
15
+ add value to result
16
+ end
17
+ return result
18
+ end
19
+
20
+ export function pipe source to target
21
+ return source.pipeTo(target)
22
+ end
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ function escapeHtml(str) {
4
+ if (str == null) return "";
5
+ const s = String(str);
6
+ return s
7
+ .replace(/&/g, "&")
8
+ .replace(/</g, "&lt;")
9
+ .replace(/>/g, "&gt;")
10
+ .replace(/"/g, "&quot;")
11
+ .replace(/'/g, "&#39;");
12
+ }
13
+
14
+ if (typeof module !== "undefined" && module.exports) {
15
+ module.exports = { escapeHtml };
16
+ }
@@ -0,0 +1,101 @@
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 words (text) {
36
+ return text.split(` `);
37
+ }
38
+ if (typeof exports !== 'undefined') exports.words = words;
39
+ function lines (text) {
40
+ return text.split(`\n`);
41
+ }
42
+ if (typeof exports !== 'undefined') exports.lines = lines;
43
+ function trimmed (text) {
44
+ return text.trim();
45
+ }
46
+ if (typeof exports !== 'undefined') exports.trimmed = trimmed;
47
+ function capitalized (text) {
48
+ let len = text.length;
49
+ if (len === 0 ) {
50
+ return text;
51
+ }
52
+ let firstChar = ((text[0])).toString().toUpperCase();
53
+ if (text === 1 .length) {
54
+ return firstChar;
55
+ }
56
+ let parts = text.split(``);
57
+ let rest = [];
58
+ let idx = 1;
59
+ while (idx < parts.length ) {
60
+ __kadence_add(rest, parts[idx]);
61
+ idx++;
62
+ }
63
+ return firstChar + (rest.join(``)) ;
64
+ }
65
+ if (typeof exports !== 'undefined') exports.capitalized = capitalized;
66
+ function padStart (text, length, char) {
67
+ return text.padStart(length, char);
68
+ }
69
+ if (typeof exports !== 'undefined') exports.padStart = padStart;
70
+ function padEnd (text, length, char) {
71
+ return text.padEnd(length, char);
72
+ }
73
+ if (typeof exports !== 'undefined') exports.padEnd = padEnd;
74
+ function repeated (text, count) {
75
+ return text.repeat(count);
76
+ }
77
+ if (typeof exports !== 'undefined') exports.repeated = repeated;
78
+ function slice (text, start, endIdx) {
79
+ return text.slice(start, endIdx);
80
+ }
81
+ if (typeof exports !== 'undefined') exports.slice = slice;
82
+ function toCamelCase (text) {
83
+ let parts = text.split(` `);
84
+ if (parts === 1 .length) {
85
+ return (text).toString().toLowerCase();
86
+ }
87
+ let res = ((parts[0])).toString().toLowerCase();
88
+ let idx = 1;
89
+ while (idx < parts.length ) {
90
+ let part = parts[idx];
91
+ let first = ((part[0])).toString().toUpperCase();
92
+ let rest = slice(part, 1);
93
+ res = res + first + rest ;
94
+ idx++;
95
+ }
96
+ return res;
97
+ }
98
+ if (typeof exports !== 'undefined') exports.toCamelCase = toCamelCase;
99
+ (async () => {
100
+
101
+ })().catch(err => { if (err) console.error("\x1b[31mRuntime Error:\x1b[0m", err.stack || err.message); });
@@ -0,0 +1,66 @@
1
+ note: String utilities for Kadence
2
+
3
+ export function words text
4
+ return split text by " "
5
+ end
6
+
7
+ export function lines text
8
+ return split text by "\n"
9
+ end
10
+
11
+ export function trimmed text
12
+ return trim text
13
+ end
14
+
15
+ export function capitalized text
16
+ let len = size of text
17
+ if len equals 0
18
+ return text
19
+ end
20
+ let firstChar = uppercase (text[0])
21
+ if size of text equals 1
22
+ return firstChar
23
+ end
24
+ let parts = split text by ""
25
+ let rest = list
26
+ let idx = 1
27
+ while idx less than size of parts
28
+ add parts[idx] to rest
29
+ increment idx
30
+ end
31
+ return firstChar plus (join rest with "")
32
+ end
33
+
34
+ export function padStart text length char
35
+ return text.padStart(length, char)
36
+ end
37
+
38
+ export function padEnd text length char
39
+ return text.padEnd(length, char)
40
+ end
41
+
42
+ export function repeated text count
43
+ return text.repeat(count)
44
+ end
45
+
46
+ export function slice text start endIdx
47
+ return text.slice(start, endIdx)
48
+ end
49
+
50
+ export function toCamelCase text
51
+ let parts = split text by " "
52
+ if size of parts equals 1
53
+ return lowercase text
54
+ end
55
+
56
+ let res = lowercase (parts[0])
57
+ let idx = 1
58
+ while idx less than size of parts
59
+ let part = parts[idx]
60
+ let first = uppercase (part[0])
61
+ let rest = run slice part 1
62
+ set res to res plus first plus rest
63
+ increment idx
64
+ end
65
+ return res
66
+ 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 os = require(`os`);
36
+ function platform () {
37
+ return os.platform();
38
+ }
39
+ if (typeof exports !== 'undefined') exports.platform = platform;
40
+ function arch () {
41
+ return os.arch();
42
+ }
43
+ if (typeof exports !== 'undefined') exports.arch = arch;
44
+ function cpus () {
45
+ return os.cpus();
46
+ }
47
+ if (typeof exports !== 'undefined') exports.cpus = cpus;
48
+ function totalMemory () {
49
+ return os.totalmem();
50
+ }
51
+ if (typeof exports !== 'undefined') exports.totalMemory = totalMemory;
52
+ function freeMemory () {
53
+ return os.freemem();
54
+ }
55
+ if (typeof exports !== 'undefined') exports.freeMemory = freeMemory;
56
+ function homedir () {
57
+ return os.homedir();
58
+ }
59
+ if (typeof exports !== 'undefined') exports.homedir = homedir;
60
+ function hostname () {
61
+ return os.hostname();
62
+ }
63
+ if (typeof exports !== 'undefined') exports.hostname = hostname;
64
+ (async () => {
65
+
66
+ })().catch(err => { if (err) console.error("\x1b[31mRuntime Error:\x1b[0m", err.stack || err.message); });
@@ -0,0 +1,31 @@
1
+ note: System utilities
2
+
3
+ let os = run require "os"
4
+
5
+ export function platform
6
+ return run os.platform
7
+ end
8
+
9
+ export function arch
10
+ return run os.arch
11
+ end
12
+
13
+ export function cpus
14
+ return run os.cpus
15
+ end
16
+
17
+ export function totalMemory
18
+ return run os.totalmem
19
+ end
20
+
21
+ export function freeMemory
22
+ return run os.freemem
23
+ end
24
+
25
+ export function homedir
26
+ return run os.homedir
27
+ end
28
+
29
+ export function hostname
30
+ return run os.hostname
31
+ end
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Runs fn(); returns { threw: true, error } if it threw, { threw: false } otherwise.
5
+ * Used by test.assertThrows in Kadence.
6
+ */
7
+ function assertThrows(fn) {
8
+ try {
9
+ fn();
10
+ return { threw: false };
11
+ } catch (e) {
12
+ return { threw: true, error: e };
13
+ }
14
+ }
15
+
16
+ if (typeof module !== "undefined" && module.exports) {
17
+ module.exports = { assertThrows };
18
+ }
package/stdlib/test.js ADDED
@@ -0,0 +1,72 @@
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 term = require(`./console.js`);
36
+ function suite (name, callback) {
37
+ __kadence_echo(`Suite: ` + name );
38
+ if (callback !== undefined ) {
39
+ callback();
40
+ }
41
+ return true;
42
+ }
43
+ if (typeof exports !== 'undefined') exports.suite = suite;
44
+ function assertEquals (actual, expected, message) {
45
+ if (actual === expected ) {
46
+ let colored = term.green(`PASS`);
47
+ __kadence_echo(colored + `: ` + message );
48
+ return true;
49
+ } else {
50
+ let colored = term.red(`FAIL`);
51
+ __kadence_echo(colored + `: ` + message );
52
+ __kadence_echo(` Expected: ` + expected );
53
+ __kadence_echo(` Actual: ` + actual );
54
+ return false;
55
+ }
56
+ }
57
+ if (typeof exports !== 'undefined') exports.assertEquals = assertEquals;
58
+ function assertTrue (value, message) {
59
+ if (value) {
60
+ let colored = term.green(`PASS`);
61
+ __kadence_echo(colored + `: ` + message );
62
+ return true;
63
+ } else {
64
+ let colored = term.red(`FAIL`);
65
+ __kadence_echo(colored + `: ` + message );
66
+ return false;
67
+ }
68
+ }
69
+ if (typeof exports !== 'undefined') exports.assertTrue = assertTrue;
70
+ (async () => {
71
+
72
+ })().catch(err => { if (err) console.error("\x1b[31mRuntime Error:\x1b[0m", err.stack || err.message); });
@@ -0,0 +1,37 @@
1
+ note: Test utilities for Kadence
2
+
3
+ let term = run require "./console.js"
4
+
5
+ export function suite name callback
6
+ echo "Suite: " plus name
7
+ if callback not equals undefined
8
+ run callback
9
+ end
10
+ return true
11
+ end
12
+
13
+ export function assertEquals actual expected message
14
+ if actual equals expected
15
+ let colored = run term.green "PASS"
16
+ echo colored plus ": " plus message
17
+ return true
18
+ else
19
+ let colored = run term.red "FAIL"
20
+ echo colored plus ": " plus message
21
+ echo " Expected: " plus expected
22
+ echo " Actual: " plus actual
23
+ return false
24
+ end
25
+ end
26
+
27
+ export function assertTrue value message
28
+ if value
29
+ let colored = run term.green "PASS"
30
+ echo colored plus ": " plus message
31
+ return true
32
+ else
33
+ let colored = run term.red "FAIL"
34
+ echo colored plus ": " plus message
35
+ return false
36
+ end
37
+ end
package/stdlib/url.js ADDED
@@ -0,0 +1,50 @@
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 parseUrl (urlString) {
36
+ return new URL(urlString);
37
+ }
38
+ if (typeof exports !== 'undefined') exports.parseUrl = parseUrl;
39
+ function buildUrl (href) {
40
+ let u = new URL(href);
41
+ return u.toString();
42
+ }
43
+ if (typeof exports !== 'undefined') exports.buildUrl = buildUrl;
44
+ function getSearchParam (url, name) {
45
+ return url.searchParams[`get`](name);
46
+ }
47
+ if (typeof exports !== 'undefined') exports.getSearchParam = getSearchParam;
48
+ (async () => {
49
+
50
+ })().catch(err => { if (err) console.error("\x1b[31mRuntime Error:\x1b[0m", err.stack || err.message); });
@@ -0,0 +1,14 @@
1
+ note: URL utilities for Kadence
2
+
3
+ export function parseUrl urlString
4
+ return new URL(urlString)
5
+ end
6
+
7
+ export function buildUrl href
8
+ let u = new URL(href)
9
+ return run u.toString
10
+ end
11
+
12
+ export function getSearchParam url name
13
+ return run url.searchParams["get"] name
14
+ end
package/stdlib/uuid.js ADDED
@@ -0,0 +1,70 @@
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 rand = require(`./random.js`);
36
+ function v4 () {
37
+ let chars = [`0`, `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `a`, `b`, `c`, `d`, `e`, `f`];
38
+ let variants = [`8`, `9`, `a`, `b`];
39
+ let s = ``;
40
+ for (let __i = 0; __i < 8; __i++) {
41
+ let s = s + (rand.choice(chars)) ;
42
+ }
43
+ let s = s + `-` ;
44
+ for (let __i = 0; __i < 4; __i++) {
45
+ let s = s + (rand.choice(chars)) ;
46
+ }
47
+ let s = s + `-4` ;
48
+ for (let __i = 0; __i < 3; __i++) {
49
+ let s = s + (rand.choice(chars)) ;
50
+ }
51
+ let s = s + `-` ;
52
+ let s = s + (rand.choice(variants)) ;
53
+ for (let __i = 0; __i < 3; __i++) {
54
+ let s = s + (rand.choice(chars)) ;
55
+ }
56
+ let s = s + `-` ;
57
+ for (let __i = 0; __i < 12; __i++) {
58
+ let s = s + (rand.choice(chars)) ;
59
+ }
60
+ return s;
61
+ }
62
+ if (typeof exports !== 'undefined') exports.v4 = v4;
63
+ function validate (uuid) {
64
+ let helper = require(`./regex-helpers.js`);
65
+ return helper.validateUuid(uuid);
66
+ }
67
+ if (typeof exports !== 'undefined') exports.validate = validate;
68
+ (async () => {
69
+
70
+ })().catch(err => { if (err) console.error("\x1b[31mRuntime Error:\x1b[0m", err.stack || err.message); });