Repository navigation
Expand file tree
/
Copy pathprotected.js
More file actions
94 lines (84 loc) · 2.46 KB
/
Copy pathprotected.js
File metadata and controls
94 lines (84 loc) · 2.46 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/**
* @returns {ProtectedStatic} instance
*/
module.exports = ()=>{
var store = {}
class ProtectedStatic {
/**
* @param {string} className
* @param {string} key
*/
get(className, key){
if(key === undefined)
return undefined
if(typeof store[className] === 'undefined')
return undefined
if(typeof store[className][key] === 'undefined')
return undefined
return store[className][key]
}
/**
* @param {string} className
*/
getAll(className){
return store[className]
}
/**
* @param {string} className
* @param {string} key
* @param {*} data
* @returns {boolean} isSuccess
*/
set(className, key, data){
// Prevents storing self instance within variables.
if(data instanceof ProtectedStatic)
return false
if(key === undefined)
return false
if(data === undefined)
return this.remove(className, key)
if(typeof store[className] != 'undefined'){
store[className][key] = data
}else{
store[className] = {}
store[className][key] = data
}
return true
}
/**
* @param {string} className
* @param {string} key
* @returns {boolean} isSuccess
*/
remove(className, key){
if(key === undefined)
return false
if(typeof store[className][key] == 'undefined')
return false
delete(store[className][key])
if(Object.keys(store[className]).length == 0)
this.removeAll(className)
return true
}
/**
* @param {string} className
* @returns {boolean} isSuccess
*/
removeAll(className){
if(typeof store[className] == 'undefined')
return false
delete(store[className])
return true
}
/**
* @param {string} className
* @param {string} key
* @returns {boolean} isExist
*/
exist(className, key){
if(key === undefined) return false
return this.get(className, key) !== undefined
}
}
return new ProtectedStatic()
}