(defmodule nemoptera_text
(export all))
(defun to-str (value)
(cond
((is_binary value) (binary_to_list value))
((is_integer value) (integer_to_list value))
((is_list value) value)
((or (=:= value 'undefined) (=:= value 'null) (=:= value 'nil) (=:= value 'none)) "")
((is_atom value) (atom_to_list value))
('true (lists:flatten (io_lib:format "~p" (list value))))))
(defun blank? (value)
(=:= "" (string:trim (to-str value))))
(defun now-iso ()
(calendar:system_time_to_rfc3339 (os:system_time 'second)
(list (tuple 'unit 'second))))
(defun sql-quote (value)
(string:replace (to-str value) "'" "''" 'all))
(defun clip (value limit)
(let ((s (to-str value)))
(if (> (length s) limit)
(lists:sublist s limit)
s)))
(defun to-int (value default)
(case (catch (list_to_integer (string:trim (to-str value))))
(n (if (is_integer n) n default))
(_ default)))