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!
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

45 lignes
1.1KB

  1. import arvadosTypeName from 'arvados-type-name';
  2. const UUID_REGEX = /[a-z0-9]{5}-[a-z0-9]{5}-[a-z0-9]{15}/g;
  3. const PDH_REGEX = /[a-f0-9]{32}\+[0-9]+/g;
  4. class WBIdTools {
  5. static isIdentifier(value) {
  6. return ( this.isUuid(value) || this.isPDH(value) );
  7. }
  8. static isUuid(value) {
  9. const m = UUID_REGEX.exec(value);
  10. return (m && m[0] === value);
  11. }
  12. static isPDH(value) {
  13. const m = PDH_REGEX.exec(value);
  14. return (m && m[0] === value);
  15. }
  16. static startsWithIdentifier(value) {
  17. return ( this.startsWithUuid(value) || this.startsWithPDH(value) );
  18. }
  19. static startsWithUuid(value) {
  20. const m = UUID_REGEX.exec(value);
  21. return ( m && m.index === 0 );
  22. }
  23. static startsWithPDH(value) {
  24. const m = PDH_REGEX.exec(value);
  25. return ( m && m.index === 0 );
  26. }
  27. static typeName(value) {
  28. if (this.isPDH(value))
  29. return 'collection';
  30. if (this.isUuid(value))
  31. return arvadosTypeName(value);
  32. throw Error('Given value is neither an UUID nor a PDH: ' + value);
  33. }
  34. }
  35. export default WBIdTools;