MCPcopy
hub / github.com/Unitech/pm2 / internalStringify

Function internalStringify

lib/tools/json5.js:665–742  ·  view source on GitHub ↗
(holder, key, isTopLevel)

Source from the content-addressed store, hash-verified

663 // End
664
665 function internalStringify(holder, key, isTopLevel) {
666 var buffer, res;
667
668 // Replace the value, if necessary
669 var obj_part = getReplacedValueOrUndefined(holder, key, isTopLevel);
670
671 if (obj_part && !isDate(obj_part)) {
672 // unbox objects
673 // don't unbox dates, since will turn it into number
674 obj_part = obj_part.valueOf();
675 }
676 switch(typeof obj_part) {
677 case "boolean":
678 return obj_part.toString();
679
680 case "number":
681 if (isNaN(obj_part) || !isFinite(obj_part)) {
682 return "null";
683 }
684 return obj_part.toString();
685
686 case "string":
687 return escapeString(obj_part.toString());
688
689 case "object":
690 if (obj_part === null) {
691 return "null";
692 } else if (isArray(obj_part)) {
693 checkForCircular(obj_part);
694 buffer = "[";
695 objStack.push(obj_part);
696
697 for (var i = 0; i < obj_part.length; i++) {
698 res = internalStringify(obj_part, i, false);
699 buffer += makeIndent(indentStr, objStack.length);
700 if (res === null || typeof res === "undefined") {
701 buffer += "null";
702 } else {
703 buffer += res;
704 }
705 if (i < obj_part.length-1) {
706 buffer += ",";
707 } else if (indentStr) {
708 buffer += "\n";
709 }
710 }
711 objStack.pop();
712 buffer += makeIndent(indentStr, objStack.length, true) + "]";
713 } else {
714 checkForCircular(obj_part);
715 buffer = "{";
716 var nonEmpty = false;
717 objStack.push(obj_part);
718 for (var prop in obj_part) {
719 if (obj_part.hasOwnProperty(prop)) {
720 var value = internalStringify(obj_part, prop, false);
721 isTopLevel = false;
722 if (typeof value !== "undefined" && value !== null) {

Callers 1

json5.jsFile · 0.85

Calls 8

isDateFunction · 0.85
escapeStringFunction · 0.85
isArrayFunction · 0.85
checkForCircularFunction · 0.85
makeIndentFunction · 0.85
isWordFunction · 0.85
toStringMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…