MCPcopy Create free account
hub / github.com/BridgeAR/safe-stable-stringify / stringify

Function stringify

index.js:705–735  ·  view source on GitHub ↗
(value, replacer, space)

Source from the content-addressed store, hash-verified

703 }
704
705 function stringify (value, replacer, space) {
706 if (arguments.length > 1) {
707 let spacer = ''
708 if (typeof space === 'number') {
709 spacer = ' '.repeat(Math.max(0, Math.min(space, 10)))
710 } else if (typeof space === 'string') {
711 spacer = space.slice(0, 10)
712 }
713 if (replacer != null) {
714 if (typeof replacer === 'function') {
715 if (safe) {
716 replacer = makeSafe(replacer, replacer.name)
717 }
718 return stringifyFnReplacer('', { '': value }, [], replacer, spacer, '')
719 }
720 if (Array.isArray(replacer)) {
721 return typeof value === 'object'
722 ? stringifyArrayReplacer('', value, [], getUniqueReplacerSet(replacer), spacer, '')
723 : stringifyPrimitive(value)
724 }
725 }
726 if (spacer.length !== 0) {
727 return typeof value === 'object'
728 ? stringifyIndent('', value, [], spacer, '')
729 : stringifyPrimitive(value)
730 }
731 }
732 return typeof value === 'object'
733 ? stringifyObject('', value, [])
734 : stringifyPrimitive(value)
735 }
736
737 return stringify
738}

Callers 4

benchmark.jsFile · 0.85
test.jsFile · 0.85
consumer.cjsFile · 0.85
consumer.mjsFile · 0.85

Calls 7

makeSafeFunction · 0.85
stringifyFnReplacerFunction · 0.85
stringifyArrayReplacerFunction · 0.85
getUniqueReplacerSetFunction · 0.85
stringifyPrimitiveFunction · 0.85
stringifyIndentFunction · 0.85
stringifyObjectFunction · 0.85

Tested by

no test coverage detected