forked from tomiichx/tomic_querybuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtilities.lua
More file actions
63 lines (50 loc) · 1.43 KB
/
Utilities.lua
File metadata and controls
63 lines (50 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
---@class Utilities
Utilities = setmetatable({}, Utilities)
Utilities.__name = "Utilities"
Utilities.__index = Utilities
local CURRENT_RESOURCE_NAME <const> = GetCurrentResourceName()
local CURRENT_ENVIRONMENT <const> = GetResourceMetadata(CURRENT_RESOURCE_NAME, 'environment', 0)
local PRODUCTION <const> = 'production'
---@type string
Utilities.CURRENT_RESOURCE_NAME = CURRENT_RESOURCE_NAME
---Check if the current environment is production
---@return boolean
function Utilities.isProduction()
return CURRENT_ENVIRONMENT == PRODUCTION
end
---Map function for tables
---@param tbl table The table to map over
---@param fn function The function to apply to each element
---@return table
function Utilities.map(tbl, fn)
local mapped = {}
for i, v in ipairs(tbl) do
mapped[i] = fn(v)
end
return mapped
end
---Helper function to ensure proper backtick escaping for identifiers
---@param identifier string
---@return string
function Utilities.ensureBackticks(identifier)
if identifier:match('^`.*`$') then
return identifier
end
if identifier == '*' then
return identifier
end
return '`' .. identifier .. '`'
end
function Utilities.getSorted(tbl)
local sortedKeys = {}
for k in pairs(tbl) do
table.insert(sortedKeys, k)
end
table.sort(sortedKeys)
return sortedKeys
end
function Utilities.isEmpty(value)
local trimmedValue = (value or ''):match('^%s*(.-)%s*$')
return trimmedValue == nil or trimmedValue == ''
end
return Utilities