Lodash for QML
This is a simple Lodash wrapper for QML. The installation process is not quite convenient yet, but stay tuned :) Maybe, I will update it in a few centuries.
$ mkdir 3rdParty
$ cd 3rdParty
$ git clone https://github.com/easyQML/lodash.qml.git
I've bundled the latest available version (which is 4.17.5) with the wrapper, but I strongly recommend you to re-generate it with the freshest one:
$ npm install -g lodash-cli
$ cd qml/lodash
$ lodash exports="none" iife=";(function () {%output% root._ = _; }.call(this));" -o lodash.js
Please, refer to the official documentation. I tried it with both local file-system paths and Qt Resource system paths, and it works.
import QtQuick
import QtQuick.Window
import lodash // import the library
Window {
visible: true
width: 640
height: 480
title: qsTr('Hello Lodash')
Component.onCompleted: {
function megaprint(v) {
console.log(JSON.stringify(v))
}
// and it magically works here who knows why:
megaprint(
_.partition([1, 2, 3, 4], n => n % 2)
)
megaprint(
_([1, 2, 3]).map(n => n * 2)
)
}
}
Output
qml: [[1,3],[2,4]]
qml: [2,4,6]
Lodash library is distributed under MIT license, so my outstanding three lines of code follow the same path: LICENSE.