yubioath-flutter/qml/utils.js

58 lines
1.7 KiB
JavaScript
Raw Normal View History

2017-11-20 17:30:26 +03:00
function versionString(version) {
2018-01-03 12:38:45 +03:00
return version ? version.join('.') : ''
2017-11-20 17:30:26 +03:00
}
function versionGE(version, major, minor, micro) {
2018-01-15 12:42:58 +03:00
if (version != undefined) {
return (version[0] > major || (version[0] == major
&& (version[1] > minor
|| (version[1] == minor
&& version[2] >= micro))))
}
return false
2017-11-20 17:30:26 +03:00
}
2018-01-15 12:12:50 +03:00
// Shim for String.prototype.startsWith(), added in Qt 5.8
// Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
function startsWith(string, search, pos) {
return string.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search
}
2018-01-15 12:12:50 +03:00
/*
* Quick and dirty shim for Array.find added in Qt 5.9
*
* @param items: array
* @param predicate: function(any) => Boolean
* @return The first `item` in `arr` that matches the `predicate`, or
* `undefined` if none matches
*/
function find(items, predicate) {
if (items) {
for (var i = 0; i < items.length; ++i) {
if (predicate(items[i])) {
return items[i]
}
}
}
return undefined
}
/*
* Quick and dirty shim for Array.findIndex added in Qt 5.9
*
* @param items: array
* @param predicate: function(any) => Boolean
* @return The index of the first `item` in `arr` that matches the
* `predicate`, or `undefined` if none matches
*/
function findIndex(items, predicate) {
if (items) {
for (var i = 0; i < items.length; ++i) {
if (predicate(items[i])) {
return i
}
}
}
return undefined
}