-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
56 lines (41 loc) · 1.17 KB
/
index.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
const Helpers = require('./lib/helpers');
const FRC = require('./lib/frc');
const cacheValidation = {
applyConfig(finalObject, config) {
if(!config) {
return true;
}
if(config && config.returnObject) {
return finalObject;
}
if(config && config.returnString) {
return Helpers.convertToString(finalObject);
}
return false;
},
init(cacheParam, config) {
if(!cacheParam) {
return { error: 'No cache to validate. Check https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control for more details' };
}
let cacheObject = cacheParam;
if(typeof cacheParam === 'string') {
if(Helpers.hasDuplicatedConfiguration(cacheParam)) {
return { error: 'No duplicated configuration is allowed' };
}
cacheObject = Helpers.convertStringIntoObject(cacheParam);
}
if(cacheObject.error) {
return cacheObject;
}
const isFRCCompliant = FRC.isFRCCompliant(cacheObject);
if(isFRCCompliant.error) {
return isFRCCompliant;
}
return cacheValidation.applyConfig(cacheObject, config);
}
};
module.exports = cacheValidation.init;
// istanbul ignore next
if(process.env.NODE_ENV === 'test') {
module.exports.testObject = cacheValidation;
}