@thigasdevelopment/luam 0.19.12 → 1.0.1
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/lua/async.lua +6 -6
- package/lua/class.lua +239 -211
- package/lua/development-logs-client.lua +15 -9
- package/lua/development-logs-server.lua +41 -44
- package/lua/math.lua +21 -18
- package/lua/promise.lua +446 -0
- package/lua/string.lua +78 -62
- package/lua/table.lua +57 -49
- package/lua/threads.lua +326 -269
- package/lua/validate.lua +230 -185
- package/luam.mjs +969 -134
- package/package.json +1 -1
package/lua/string.lua
CHANGED
|
@@ -1,82 +1,98 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
---@param value any
|
|
2
|
+
---@return string
|
|
3
|
+
local function trim (value)
|
|
4
|
+
if (type (value) ~= 'string') then
|
|
5
|
+
return tostring (value);
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
return value:match ('^%s*(.-)%s*$') or '';
|
|
7
9
|
end
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return nil
|
|
15
|
-
end
|
|
11
|
+
---@param context table
|
|
12
|
+
---@param path string
|
|
13
|
+
---@return any
|
|
14
|
+
local function resolve (context, path)
|
|
15
|
+
local current = context;
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
for key in path:gmatch ('[^%.]+') do
|
|
18
|
+
if (type (current) ~= 'table') then
|
|
19
|
+
return nil;
|
|
20
|
+
end
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
current = current[key];
|
|
23
|
+
if (current == nil) then
|
|
24
|
+
return nil;
|
|
25
|
+
end
|
|
26
|
+
end
|
|
23
27
|
|
|
24
|
-
|
|
28
|
+
return current;
|
|
25
29
|
end
|
|
26
30
|
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
---@param raw string
|
|
32
|
+
---@return string, string?
|
|
33
|
+
local function parse (raw)
|
|
34
|
+
local key, rest = raw:match ('^(.-):(.+)$');
|
|
35
|
+
if (not key) then
|
|
36
|
+
return raw, nil;
|
|
37
|
+
end
|
|
29
38
|
|
|
30
|
-
|
|
31
|
-
return raw, nil
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
return key, trim(rest:match('^([^:]+)'))
|
|
39
|
+
return key, trim (rest:match ('^([^:]+)'));
|
|
35
40
|
end
|
|
36
41
|
|
|
37
|
-
|
|
38
|
-
|
|
42
|
+
---@param value any
|
|
43
|
+
---@return string
|
|
44
|
+
function string.trim (value)
|
|
45
|
+
return trim (value);
|
|
39
46
|
end
|
|
40
47
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
48
|
+
---@param value string
|
|
49
|
+
---@param prefix string
|
|
50
|
+
---@return boolean
|
|
51
|
+
function string.startsWith (value, prefix)
|
|
52
|
+
if (type (value) ~= 'string') or (type (prefix) ~= 'string') then
|
|
53
|
+
return false;
|
|
54
|
+
end
|
|
45
55
|
|
|
46
|
-
|
|
56
|
+
return value:sub (1, prefix:len ()) == prefix;
|
|
47
57
|
end
|
|
48
58
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
59
|
+
---@param value string
|
|
60
|
+
---@param suffix string
|
|
61
|
+
---@return boolean
|
|
62
|
+
function string.endsWith (value, suffix)
|
|
63
|
+
if (type (value) ~= 'string') or (type (suffix) ~= 'string') then
|
|
64
|
+
return false;
|
|
65
|
+
end
|
|
53
66
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
67
|
+
if (suffix == '') then
|
|
68
|
+
return true;
|
|
69
|
+
end
|
|
57
70
|
|
|
58
|
-
|
|
71
|
+
return value:sub (-suffix:len ()) == suffix;
|
|
59
72
|
end
|
|
60
73
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
74
|
+
---@param text string
|
|
75
|
+
---@param context table
|
|
76
|
+
---@return string
|
|
77
|
+
function string.template (text, context)
|
|
78
|
+
if (type (text) ~= 'string') then
|
|
79
|
+
return tostring (text);
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
if (type (context) ~= 'table') or (next (context) == nil) then
|
|
83
|
+
return text;
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
return (
|
|
87
|
+
text:gsub ('%${(.-)}', function (raw)
|
|
88
|
+
local key, default = parse (trim (raw));
|
|
89
|
+
local value = resolve (context, trim (key));
|
|
90
|
+
|
|
91
|
+
if (value == nil) then
|
|
92
|
+
return default ~= nil and default or '';
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
return tostring (value);
|
|
96
|
+
end)
|
|
97
|
+
);
|
|
82
98
|
end
|
package/lua/table.lua
CHANGED
|
@@ -1,63 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
---@param value table
|
|
2
|
+
---@return number
|
|
3
|
+
function table.size (value)
|
|
4
|
+
local size = 0;
|
|
5
|
+
if (type (value) ~= 'table') then
|
|
6
|
+
return size;
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
for _ in pairs (value) do
|
|
10
|
+
size = size + 1;
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
return size;
|
|
13
14
|
end
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
---@param value table
|
|
17
|
+
---@return boolean
|
|
18
|
+
function table.isEmpty (value)
|
|
19
|
+
if (type (value) ~= 'table') then
|
|
20
|
+
return true;
|
|
21
|
+
end
|
|
19
22
|
|
|
20
|
-
|
|
23
|
+
return next (value) == nil;
|
|
21
24
|
end
|
|
22
25
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
---@param value table
|
|
27
|
+
---@return table
|
|
28
|
+
function table.keys (value)
|
|
29
|
+
local keys = { };
|
|
30
|
+
if (type (value) ~= 'table') then
|
|
31
|
+
return keys;
|
|
32
|
+
end
|
|
29
33
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
for key in pairs (value) do
|
|
35
|
+
keys[#keys + 1] = key;
|
|
36
|
+
end
|
|
33
37
|
|
|
34
|
-
|
|
38
|
+
return keys;
|
|
35
39
|
end
|
|
36
40
|
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
---@param value table
|
|
42
|
+
---@return table
|
|
43
|
+
function table.values (value)
|
|
44
|
+
local values = { };
|
|
45
|
+
if (type (value) ~= 'table') then
|
|
46
|
+
return values;
|
|
47
|
+
end
|
|
39
48
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
49
|
+
for _, item in pairs (value) do
|
|
50
|
+
values[#values + 1] = item;
|
|
51
|
+
end
|
|
43
52
|
|
|
44
|
-
|
|
45
|
-
values[#values + 1] = item
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
return values
|
|
53
|
+
return values;
|
|
49
54
|
end
|
|
50
55
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
---@param value table
|
|
57
|
+
---@param item any
|
|
58
|
+
---@return boolean
|
|
59
|
+
function table.includes (value, item)
|
|
60
|
+
if (type (value) ~= 'table') then
|
|
61
|
+
return false;
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
for _, current in pairs (value) do
|
|
65
|
+
if (current == item) then
|
|
66
|
+
return true;
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
return false;
|
|
63
71
|
end
|