MCPcopy Create free account
hub / github.com/dipscope/TypeManager.TS / convert

Method convert

src/serializers/string-serializer.ts:90–110  ·  view source on GitHub ↗

* Converts provided value to the target type value. * * @param {any} x Some value. * @param {SerializerContext } serializerContext Type serializer context. * * @returns {TypeLike } Converted value or original value.

(x: any, serializerContext: SerializerContext<string>)

Source from the content-addressed store, hash-verified

88 * @returns {TypeLike<string>} Converted value or original value.
89 */
90 private convert(x: any, serializerContext: SerializerContext<string>): TypeLike<string>
91 {
92 if (typeof x === 'number' || typeof x === 'boolean')
93 {
94 return String(x);
95 }
96
97 if (x instanceof Date)
98 {
99 return x.toISOString();
100 }
101
102 if (typeof x === 'object')
103 {
104 return JSON.stringify(x);
105 }
106
107 serializerContext.logger.error('StringSerializer', `${serializerContext.jsonPath}: cannot convert value to string.`, x);
108
109 return undefined;
110 }
111}

Callers 2

serializeMethod · 0.95
deserializeMethod · 0.95

Calls 2

stringifyMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected