| 41 | } |
| 42 | |
| 43 | export function buildIndex(data) { |
| 44 | let scopes = false; |
| 45 | |
| 46 | if (data.scopes && Array.isArray(data.scopes)) { |
| 47 | scopes = Object.create(null); |
| 48 | |
| 49 | for (let i = 0; i < data.scopes.length; i++) { |
| 50 | const list = data.scopes[i]; |
| 51 | |
| 52 | if (!list || !Array.isArray(list)) { |
| 53 | throw new Error('Wrong usage format'); |
| 54 | } |
| 55 | |
| 56 | for (const name of list) { |
| 57 | if (hasOwnProperty.call(scopes, name)) { |
| 58 | throw new Error(`Class can't be used for several scopes: ${name}`); |
| 59 | } |
| 60 | |
| 61 | scopes[name] = i + 1; |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | return { |
| 67 | whitelist: buildList(data), |
| 68 | blacklist: buildList(data.blacklist), |
| 69 | scopes |
| 70 | }; |
| 71 | } |