#cubzh-library/helpers - Small Lua helpers

1 messages · Page 1 of 1 (latest)

split ivy
#

Installation

Modules = {
  helpers = "github.com/Donorhan/cubzh-library/helpers:42ee1c9",
}

How to

Table

helpers.table.display(table, [customDisplay])
Displays key-value pairs of the given map on the console.

helpers.table.every(table, callback)
Checks if a callback function returns true for every element in the table.

helpers.table.fill(table, value)
Fills the table with the value given as a parameter

helpers.table.filter(table, callback)
Creates a new table containing only the elements from the original table for which the callback function returns true.

helpers.table.forEach(table, callback)
Executes a callback function for each element in the table.

helpers.table.get(table, key, default)
Retrieves an element from the array; if the value does not exist, returns the default value given in parameter

helpers.table.keys(table)
Retrieves all the keys of a table

helpers.table.length(table)
Returns the number of elements in the table.

helpers.table.map(table, callback)
Modifies each element in the table using the provided callback function.

helpers.table.merge(firstTable, secondTable)
Merges two arrays: if an element in the second array already exists in the first, its value will be overwritten.

helpers.table.sample(table)
Take a random element from the array.

helpers.table.values(table)
Returns an array containing all the values from the table.

helpers.table.removeKey(table, key)
Removes a key-value pair from the table, if the key exists.

helpers.table.some(table, callback)
Checks if at least one element in the table satisfies the condition specified by the callback function.

Math

helpers.math.lerp(from, to, time)
Linear interpolation between two values

helpers.math.remap(value, low1, high1, low2, high2)
Remaps a value from one range to another using linear interpolation.

helpers.math.round(value)
Round a number to its nearest higher or lower value.

sly elbow
#

Really cool module!

split ivy
#

I've changed the syntax a little and added a few useful functions:
table.sample, table.merge, table.length, table.fill, table.keys, table.findIndex, table.get and math.round, also table.display has a custom print callback now.

#

cubzh-library/helpers - Small Lua helpers

pure lodge
#

@split ivy cool! But can you post last commit id on updates?

split ivy
#

Oops! Done đŸ™‚

pure lodge
#

thanks! cool module, liked remap function

pure lodge
#

also i don't think that we need table.lenght

#

because we can use #table to get it length