2017-08-10 06:45:02 -08:00
|
|
|
import path from 'path';
|
2016-07-13 12:44:24 -08:00
|
|
|
import * as regex from './url-regex';
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
export default function isUrlCommand(shell, data) {
|
2017-08-10 06:45:02 -08:00
|
|
|
const matcher = regex[path.parse(shell).name]; // eslint-disable-line import/namespace
|
2016-09-21 06:27:11 -08:00
|
|
|
if (undefined === matcher || !data) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2016-07-14 15:40:15 -08:00
|
|
|
|
2016-07-20 09:08:12 -08:00
|
|
|
const match = data.match(matcher);
|
2016-12-17 13:17:58 -09:00
|
|
|
const urlRegex = /((?:https?:\/\/)(?:[-a-z0-9]+\.)*[-a-z0-9]+.*)/;
|
2016-07-14 15:40:15 -08:00
|
|
|
|
2016-12-17 13:17:58 -09:00
|
|
|
if (match && urlRegex.test(match[2])) {
|
|
|
|
|
return `${match[2]}`;
|
2016-07-13 12:44:24 -08:00
|
|
|
}
|
|
|
|
|
|
2016-07-14 15:40:15 -08:00
|
|
|
return null;
|
2016-07-13 12:44:24 -08:00
|
|
|
}
|