MCPcopy Index your code
hub / github.com/sindresorhus/query-string / parseValue

Function parseValue

base.js:315–357  ·  view source on GitHub ↗
(value, options, type)

Source from the content-addressed store, hash-verified

313}
314
315function parseValue(value, options, type) {
316 if (type === 'string' && typeof value === 'string') {
317 return value;
318 }
319
320 if (typeof type === 'function' && typeof value === 'string') {
321 return type(value);
322 }
323
324 if (type === 'boolean' && value === null) {
325 return true;
326 }
327
328 if (type === 'boolean' && value !== null && (value.toLowerCase() === 'true' || value.toLowerCase() === 'false')) {
329 return value.toLowerCase() === 'true';
330 }
331
332 if (type === 'boolean' && value !== null && (value.toLowerCase() === '1' || value.toLowerCase() === '0')) {
333 return value.toLowerCase() === '1';
334 }
335
336 if (type === 'string[]' && options.arrayFormat !== 'none' && typeof value === 'string') {
337 return [value];
338 }
339
340 if (type === 'number[]' && options.arrayFormat !== 'none' && !Number.isNaN(Number(value)) && (typeof value === 'string' && value.trim() !== '')) {
341 return [Number(value)];
342 }
343
344 if (type === 'number' && !Number.isNaN(Number(value)) && (typeof value === 'string' && value.trim() !== '')) {
345 return Number(value);
346 }
347
348 if (options.parseBooleans && value !== null && (value.toLowerCase() === 'true' || value.toLowerCase() === 'false')) {
349 return value.toLowerCase() === 'true';
350 }
351
352 if (options.parseNumbers && !Number.isNaN(Number(value)) && (typeof value === 'string' && value.trim() !== '')) {
353 return Number(value);
354 }
355
356 return value;
357}
358
359export function extract(input) {
360 input = removeHash(input);

Callers 1

parseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…