MCPcopy
hub / github.com/axios/axios / stringifySafely

Function stringifySafely

lib/defaults/index.js:23–36  ·  view source on GitHub ↗

* It takes a string, tries to parse it, and if it fails, it returns the stringified version * of the input * * @param {any} rawValue - The value to be stringified. * @param {Function} parser - A function that parses a string into a JavaScript object. * @param {Function} encoder - A function tha

(rawValue, parser, encoder)

Source from the content-addressed store, hash-verified

21 * @returns {string} A stringified version of the rawValue.
22 */
23function stringifySafely(rawValue, parser, encoder) {
24 if (utils.isString(rawValue)) {
25 try {
26 (parser || JSON.parse)(rawValue);
27 return utils.trim(rawValue);
28 } catch (e) {
29 if (e.name !== 'SyntaxError') {
30 throw e;
31 }
32 }
33 }
34
35 return (encoder || JSON.stringify)(rawValue);
36}
37
38const defaults = {
39 transitional: transitionalDefaults,

Callers 1

index.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…