Project rename
This commit is contained in:
+52
@@ -0,0 +1,52 @@
|
||||
var config = require('./config')
|
||||
|
||||
module.exports = function checkOptions (options) {
|
||||
if (!isObject(options)) {
|
||||
throw new Error('featurePolicy must be called with an object argument. See the documentation.')
|
||||
}
|
||||
|
||||
var features = options.features
|
||||
|
||||
var featuresExist = isObject(features)
|
||||
if (!featuresExist || Object.keys(features).length === 0) {
|
||||
throw new Error('featurePolicy must have at least one feature under the "features" key. See the documentation.')
|
||||
}
|
||||
|
||||
Object.keys(features).forEach(function (feature) {
|
||||
if (!config.features.hasOwnProperty(feature)) {
|
||||
throw new Error('featurePolicy does not support the "' + feature + '" feature.')
|
||||
}
|
||||
|
||||
var value = features[feature]
|
||||
|
||||
if (!Array.isArray(value) || value.length === 0) {
|
||||
throw new Error('The value of the "' + feature + '" feature must be a non-empty array.')
|
||||
}
|
||||
|
||||
var containsStar = false
|
||||
var containsNone = false
|
||||
value.forEach(function (allowed) {
|
||||
if (allowed === '*') {
|
||||
containsStar = true
|
||||
} else if (allowed === "'none'") {
|
||||
containsNone = true
|
||||
} else if (allowed === 'self') {
|
||||
throw new Error("'self' must be quoted.")
|
||||
} else if (allowed === 'none') {
|
||||
throw new Error("'none' must be quoted.")
|
||||
}
|
||||
})
|
||||
|
||||
if (value.length > 1) {
|
||||
if (containsStar) {
|
||||
throw new Error('The value of the "' + feature + '" feature cannot contain * and other values.')
|
||||
} else if (containsNone) {
|
||||
throw new Error('The value of the "' + feature + '" feature cannot contain \'none\' and other values.')
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function isObject (value) {
|
||||
return Object.prototype.toString.call(value) === '[object Object]'
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
module.exports = {
|
||||
features: {
|
||||
geolocation: 'geolocation',
|
||||
midi: 'midi',
|
||||
notifications: 'notifications',
|
||||
push: 'push',
|
||||
syncXhr: 'sync-xhr',
|
||||
microphone: 'microphone',
|
||||
camera: 'camera',
|
||||
magnetometer: 'magnetometer',
|
||||
gyroscope: 'gyroscope',
|
||||
speaker: 'speaker',
|
||||
vibrate: 'vibrate',
|
||||
fullscreen: 'fullscreen',
|
||||
payment: 'payment',
|
||||
accelerometer: 'accelerometer',
|
||||
usb: 'usb',
|
||||
vr: 'vr',
|
||||
autoplay: 'autoplay'
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
var config = require('./config')
|
||||
|
||||
module.exports = function makePolicy (options) {
|
||||
return Object.keys(options.features).map(function (featureKey) {
|
||||
const dasherizedKey = config.features[featureKey]
|
||||
return [dasherizedKey].concat(options.features[featureKey]).join(' ')
|
||||
}).join(';')
|
||||
}
|
||||
Reference in New Issue
Block a user