* Compile argument into trust function. * * @param val
(val: string | string[] | number[])
| 44 | * @param val |
| 45 | */ |
| 46 | function compile(val: string | string[] | number[]) { |
| 47 | let trust |
| 48 | if (typeof val === 'string') trust = [val] |
| 49 | else if (Array.isArray(val)) trust = val.slice() |
| 50 | else throw new TypeError('unsupported trust argument') |
| 51 | |
| 52 | for (let i = 0; i < trust.length; i++) { |
| 53 | val = trust[i] |
| 54 | if (!Object.prototype.hasOwnProperty.call(IP_RANGES, val)) continue |
| 55 | |
| 56 | // Splice in pre-defined range |
| 57 | val = IP_RANGES[val as string] |
| 58 | // eslint-disable-next-line prefer-spread |
| 59 | trust.splice.apply(trust, [i, 1].concat(val as number[])) |
| 60 | i += val.length - 1 |
| 61 | } |
| 62 | return compileTrust(compileRangeSubnets(trust)) |
| 63 | } |
| 64 | /** |
| 65 | * Compile `arr` elements into range subnets. |
| 66 | */ |
no test coverage detected