* Sets the data value and type and then validates them. * * @param {*} value * - The value of the input data. * @param {number} type * - The data type of value, see Dish enums.
(value, type)
| 167 | * - The data type of value, see Dish enums. |
| 168 | */ |
| 169 | set(value, type) { |
| 170 | if (typeof type === "string") { |
| 171 | type = Dish.typeEnum(type); |
| 172 | } |
| 173 | |
| 174 | log.debug("Dish type: " + Dish.enumLookup(type)); |
| 175 | this.value = value; |
| 176 | this.type = type; |
| 177 | |
| 178 | if (!this.valid()) { |
| 179 | const sample = Utils.truncate(JSON.stringify(this.value), 25); |
| 180 | throw new DishError(`Data is not a valid ${Dish.enumLookup(type)}: ${sample}`); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Returns the Dish as the given type, without mutating the original dish. |
no test coverage detected