diff options
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); |