Skip to content

Instantly share code, notes, and snippets.

@wibbuffey
Last active October 18, 2021 15:11
Show Gist options
  • Save wibbuffey/15abb674e7bf21a77f0a55a846e94401 to your computer and use it in GitHub Desktop.
Save wibbuffey/15abb674e7bf21a77f0a55a846e94401 to your computer and use it in GitHub Desktop.
[[ MOVED ]] simple command line parser in node.js
// 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"})
@wibbuffey
Copy link
Author

fixed to use Array.prototype.bind() instead of Array.prototype.append()

@wibbuffey
Copy link
Author

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