* Property helper functions. * * @_subsection api/utils:Properties [about-properties]
(value, type, name)
| 4 | * @_subsection api/utils:Properties [about-properties] |
| 5 | */ |
| 6 | function checkType(value, type, name) { |
| 7 | const types = type.split("|").map(t => t.trim()); |
| 8 | for (let i = 0; i < types.length; i++) { |
| 9 | switch (type) { |
| 10 | case "any": |
| 11 | return; |
| 12 | case "bigint": |
| 13 | case "boolean": |
| 14 | case "number": |
| 15 | case "string": |
| 16 | if (typeof (value) === type) { |
| 17 | return; |
| 18 | } |
| 19 | } |
| 20 | } |
| 21 | const error = new Error(`invalid value for type ${type}`); |
| 22 | error.code = "INVALID_ARGUMENT"; |
| 23 | error.argument = `value.${name}`; |
| 24 | error.value = value; |
| 25 | throw error; |
| 26 | } |
| 27 | /** |
| 28 | * Resolves to a new object that is a copy of %%value%%, but with all |
| 29 | * values resolved. |
no test coverage detected