MCPcopy Create free account
hub / github.com/ljharb/qs / stringify

Function stringify

lib/stringify.js:65–206  ·  view source on GitHub ↗
(
    object,
    prefix,
    generateArrayPrefix,
    commaRoundTrip,
    allowEmptyArrays,
    strictNullHandling,
    skipNulls,
    encodeDotInKeys,
    encoder,
    filter,
    sort,
    allowDots,
    serializeDate,
    format,
    formatter,
    encodeValuesOnly,
    charset,
    sideChannel
)

Source from the content-addressed store, hash-verified

63var sentinel = {};
64
65var stringify = function stringify(
66 object,
67 prefix,
68 generateArrayPrefix,
69 commaRoundTrip,
70 allowEmptyArrays,
71 strictNullHandling,
72 skipNulls,
73 encodeDotInKeys,
74 encoder,
75 filter,
76 sort,
77 allowDots,
78 serializeDate,
79 format,
80 formatter,
81 encodeValuesOnly,
82 charset,
83 sideChannel
84) {
85 var obj = object;
86
87 var tmpSc = sideChannel;
88 var step = 0;
89 var findFlag = false;
90 while ((tmpSc = tmpSc.get(sentinel)) !== void undefined && !findFlag) {
91 // Where object last appeared in the ref tree
92 var pos = tmpSc.get(object);
93 step += 1;
94 if (typeof pos !== 'undefined') {
95 if (pos === step) {
96 throw new RangeError('Cyclic object value');
97 } else {
98 findFlag = true; // Break while
99 }
100 }
101 if (typeof tmpSc.get(sentinel) === 'undefined') {
102 step = 0;
103 }
104 }
105
106 if (typeof filter === 'function') {
107 obj = filter(prefix, obj);
108 } else if (obj instanceof Date) {
109 obj = serializeDate(obj);
110 } else if (generateArrayPrefix === 'comma' && isArray(obj)) {
111 obj = utils.maybeMap(obj, function (value) {
112 if (value instanceof Date) {
113 return serializeDate(value);
114 }
115 return value;
116 });
117 }
118
119 if (obj === null) {
120 if (strictNullHandling) {
121 return formatter(encoder && !encodeValuesOnly ? encoder(prefix, defaults.encoder, charset, 'key', format) : prefix);
122 }

Callers 1

stringify.jsFile · 0.85

Calls 5

filterFunction · 0.85
serializeDateFunction · 0.85
encoderFunction · 0.85
isNonNullishPrimitiveFunction · 0.85
pushToArrayFunction · 0.85

Tested by

no test coverage detected