UNPKG

620 BJavaScriptView Raw
1module.exports = _args => {
2 const args = _args.reduce((res, arg) => {
3 return res.concat(
4 arg.startsWith('-') && arg.includes('=') ? arg.split('=') : arg
5 )
6 }, [])
7
8 return {
9 getValue(name) {
10 if (!this.has(name)) return
11
12 const index = args.indexOf(name.length === 1 ? `-${name}` : `--${name}`)
13 return args[index + 1]
14 },
15
16 has(name) {
17 if (name.length > 1) {
18 return args.includes(`--${name}`)
19 }
20
21 const RE = new RegExp(`^-([a-zA-Z]+)`)
22 return args.find(arg => {
23 return RE.test(arg) && RE.exec(arg)[1].includes(name)
24 })
25 }
26 }
27}