String Extensions (string)
string
Extensions to Lua's string library: splitting, trimming, padding, hashing (MD5/SHA1/SHA256/SHA512), Base64, AES-128, hex encoding, URI encoding, version comparison, validation (email/URL/number), and random generation.
36 functions
Lua 5.3
string.string.aes128_decrypt
string.aes128_decrypt(data, key)AES-128 ECB decrypt.
string.string.aes128_encrypt
string.aes128_encrypt(data, key)AES-128 ECB encrypt with PKCS7 padding.
string.string.atrim
string.atrim(text)Remove ALL whitespace characters.
string.string.base64_decode
string.base64_decode(b64)Base64 decode. Same as utils.base64_decode().
string.string.base64_encode
string.base64_encode(data)Base64 encode. Same as utils.base64_encode().
string.string.compare
string.compare(a, b [, case_sensitive])Compare strings. Default is case-INsensitive.
string.string.compare_version
string.compare_version(a, b)Compare dot-separated version strings (up to 16 components).
string.string.decode_uri
string.decode_uri(text)Decode percent-encoded URI.
string.string.encode_uri
string.encode_uri(text)URI encode (like JavaScript encodeURI). Preserves: A-Za-z0-9;,/?:@&=+$-_.!~*'()#
string.string.encode_uri_component
string.encode_uri_component(text)URI component encode (like JavaScript encodeURIComponent). More aggressive than encode_uri.
string.string.ends_with
string.ends_with(text, suffix)Check if string ends with suffix.
string.string.from_hex
string.from_hex(hex)Convert hex string to binary data.
string.string.is_alphanumeric
string.is_alphanumeric(text)Check if all characters are alphanumeric (Unicode-aware).
string.string.is_email
string.is_email(text)Check if string matches email regex.
string.string.is_integer
string.is_integer(text)Check if string is a valid integer (optional +/- sign, digits only).
string.string.is_letter
string.is_letter(text)Check if all characters are letters (Unicode-aware).
string.string.is_link
string.is_link(text)Check if string is an HTTP/HTTPS URL.
string.string.is_lower
string.is_lower(text)Check if string is all lowercase.
string.string.is_number
string.is_number(text)Check if string is a valid number (integer or float).
string.string.is_numeric
string.is_numeric(text)Check if all characters are digits (0-9 only, no sign/decimal).
string.string.is_upper
string.is_upper(text)Check if string is all uppercase.
string.string.lpad
string.lpad(text, length [, pad])Left-pad string to target length.
string.string.ltrim
string.ltrim(text)Remove leading whitespace.
string.string.md5
string.md5(text)Calculate MD5 hash. Same as utils.md5().
string.string.random
string.random(pool, count)Generate random string from character pool using arc4random_uniform.
string.string.rpad
string.rpad(text, length [, pad])Right-pad string to target length.
string.string.rtrim
string.rtrim(text)Remove trailing whitespace.
string.string.sha1
string.sha1(data)Calculate SHA-1 hash.
string.string.sha256
string.sha256(data)Calculate SHA-256 hash. Same as utils.sha256().
string.string.sha512
string.sha512(data)Calculate SHA-512 hash.
string.string.split
string.split(text, separator)Split string by separator using manual memcmp scan.
string.string.starts_with
string.starts_with(text, prefix)Check if string starts with prefix.
string.string.strip_utf8_bom
string.strip_utf8_bom(data)Remove UTF-8 BOM (EF BB BF) if present.
string.string.to_capitalized
string.to_capitalized(text)Capitalize first character only.
string.string.to_hex
string.to_hex(data)Convert binary data to hex string.
string.string.trim
string.trim(text)Remove whitespace from both ends.