-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (41 loc) · 1.72 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
'use strict'
module.exports = function (manifest) {
// Required properties
if (!obj(manifest)) {
throw new TypeError('Manifest must be an object')
} else if (!strong(manifest.name)) {
throw new TypeError('The manifest.name property is required and must be a string')
} else if (manifest.name.toLowerCase() !== manifest.name) {
throw new TypeError('The manifest.name property must be lowercase')
}
// Optional properties
if (manifest.version != null && !strong(manifest.version)) {
throw new TypeError('The optional manifest.version property must be a string')
} else if (manifest.title != null && !strong(manifest.title)) {
throw new TypeError('The optional manifest.title property must be a string')
} else if (manifest.provider != null && !strong(manifest.provider)) {
throw new TypeError('The optional manifest.provider property must be a string')
} else if (manifest.wants != null && !obj(manifest.wants)) {
throw new TypeError('The optional manifest.wants property must be an object')
} else if (manifest.supports != null && !obj(manifest.supports)) {
throw new TypeError('The optional manifest.supports property must be an object')
} else if (manifest.options != null && !obj(manifest.options)) {
throw new TypeError('The optional manifest.options property must be an object')
}
if (manifest.supports && manifest.wants && manifest.options) {
return manifest
} else {
return {
...manifest,
supports: manifest.supports || {},
wants: manifest.wants || {},
options: manifest.options || {}
}
}
}
function strong (v) {
return typeof v === 'string' && v !== ''
}
function obj (v) {
return typeof v === 'object' && v !== null && !Array.isArray(v)
}