| 206 | } |
| 207 | |
| 208 | function validateArrayFormatSeparator(value) { |
| 209 | // A lone surrogate is one UTF-16 code unit, but it is not a character and cannot be percent-encoded, so it would make the encoder throw a `URIError` later instead. Whitespace cannot be a separator because `parse()` ignores leading and trailing whitespace in the query. A separator that only works sometimes, like `%` or a hexadecimal digit, is documented as unsupported instead, so that the encoder can keep its best-effort behavior for it. |
| 210 | if (typeof value !== 'string' || value.length !== 1) { |
| 211 | throw new TypeError('arrayFormatSeparator must be a single character'); |
| 212 | } |
| 213 | |
| 214 | if (value.trim() === '') { |
| 215 | throw new TypeError('arrayFormatSeparator must not be whitespace, since parse() ignores leading and trailing whitespace in the query'); |
| 216 | } |
| 217 | |
| 218 | if (/\p{Surrogate}/v.test(value)) { |
| 219 | throw new TypeError('arrayFormatSeparator must not be a lone surrogate, since it cannot be percent-encoded'); |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | function encode(value, options) { |
| 224 | const type = typeof value; |