MCPcopy
hub / github.com/directus/directus / getStringifiedValue

Function getStringifiedValue

app/src/utils/get-stringified-value.ts:10–23  ·  view source on GitHub ↗
(
	value: string | object | number | boolean | unknown | undefined,
	isObjectLike: boolean,
)

Source from the content-addressed store, hash-verified

8 * @returns - JSON stringified value or a plain string
9 */
10export function getStringifiedValue(
11 value: string | object | number | boolean | unknown | undefined,
12 isObjectLike: boolean,
13): string {
14 if (!value) return '';
15
16 if (isObjectLike || typeof value === 'object') {
17 // If the value is a string and is a valid JSON, parse it first to avoid unnecessary double escaped quotation marks
18 const valueToStringify = typeof value === 'string' && isValidJSON(String(value)) ? parseJSON(String(value)) : value;
19 return JSON.stringify(valueToStringify, null, 4);
20 }
21
22 return String(value);
23}

Callers 1

Calls 2

isValidJSONFunction · 0.90
parseJSONFunction · 0.90

Tested by

no test coverage detected