-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidator.js
68 lines (60 loc) · 1.66 KB
/
validator.js
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*******************************************
* copyright: nodeCache.js @github.com/akashchouhan16
* author: @akashchouhan16
* *****************************************
*/
class Validator {
#options
#pathRegex
constructor(options = null) {
if (options && typeof options != "object") {
this.#options = null
} else {
this.#options = { ...options }
}
this.#pathRegex = "*"
}
validate(options = null) {
let _mode = null, _path = null
if (options) {
const { mode, path } = options
_mode = mode
_path = path
} else {
const { mode, path } = this.#options
_mode = mode
_path = path
}
if (!_mode && !_path)
return false
if (_mode && _path) {
return this.#validateMode(_mode) && this.#validatePath(_path)
}
if (_mode) {
return this.#validateMode(_mode)
} else {
return this.#validatePath(_path)
}
}
#validateMode(mode) {
if (mode) {
// add checks to validate additional modes.
if (typeof mode != "string" || ["none", "std", "exp"].includes(mode) == false)
return false
return true
}
return false
}
#validatePath(path) {
if (path) {
// add checks to valid path with file and console Regex.
if (typeof path != "string" || ["none", "console", "file"].includes(path) == false)
return false
return true
}
return false
}
}
module.exports = {
Validator
}