UNPKG

584 BJavaScriptView Raw
1'use strict'
2
3module.exports = (object, checkedMember, allowed) => {
4 let method = object.method
5 if (method === undefined) {
6 object[checkedMember] = allowed
7 return
8 }
9 if (typeof method === 'string') {
10 method = method.split(',')
11 }
12 if (!Array.isArray(method)) {
13 throw new Error('Invalid method specification')
14 }
15 method = method.map(verb => verb.toUpperCase())
16 if (allowed) {
17 method = method.filter(verb => allowed.includes(verb))
18 }
19 if (!method.length) {
20 throw new Error('No method specified (or left)')
21 }
22 object[checkedMember] = method
23}