IF YOU WOULD LIKE TO GET AN ACCOUNT, please write an email to s dot adaszewski at gmail dot com. User accounts are meant only to report issues and/or generate pull requests. This is a purpose-specific Git hosting for ADARED projects. Thank you for your understanding!
Sfoglia il codice sorgente

Started implementing WBIdTools.

pull/1/head
parent
commit
d8e66eb1c7
1 ha cambiato i file con 44 aggiunte e 0 eliminazioni
  1. +44
    -0
      frontend/src/js/misc/wb-id-tools.js

+ 44
- 0
frontend/src/js/misc/wb-id-tools.js Vedi File

@@ -0,0 +1,44 @@
import arvadosTypeName from 'arvados-type-name';
const UUID_REGEX = /[a-z0-9]{5}-[a-z0-9]{5}-[a-z0-9]{15}/g;
const PDH_REGEX = /[a-f0-9]{32}\+[0-9]+/g;
class WBIdTools {
static isIdentifier(value) {
return ( this.isUuid(value) || this.isPDH(value) );
}
static isUuid(value) {
const m = UUID_REGEX.exec(value);
return (m && m[0] === value);
}
static isPDH(value) {
const m = PDH_REGEX.exec(value);
return (m && m[0] === value);
}
static startsWithIdentifier(value) {
return ( this.startsWithUuid(value) || this.startsWithPDH(value) );
}
static startsWithUuid(value) {
const m = UUID_REGEX.exec(value);
return ( m && m.index === 0 );
}
static startsWithPDH(value) {
const m = PDH_REGEX.exec(value);
return ( m && m.index === 0 );
}
static typeName(value) {
if (this.isPDH(value))
return 'collection';
if (this.isUuid(value))
return arvadosTypeName(value);
throw Error('Given value is neither an UUID nor a PDH: ' + value);
}
}
export default WBIdTools;

Loading…
Annulla
Salva