Last active
August 4, 2017 03:50
-
-
Save the-vampiire/db89c0065981fbb9870e0c9bf5626476 to your computer and use it in GitHub Desktop.
argumentParser / argumentSplitter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| argumentParser = arguments => { | |
| const output = argumentSplitter(arguments); | |
| const item = output.item; | |
| const pairsArray = output.pairsArray; | |
| let flagDataPairs = {}; | |
| pairsArray.forEach( pairString => { | |
| let flag = pairString.slice(0, pairString.indexOf(' ')); | |
| let data = pairString.slice(pairString.indexOf(' ')+1); | |
| // analyzer function which accepts the (flag, data) and determines if the data type is correct for that flag | |
| // modification step (as needed) | |
| switch(flag){ | |
| case 'git': | |
| flag = 'gitHubURL'; | |
| break; | |
| case 'date': | |
| flag = 'completedDate'; | |
| data = Date.parse(new Date(data))/1000; | |
| } | |
| // pair storage step | |
| flagDataPairs[flag] = data; | |
| }); | |
| return {item: item, updateData: flagDataPairs}; | |
| }; | |
| argumentSplitter = arguments => { | |
| const item = arguments.slice(0, arguments.indexOf(' ')); | |
| const pairsArray = arguments.slice(arguments.indexOf('-')) | |
| .replace(/(\ -)/g, '-') | |
| .split(/-/g) | |
| .splice(1); | |
| return {item: item, pairsArray: pairsArray}; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment