MCPcopy Create free account
hub / github.com/sindresorhus/query-string / validateArrayFormatSeparator

Function validateArrayFormatSeparator

base.js:208–221  ·  view source on GitHub ↗
(value)

Source from the content-addressed store, hash-verified

206}
207
208function 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
223function encode(value, options) {
224 const type = typeof value;

Callers 2

parseFunction · 0.85
stringifyFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected