* Set an option * @param {number | string} key The key can be ID of the property (`in_{ID}`), * the inline name or the internalID. * @param {*} value The new value of the property
(key, value)
| 96 | * @param {*} value The new value of the property |
| 97 | */ |
| 98 | setOption(key, value) { |
| 99 | let propI = ''; |
| 100 | |
| 101 | if (this.#options.inputs[`in_${key}`]) propI = `in_${key}`; |
| 102 | else if (this.#options.inputs[key]) propI = key; |
| 103 | else { |
| 104 | propI = Object.keys(this.#options.inputs).find((I) => ( |
| 105 | this.#options.inputs[I].inline === key |
| 106 | || this.#options.inputs[I].internalID === key |
| 107 | )); |
| 108 | } |
| 109 | |
| 110 | if (propI && this.#options.inputs[propI]) { |
| 111 | const input = this.#options.inputs[propI]; |
| 112 | |
| 113 | const types = { |
| 114 | bool: 'Boolean', |
| 115 | integer: 'Number', |
| 116 | float: 'Number', |
| 117 | text: 'String', |
| 118 | }; |
| 119 | |
| 120 | // eslint-disable-next-line valid-typeof |
| 121 | if (types[input.type] && typeof value !== types[input.type].toLowerCase()) { |
| 122 | throw new Error(`Input '${input.name}' (${propI}) must be a ${types[input.type]} !`); |
| 123 | } |
| 124 | |
| 125 | if (input.options && !input.options.includes(value)) { |
| 126 | throw new Error(`Input '${input.name}' (${propI}) must be one of these values:`, input.options); |
| 127 | } |
| 128 | |
| 129 | input.value = value; |
| 130 | } else throw new Error(`Input '${key}' not found (${propI}).`); |
| 131 | } |
| 132 | }; |
no outgoing calls
no test coverage detected