MCPcopy Create free account
hub / github.com/openai/openai-node / normalize_stringify_options

Function normalize_stringify_options

src/internal/qs/stringify.ts:222–304  ·  view source on GitHub ↗
(
  opts: StringifyOptions = defaults,
)

Source from the content-addressed store, hash-verified

220}
221
222function normalize_stringify_options(
223 opts: StringifyOptions = defaults,
224): NonNullableProperties<Omit<StringifyOptions, 'indices'>> & { indices?: boolean } {
225 if (typeof opts.allowEmptyArrays !== 'undefined' && typeof opts.allowEmptyArrays !== 'boolean') {
226 throw new TypeError('`allowEmptyArrays` option can only be `true` or `false`, when provided');
227 }
228
229 if (typeof opts.encodeDotInKeys !== 'undefined' && typeof opts.encodeDotInKeys !== 'boolean') {
230 throw new TypeError('`encodeDotInKeys` option can only be `true` or `false`, when provided');
231 }
232
233 if (opts.encoder !== null && typeof opts.encoder !== 'undefined' && typeof opts.encoder !== 'function') {
234 throw new TypeError('Encoder has to be a function.');
235 }
236
237 const charset = opts.charset || defaults.charset;
238 if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') {
239 throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined');
240 }
241
242 let format = default_format;
243 if (typeof opts.format !== 'undefined') {
244 if (!has(formatters, opts.format)) {
245 throw new TypeError('Unknown format option provided.');
246 }
247 format = opts.format;
248 }
249 const formatter = formatters[format];
250
251 let filter = defaults.filter;
252 if (typeof opts.filter === 'function' || isArray(opts.filter)) {
253 filter = opts.filter;
254 }
255
256 let arrayFormat: StringifyOptions['arrayFormat'];
257 if (opts.arrayFormat && opts.arrayFormat in array_prefix_generators) {
258 arrayFormat = opts.arrayFormat;
259 } else if ('indices' in opts) {
260 arrayFormat = opts.indices ? 'indices' : 'repeat';
261 } else {
262 arrayFormat = defaults.arrayFormat;
263 }
264
265 if ('commaRoundTrip' in opts && typeof opts.commaRoundTrip !== 'boolean') {
266 throw new TypeError('`commaRoundTrip` must be a boolean, or absent');
267 }
268
269 const allowDots =
270 typeof opts.allowDots === 'undefined' ?
271 !!opts.encodeDotInKeys === true ?
272 true
273 : defaults.allowDots
274 : !!opts.allowDots;
275
276 return {
277 addQueryPrefix: typeof opts.addQueryPrefix === 'boolean' ? opts.addQueryPrefix : defaults.addQueryPrefix,
278 // @ts-ignore
279 allowDots: allowDots,

Callers 1

stringifyFunction · 0.85

Calls 2

hasFunction · 0.90
isArrayFunction · 0.90

Tested by

no test coverage detected