Skip to main content
Version: 7.2402.x.x RR

Helpers

The Helpers.lua module is a collection of helper functions that are helpful for writing LuaFilter scripts.

FunctionDescriptionSample
Helpers.startsWith(stringToCheck, startsWith)Checks if a string (first parameter stringToCheck) starts with a given part (second parameter startsWith). Returns with "true", if either the string starts with the given part, or if both stringToCheck and startsWith are nil.
Helpers.endsWith(stringToCheck, endsWith)Checks if a string (first parameter stringToCheck) ends with a given part (second parameter endsWith). Returns with "true", if either the string ends with the given part, or if both stringToCheck and endsWith are nil.
Helpers.containsHost(url)Checks if a URL contains a schema/host prefix.
Helpers.trim(string)Returns a given string, with all leading and trailing whitespaces removed.
local result = Helpers.trim(" some string ")
-- result will contain "some string"
FunctionDescriptionSample
Helpers.getTrimmedLines(string)Splits a string into several lines. Returns with a table containing the lines.
local string = "foo bar\nbar foo\n"
local lines = Helpers.getTrimmedLines(string)
-- the table 'lines' will contain two strings, "foo bar" and "bar foo"
FunctionDescriptionSample
Helpers.normalize(uri)Normalizes a request URI.
local normalizedUri = Helpers.normalize("/a/b/../index.html")
-- normalizedUri will be "/a/index.html"
FunctionDescriptionSample
Helpers.noCase(string)Changes any character "x" in a string (both lower and upper case) into the pattern [xX]. Useful for case-insensitive search.
Helpers.tableLength(tab)Returns the number of table entries.
local table = {'some', 'string'}
local counter = Helpers.tableLength(table)
-- counter will be '2'