Mercurial Hosting > linkmystyle
view 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 |
line wrap: on
line source
local Luan = require "luan:Luan.luan" local error = Luan.error local new_error = Luan.new_error or error() local ipairs = Luan.ipairs or error() local type = Luan.type or error() local set_metatable = Luan.set_metatable or error() local Number = require "luan:Number.luan" local long = Number.long or error() local String = require "luan:String.luan" local regex = String.regex or error() local Http = require "luan:http/Http.luan" local Logging = require "luan:logging/Logging.luan" local logger = Logging.logger "Utils" local Utils = {} Utils.is_production = Http.domain == "linkmy.style" Utils.compressed = {compressed=true} function Utils.base_url() local request = Http.request return request.scheme.."://"..request.headers["Host"] end local set_mt = {} function set_mt.__index(table,key) return false end function Utils.list_to_set(list) local set = {} for _, v in ipairs(list) do set[v] = true end set_metatable(set,set_mt) return set end function Utils.to_list(input) if input == nil then return {} elseif type(input) == "table" then return input else return {input} end end function Utils.long_or_nil(i) return i and long(i) end Utils.email_regex = regex[[^[-+~.\w]+@([-.\w]+)$]] function Utils.warn(msg) local e = new_error(msg) e.priority = "warn" e.throw() end return Utils