Skip to content

Instantly share code, notes, and snippets.

@the-vampiire
Last active August 5, 2017 02:36
Show Gist options
  • Select an option

  • Save the-vampiire/1b47d3f2d608e4c63dc141f1ccea8018 to your computer and use it in GitHub Desktop.

Select an option

Save the-vampiire/1b47d3f2d608e4c63dc141f1ccea8018 to your computer and use it in GitHub Desktop.
error scanner and flag modifier
errorScanAndModify = (item, flag, data) => {
let expectedFlags;
switch(item){
case 'projects':
expectedFlags = ['name', 'n', 'url', 'u', 'git', 'g', 'date', 'd'];
break;
case 'gitHub':
case 'blog':
case 'portfolio':
expectedFlags = ['url', 'u'];
break;
case 'certifications':
expectedFlags = ['url', 'u', 'date', 'd'];
break;
}
if(!~expectedFlags.indexOf(flag)){
return `invalid update flag [\`-${flag}\`] for update item [\`${item}\`].\n Try \`/update ${item}\` for a list of required and optional flags`
}
// modification step (as needed)
switch(true){
case flag === 'git' || flag === 'g':
if(!data.includes('https://www.github.com/'))
return `invalid data: \`${data}\` associated with flag [\`-${flag}\`] does not begin with \`https://www.github.com/\``;
flag = 'gitHub';
break;
case flag === 'url' || flag === 'u':
if(item === 'gitHub'){
if(!data.includes('https://www.github.com/')) return `invalid gitHub profile url, ensure the url entered is of the form [\`https://www.github.com/yourUserName\`]`
}
if(!/(http:\/\/|https:\/\/)(www\.)/.test(data))
return `invalid data: \`${data}\` associated with flag [\`-${flag}\`]. ensure the full [\`http://www.\`] or [\`https://www.\`] url is being passed`;
flag = 'url';
break;
case flag === 'date' || flag === 'd':
if(!/[0-9]{2}\/[0-9]{2}\/[0-9]{2}/.test(data))
return `invalid date format [${data}]. must be in \`mm/dd/yy\` format`;
data = Date.parse(new Date(data))/1000;
flag = 'completedDate';
break;
case flag === 'n':
flag = 'name';
break;
}
return {data: data, flag: flag};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment