Lodash documentation

From Domoticz
Revision as of 16:13, 13 January 2021 by Walter vl (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


lodash.

What is lodash?

lodash is a well known and very popular Javascript library filled with dozens of handy helper functions that really make your life as coder a lot easier. Fortunately there is also a Lua version. From domoticz Version 3.8835 this library is available for Lua and dzVents scripts.

What's in a name?

lodash was meant as a lightweight replacement for underscore. So lodash is effectively a play on words on underscore - "low dash", what does a dash - look like when its a bit lower to the ground? _ Why, an underscore of course

Why lodash?

Lodash makes Lua easier by taking the hassle out of working with arrays, numbers, objects, strings, etc. Lodash’s modular methods are great for:

  • Iterating arrays, objects, & strings
  • Manipulating & testing values
  • Creating composite functions

How lodash?

In dzVents it is directly available through the domoticz object:

local _ = domoticz.utils._
_.print({2, 3, 'x', 4}, 'x')
_.print( _.indexOf({2, 3, 'x', 4}, 'x'))
-- > dzVents: {2, 3, "x", 4}
-- > dzVents: x
-- > dzVents: 3

in classic domoticz Lua you need a require statement:

local _ = require('dzVents/runtime/lodash')
_.print({2, 3, 'x', 4}, 'x')
_.print( _.indexOf({2, 3, 'x', 4}, 'x'))
-- > LUA: {2, 3, "x", 4}
-- > LUA: x
-- > LUA: 3

lodash sections

Array

Arrays are ordered arrangement of objects, which may be a one-dimensional array containing a collection of rows or a multi-dimensional array containing multiple rows and columns. In Lua all arrays are implemented as associative arrays which means they store a set of key/value pairs in a table.

Collection

Collections are Basically things that implement some kind of "iterable" interface, and they internally use the same iteration method.
All the "collection methods" do work both on arrays and objects (and a few more iterable things), while the array methods should only be used on arrays.
Collections are like tables on steroids. They are designed to act as a fluent wrapper when working with structured data, offering the developer convenience for common tasks.

Function

simplifying binding, decorating, constraining, throttling, debouncing, currying, and changing the pointer.

Number

String

Conversion functions for performing basic string operations, such as trimming, converting to uppercase, camel case, etc.

Object

Accessing, extending, merging, defaults, and transforming Tables, -functions, -threads, and userdata

Seq

Chaining, wrapping, filtering, and testing.

Utility

A group of functions for simplifying common programming tasks such as determining type as well as simplifying math operations.

Helper functions

The helper functions are there to support the exposed lodash functions. In them selves they are not part of the lodash API.

All lodash functions explained with link to sources

Link to lodash page.


License and Author!

  • License: MIT
  • Author: Daniel Moghimi

Useful links