Last active
October 18, 2021 15:11
-
-
Save wibbuffey/15abb674e7bf21a77f0a55a846e94401 to your computer and use it in GitHub Desktop.
[[ MOVED ]] simple command line parser in node.js
This file contains 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
// moved: github.com/ShinyWobbuffet/nsfp | |
function parse (array, registry) { | |
const flags = [] | |
const other = [] | |
array.forEach((item, index) => { | |
if (item.startsWith("--")) { | |
flags.push(item.slice(2)) | |
} else if (item.startsWith("-")) { | |
if (registry[item.slice(1)]) { | |
flags.push(registry[item.slice(1)]) | |
} else { | |
flags.push(item.slice(1)) | |
} | |
} else { | |
other.push(item) | |
} | |
}) | |
return flags, other; | |
} | |
// parse(process.argv.split(2), {"h": "help"}) |
now using .push()
instead of .bind()
(my mistake, i'm working on minifying the source so i'm too used to .bind()
)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
fixed to use
Array.prototype.bind()
instead ofArray.prototype.append()