MCPcopy Create free account
hub / github.com/echoVic/blade-code / isValidType

Method isValidType

src/tools/validator.ts:75–94  ·  view source on GitHub ↗

* 检查值类型是否匹配

(value: any, expectedType: string)

Source from the content-addressed store, hash-verified

73 * 检查值类型是否匹配
74 */
75 private static isValidType(value: any, expectedType: string): boolean {
76 if (value === null || value === undefined) {
77 return true; // null/undefined 在某些情况下是允许的
78 }
79
80 switch (expectedType) {
81 case 'string':
82 return typeof value === 'string';
83 case 'number':
84 return typeof value === 'number' && !isNaN(value);
85 case 'boolean':
86 return typeof value === 'boolean';
87 case 'array':
88 return Array.isArray(value);
89 case 'object':
90 return typeof value === 'object' && !Array.isArray(value);
91 default:
92 return false;
93 }
94 }
95
96 /**
97 * 应用默认值

Callers 1

validateValueMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected