all files / lib/util/ parse.js

91.67% Statements 11/12
75% Branches 6/8
100% Functions 1/1
91.67% Lines 11/12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24    240× 240× 240×   240×       240× 59×     240×   240× 232×       240×  
'use strict';
 
module.exports = function (str) {
  var regex = /^(([a-zA-Z][_\-0-9a-zA-Z]*)\/)?([a-zA-Z][_\-0-9a-zA-Z]*)(@(\d+\.\d+\.\d+))?$/i;
  var parsed = {};
  var match = regex.exec(str);
 
  Iif (!match) {
    throw new Error('Component cannot be parsed');
  }
 
  if (match[2]) {
    parsed.owner = match[2];
  }
 
  parsed.name = match[3] || '';
 
  if (match[5]) {
    parsed.version = match[5];
  }
 
 
  return parsed;
};