MCPcopy Create free account
hub / github.com/PageLeay/celestial-runtime / checkType

Function checkType

lib.esm/utils/properties.js:6–26  ·  view source on GitHub ↗

* Property helper functions. * * @_subsection api/utils:Properties [about-properties]

(value, type, name)

Source from the content-addressed store, hash-verified

4 * @_subsection api/utils:Properties [about-properties]
5 */
6function 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.

Callers 1

definePropertiesFunction · 0.70

Calls 2

mapMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected