forked from kriskbx/gitlab-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathargs.js
More file actions
46 lines (36 loc) · 1.04 KB
/
Copy pathargs.js
File metadata and controls
46 lines (36 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* Args helper
*/
class Args {
constructor(args) {
this.args = args;
this.data = [];
}
/**
* parse the args and return the project argument
* @returns {*}
*/
project() {
if (!this.args[0] && !this.data.project) return null;
if (this.data.project) return this.data.project;
let projects = [...new Set(this.args.filter(arg => isNaN(new Number(arg))))];
this.args = this.args.filter(arg => !projects.includes(arg));
if(projects.length == 0)
return null;
return this.data.project = projects;
}
/**
* parse the args and return an array of issues
* @returns {*}
*/
iids() {
if (this.data.iids) return this.data.iids;
this.data.iids = [...new Set(this.args.map((issue) => {
if (issue.indexOf(',') === -1) return issue;
return issue.split(',');
}).flat())];
if (this.data.iids.length === 0) return null;
return this.data.iids;
}
}
export default Args;