MCPcopy Create free account
hub / github.com/CashScript/cashscript / stringify

Function stringify

packages/utils/src/artifact.ts:87–105  ·  view source on GitHub ↗
(
  obj: any,
  format: 'json' | 'ts',
  indentationLevel: number = 1,
  isArrayElement: boolean = false,
)

Source from the content-addressed store, hash-verified

85// stays compact, while standalone objects assigned to a property (e.g. `compiler.options`) keep
86// their values expanded one per line.
87function stringify(
88 obj: any,
89 format: 'json' | 'ts',
90 indentationLevel: number = 1,
91 isArrayElement: boolean = false,
92): string {
93 if (typeof obj === 'string') return formatString(obj, format);
94
95 // Numbers, booleans and null are represented identically in JSON and TS
96 if (obj === null || typeof obj === 'number' || typeof obj === 'boolean') {
97 return JSON.stringify(obj);
98 }
99
100 if (Array.isArray(obj)) return formatArray(obj, format, indentationLevel, isArrayElement);
101
102 if (typeof obj === 'object') return formatObject(obj, format, indentationLevel, isArrayElement);
103
104 throw new Error(`Unsupported type: ${typeof obj}`);
105}
106
107function formatString(value: string, format: 'json' | 'ts'): string {
108 // JSON strings use standard double-quoted escaping

Callers 10

formatArtifactFunction · 0.85
formatArrayFunction · 0.85
formatObjectFunction · 0.85
mecenas.tsFile · 0.85
announcement.tsFile · 0.85
p2pkh.jsFile · 0.85
p2pkh.tsFile · 0.85
hodl_vault.tsFile · 0.85

Calls 3

formatStringFunction · 0.85
formatArrayFunction · 0.85
formatObjectFunction · 0.85

Tested by

no test coverage detected