Skip to main content
Version: 3.14.x.x LTS

Helpers

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

FunctionDescription
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.

Sample

local result = Helpers.trim(" some string ")
-- result will contain "some string"
FunctionDescription
Helpers.getTrimmedLines(string)Splits a string into several lines. Returns with a table containing the lines.

Sample

local string = "foo bar\nbar foo\n"
local lines = Helpers.getTrimmedLines(string)
-- the table 'lines' will contain two strings, "foo bar" and "bar foo"
FunctionDescription
Helpers.normalize(uri)Normalizes a request URI.

Sample

local normalizedUri = Helpers.normalize("/a/b/../index.html")
-- normalizedUri will be "/a/index.html"
FunctionDescription
Helpers.noCase(string)Changes any character "x" in a string (both lower and upper case) into the pattern. Useful for case-insensitive search.
Helpers.tableLength(tab)Returns the number of table entries.

Sample

local table = {'some', 'string'}
local counter = Helpers.tableLength(table)
-- counter will be '2'