(value, options, type)
| 313 | } |
| 314 | |
| 315 | function 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 | |
| 359 | export function extract(input) { |
| 360 | input = removeHash(input); |
no outgoing calls
no test coverage detected
searching dependent graphs…