UNPKG

validation-query

Version:

**Validation Query** Validation Query is a utility library providing a range of functions for managing query strings in web applications. It offers features for validating, decoding, and parsing query string parameters, as well as inspecting the current e

16 lines (14 loc) 452 B
/** * Parses a string value to a boolean. * * The function returns `true` for any non-falsy string value, and `false` for * the following falsy string values: `'f'`, `'false'`, `'n'`, `'no'`, and * `'0'` (case-insensitive). * * @param val - The string value to parse. * @returns The boolean value. */ const falsy: RegExp = /^(?:f(?:alse)?|no?|0+)$/i; export function parseBoolean(val: string): boolean { return !falsy.test(val) && !!val; }