comparison src/lib/Utils.luan @ 0:8f4df159f06b

start public repo
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 11 Jul 2025 20:57:49 -0600
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:8f4df159f06b
1 local Luan = require "luan:Luan.luan"
2 local error = Luan.error
3 local new_error = Luan.new_error or error()
4 local ipairs = Luan.ipairs or error()
5 local type = Luan.type or error()
6 local set_metatable = Luan.set_metatable or error()
7 local Number = require "luan:Number.luan"
8 local long = Number.long or error()
9 local String = require "luan:String.luan"
10 local regex = String.regex or error()
11 local Http = require "luan:http/Http.luan"
12 local Logging = require "luan:logging/Logging.luan"
13 local logger = Logging.logger "Utils"
14
15
16 local Utils = {}
17
18 Utils.is_production = Http.domain == "linkmy.style"
19
20 Utils.compressed = {compressed=true}
21
22 function Utils.base_url()
23 local request = Http.request
24 return request.scheme.."://"..request.headers["Host"]
25 end
26
27 local set_mt = {}
28 function set_mt.__index(table,key)
29 return false
30 end
31
32 function Utils.list_to_set(list)
33 local set = {}
34 for _, v in ipairs(list) do
35 set[v] = true
36 end
37 set_metatable(set,set_mt)
38 return set
39 end
40
41 function Utils.to_list(input)
42 if input == nil then
43 return {}
44 elseif type(input) == "table" then
45 return input
46 else
47 return {input}
48 end
49 end
50
51 function Utils.long_or_nil(i)
52 return i and long(i)
53 end
54
55 Utils.email_regex = regex[[^[-+~.\w]+@([-.\w]+)$]]
56
57 function Utils.warn(msg)
58 local e = new_error(msg)
59 e.priority = "warn"
60 e.throw()
61 end
62
63 return Utils