/**
 * 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;
}
