index.js 569 B

12345678910111213141516171819202122232425
  1. module.exports = (args) => {
  2. const options = {}
  3. const params = args.filter(arg => {
  4. const doubleDashMatch = arg.match(/^--(\w[\w-.]*)(=(\S+))?$/)
  5. if (doubleDashMatch) {
  6. options[doubleDashMatch[1]] = Number(doubleDashMatch[3]) || doubleDashMatch[3] || true
  7. return false
  8. }
  9. const singleDashMatch = arg.match(/^-(\w)(=(\S+))?$/)
  10. if (singleDashMatch) {
  11. options[singleDashMatch[1]] = Number(singleDashMatch[3]) || singleDashMatch[3] || true
  12. return false
  13. }
  14. return true
  15. })
  16. return {
  17. params,
  18. options
  19. }
  20. }