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!
瀏覽代碼

Started implementing WBIdTools.

pull/1/head
父節點
當前提交
d8e66eb1c7
共有 1 個檔案被更改,包括 44 行新增0 行删除
  1. +44
    -0
      frontend/src/js/misc/wb-id-tools.js

+ 44
- 0
frontend/src/js/misc/wb-id-tools.js 查看文件

@@ -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…
取消
儲存