MCPcopy Create free account
hub / github.com/cure53/DOMPurify / stringifyValue

Function stringifyValue

src/utils.ts:224–274  ·  view source on GitHub ↗

* Convert non-node values into strings without depending on direct property access. * * @param value - The value to stringify. * @returns A string representation of the provided value.

(value: unknown)

Source from the content-addressed store, hash-verified

222 * @returns A string representation of the provided value.
223 */
224function stringifyValue(value: unknown): string {
225 switch (typeof value) {
226 case 'string': {
227 return value;
228 }
229
230 case 'number': {
231 return numberToString(value);
232 }
233
234 case 'boolean': {
235 return booleanToString(value);
236 }
237
238 case 'bigint': {
239 return bigintToString ? bigintToString(value) : '0';
240 }
241
242 case 'symbol': {
243 return symbolToString ? symbolToString(value) : 'Symbol()';
244 }
245
246 case 'undefined': {
247 return objectToString(value);
248 }
249
250 case 'function':
251 case 'object': {
252 if (value === null) {
253 return objectToString(value);
254 }
255
256 const valueAsRecord = value as Record<string, any>;
257 const valueToString = lookupGetter(valueAsRecord, 'toString');
258
259 if (typeof valueToString === 'function') {
260 const stringified = valueToString(valueAsRecord);
261
262 return typeof stringified === 'string'
263 ? stringified
264 : objectToString(stringified);
265 }
266
267 return objectToString(value);
268 }
269
270 default: {
271 return objectToString(value);
272 }
273 }
274}
275
276/**
277 * This method automatically checks if the prop is function or getter and behaves accordingly.

Callers 1

createDOMPurifyFunction · 0.85

Calls 1

lookupGetterFunction · 0.85

Tested by

no test coverage detected