(object: any, opts: StringifyOptions = {})
| 304 | } |
| 305 | |
| 306 | export function stringify(object: any, opts: StringifyOptions = {}) { |
| 307 | let obj = object; |
| 308 | const options = normalize_stringify_options(opts); |
| 309 | |
| 310 | let obj_keys: PropertyKey[] | undefined; |
| 311 | let filter; |
| 312 | |
| 313 | if (typeof options.filter === 'function') { |
| 314 | filter = options.filter; |
| 315 | obj = filter('', obj); |
| 316 | } else if (isArray(options.filter)) { |
| 317 | filter = options.filter; |
| 318 | obj_keys = filter; |
| 319 | } |
| 320 | |
| 321 | const keys: string[] = []; |
| 322 | |
| 323 | if (typeof obj !== 'object' || obj === null) { |
| 324 | return ''; |
| 325 | } |
| 326 | |
| 327 | const generateArrayPrefix = array_prefix_generators[options.arrayFormat]; |
| 328 | const commaRoundTrip = generateArrayPrefix === 'comma' && options.commaRoundTrip; |
| 329 | |
| 330 | if (!obj_keys) { |
| 331 | obj_keys = Object.keys(obj); |
| 332 | } |
| 333 | |
| 334 | if (options.sort) { |
| 335 | obj_keys.sort(options.sort); |
| 336 | } |
| 337 | |
| 338 | const sideChannel = new WeakMap(); |
| 339 | for (let i = 0; i < obj_keys.length; ++i) { |
| 340 | const key = obj_keys[i]!; |
| 341 | |
| 342 | if (options.skipNulls && obj[key] === null) { |
| 343 | continue; |
| 344 | } |
| 345 | push_to_array( |
| 346 | keys, |
| 347 | inner_stringify( |
| 348 | obj[key], |
| 349 | key, |
| 350 | // @ts-expect-error |
| 351 | generateArrayPrefix, |
| 352 | commaRoundTrip, |
| 353 | options.allowEmptyArrays, |
| 354 | options.strictNullHandling, |
| 355 | options.skipNulls, |
| 356 | options.encodeDotInKeys, |
| 357 | options.encode ? options.encoder : null, |
| 358 | options.filter, |
| 359 | options.sort, |
| 360 | options.allowDots, |
| 361 | options.serializeDate, |
| 362 | options.format, |
| 363 | options.formatter, |
no test coverage detected