MCPcopy
hub / github.com/cure53/DOMPurify / stringifyValue

Function stringifyValue

src/utils.ts:201–251  ·  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

199 * @returns A string representation of the provided value.
200 */
201function stringifyValue(value: unknown): string {
202 switch (typeof value) {
203 case 'string': {
204 return value;
205 }
206
207 case 'number': {
208 return numberToString(value);
209 }
210
211 case 'boolean': {
212 return booleanToString(value);
213 }
214
215 case 'bigint': {
216 return bigintToString ? bigintToString(value) : '0';
217 }
218
219 case 'symbol': {
220 return symbolToString ? symbolToString(value) : 'Symbol()';
221 }
222
223 case 'undefined': {
224 return objectToString(value);
225 }
226
227 case 'function':
228 case 'object': {
229 if (value === null) {
230 return objectToString(value);
231 }
232
233 const valueAsRecord = value as Record<string, any>;
234 const valueToString = lookupGetter(valueAsRecord, 'toString');
235
236 if (typeof valueToString === 'function') {
237 const stringified = valueToString(valueAsRecord);
238
239 return typeof stringified === 'string'
240 ? stringified
241 : objectToString(stringified);
242 }
243
244 return objectToString(value);
245 }
246
247 default: {
248 return objectToString(value);
249 }
250 }
251}
252
253/**
254 * 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

Used in the wild real call sites across dependent graphs

searching dependent graphs…