(object, options)
| 452 | } |
| 453 | |
| 454 | export function stringify(object, options) { |
| 455 | if (!object) { |
| 456 | return ''; |
| 457 | } |
| 458 | |
| 459 | options = { |
| 460 | encode: true, |
| 461 | strict: true, |
| 462 | arrayFormat: 'none', |
| 463 | arrayFormatSeparator: ',', |
| 464 | ...options, |
| 465 | }; |
| 466 | |
| 467 | validateArrayFormatSeparator(options.arrayFormatSeparator); |
| 468 | |
| 469 | const shouldFilter = key => ( |
| 470 | (options.skipNull && isNullOrUndefined(object[key])) |
| 471 | || (options.skipEmptyString && object[key] === '') |
| 472 | ); |
| 473 | |
| 474 | const formatter = encoderForArrayFormat(options); |
| 475 | |
| 476 | const objectCopy = {}; |
| 477 | |
| 478 | for (const [key, value] of Object.entries(object)) { |
| 479 | if (!shouldFilter(key)) { |
| 480 | objectCopy[key] = value; |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | const keys = Object.keys(objectCopy); |
| 485 | |
| 486 | if (options.sort !== false) { |
| 487 | keys.sort(options.sort); |
| 488 | } |
| 489 | |
| 490 | return keys.map(key => { |
| 491 | let value = object[key]; |
| 492 | |
| 493 | // Apply replacer function if provided |
| 494 | if (options.replacer) { |
| 495 | value = options.replacer(key, value); |
| 496 | |
| 497 | // If replacer returns undefined, skip this key |
| 498 | if (value === undefined) { |
| 499 | return ''; |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | if (value === undefined) { |
| 504 | return ''; |
| 505 | } |
| 506 | |
| 507 | if (value === null) { |
| 508 | return encode(key, options); |
| 509 | } |
| 510 | |
| 511 | if (Array.isArray(value)) { |
no test coverage detected
searching dependent graphs…