diff options
author | Wojtek Kosior <koszko@koszko.org> | 2022-01-22 13:49:40 +0100 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2022-01-22 13:49:40 +0100 |
commit | 7218849ae2f43aee6b3462a30e07caf5bac3d22b (patch) | |
tree | 3de3b31c07e532edf7373faf4a267f313dc2ed25 /common/entities.js | |
parent | 046b8a7b3e7259bf451926732e6221076b1d4153 (diff) | |
download | browser-extension-7218849ae2f43aee6b3462a30e07caf5bac3d22b.tar.gz browser-extension-7218849ae2f43aee6b3462a30e07caf5bac3d22b.zip |
add a mapping/resources installation dialog
Diffstat (limited to 'common/entities.js')
-rw-r--r-- | common/entities.js | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/common/entities.js b/common/entities.js index 60a7e2d..b70661f 100644 --- a/common/entities.js +++ b/common/entities.js @@ -54,6 +54,24 @@ const parse_version = ver_str => ver_str.split(".").map(n => parseInt(n)); * No version normalization is performed. */ const version_string = (ver, rev=0) => ver.join(".") + (rev ? `-${rev}` : ""); +#EXPORT version_string + +/* + * This function overloads on the number of arguments. If one argument is + * passed, it is an item definition (it need not be complete, only identifier, + * version and, if applicable, revision properties are relevant). If two or + * three arguments are given, they are in order: item identifier, item version + * and item revision. + * Returned is a string identifying this version of item. + */ +function item_id_string(...args) { + let def = args[0] + if (args.length > 1) + def = {identifier: args[0], version: args[1], revision: args[2]}; + return !Array.isArray(def.version) ? def.identifier : + `${def.identifier}-${version_string(def.version, def.revision)}`; +} +#EXPORT item_id_string /* vers should be an array of comparable values. Return the greatest one. */ const max = vals => Array.reduce(vals, (v1, v2) => v1 > v2 ? v1 : v2); |