Module ngx-oauth.util

General utility functions.

Functions

concat (...) Returns a new table with items concatenated from the given tables.
contains (item, tab) Returns true if the table tab contains the specified item; otherwise returns false.
default (value, default_value) Returns the value if not nil or empty, otherwise returns the default_value.
id (value) Returns the given value.
is_empty (value) Returns true if the value is nil or empty string.
is_absolute_url (value) Returns true if the value starts with https:// or http://.
map (func, tab) Returns a new table with the results of running func(value, key) once for every key-value pair in the tab.
imap (func, tab) Returns a new table with the results of running func(value, index) once for every item in the tab.
merge (...) Returns a new table containing the contents of all the given tables.
mtype (value) Returns type of the given value.
partial (func, ...) Partial application.
pipe (...) Performs left-to-right function composition.
starts_with (prefix, str) Returns true if the string str starts with the prefix.
unless (pred, when_false, value) Returns the result of calling when_false with the value if pred function returns falsy for the value; otherwise returns the value as is.


Functions

concat (...)
Returns a new table with items concatenated from the given tables. Tables are iterated using ipairs, so this function is intended for tables that represent indexed arrays.

Parameters:

Returns:

    table A new table.

See also:

contains (item, tab)
Returns true if the table tab contains the specified item; otherwise returns false.

Parameters:

  • item The item to search.
  • tab table The table to test.

Returns:

    bool Whether the tab contains the item.
default (value, default_value)
Returns the value if not nil or empty, otherwise returns the default_value.

Parameters:

  • value
  • default_value
id (value)
Returns the given value. That's it, this is an identity function.

Parameters:

  • value
is_empty (value)
Returns true if the value is nil or empty string.

Parameters:

  • value

Returns:

    bool
is_absolute_url (value)
Returns true if the value starts with https:// or http://. This is very simplified test, but it's good enough and efficient for our needs.

Parameters:

  • value
map (func, tab)
Returns a new table with the results of running func(value, key) once for every key-value pair in the tab. Tables are iterated using pairs, so this function is intended for tables that represent associative arrays.

Parameters:

  • func function The function that accepts at least one argument and returns a value.
  • tab table The table to map over.

Returns:

    table A new table.

See also:

imap (func, tab)
Returns a new table with the results of running func(value, index) once for every item in the tab. Tables are iterated using ipairs, so this function is intended for tables that represent indexed arrays.

Parameters:

  • func function The function that accepts at least one argument and returns a value.
  • tab table The table to map over.

Returns:

    table A new table.

See also:

merge (...)
Returns a new table containing the contents of all the given tables. Tables are iterated using pairs, so this function is intended for tables that represent associative arrays. Entries with duplicate keys are overwritten with the values from a later table.

Parameters:

Returns:

    table A new table.

See also:

mtype (value)
Returns type of the given value. If value has a metatable with key __type, then returns its value; otherwise returns Lua's raw type.

Parameters:

  • value

Returns:

    string A type of the value.
partial (func, ...)
Partial application. Takes a function func and arguments, and returns a function func2. When applied, func2 returns the result of applying func to the arguments provided initially followed by the arguments provided to func2.

Parameters:

  • func
  • ... Arguments to pass to the func.

Returns:

    func A partially applied function.
pipe (...)
Performs left-to-right function composition.

Parameters:

  • ... {function,...} The functions to compose; as multiple arguments, or in a single table.

Returns:

    function A composition of the given functions.
starts_with (prefix, str)
Returns true if the string str starts with the prefix.

Parameters:

Returns:

    bool
unless (pred, when_false, value)
Returns the result of calling when_false with the value if pred function returns falsy for the value; otherwise returns the value as is.

Parameters:

  • pred function The predicate function.
  • when_false function The function to invoke when the pred evaluates to a falsy value.
  • value The value to test with the pred function and pass to the when_false if necessary.

Returns:

    The value, or the result of applying value to when_false.
generated by LDoc 1.4.3