MCPcopy Create free account
hub / github.com/nodejs/node / serializeJavascriptValueToJSONString

Function serializeJavascriptValueToJSONString

deps/undici/src/lib/web/infra/index.js:202–216  ·  view source on GitHub ↗
(value)

Source from the content-addressed store, hash-verified

200
201// https://infra.spec.whatwg.org/#serialize-a-javascript-value-to-a-json-string
202function serializeJavascriptValueToJSONString (value) {
203 // 1. Let result be ? Call(%JSON.stringify%, undefined, « value »).
204 const result = JSON.stringify(value)
205
206 // 2. If result is undefined, then throw a TypeError.
207 if (result === undefined) {
208 throw new TypeError('Value is not JSON serializable')
209 }
210
211 // 3. Assert: result is a string.
212 assert(typeof result === 'string')
213
214 // 4. Return result.
215 return result
216}
217
218module.exports = {
219 collectASequenceOfCodePoints,

Callers 1

jsonMethod · 0.50

Calls 1

assertFunction · 0.50

Tested by

no test coverage detected