npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@marianmeres/parse-boolean

v2.1.0

Published

[![NPM version](https://img.shields.io/npm/v/@marianmeres/parse-boolean.svg)](https://www.npmjs.com/package/@marianmeres/parse-boolean) [![JSR version](https://jsr.io/badges/@marianmeres/parse-boolean)](https://jsr.io/@marianmeres/parse-boolean)

Downloads

579

Readme

@marianmeres/parse-boolean

NPM version JSR version

A little utility which parses any input to boolean. Almost as simple as (v) => !!v except that it handles strings deliberately.

Truthy strings are true, t, yes, y, on, ok, enable, enabled and finite non-zero numeric strings. All other strings are considered falsy. The truthy dictionary can be extended. Case insensitive, trimmed.

Mainly useful for string-to-boolean conversion from text config files, html form values, or similar...

Install

deno add jsr:@marianmeres/parse-boolean
npm install @marianmeres/parse-boolean

Usage

parseBoolean(value: unknown, options?: { strict?: boolean }): boolean

Examples

parseBoolean('yEs');      // true
parseBoolean('ON');       // true
parseBoolean('1');        // true
parseBoolean('1.5');      // true
parseBoolean('');         // false
parseBoolean('foo');      // false
parseBoolean('-0.0');     // false
parseBoolean('{}');       // false
parseBoolean('123abc');   // false (not a valid number)
parseBoolean('Infinity'); // false (not a finite number)
// all non-strings are cast as !!v
parseBoolean({});         // true
parseBoolean(NaN);        // false
parseBoolean(123);        // true

Custom dictionary

Extend the truthy dictionary with your own values:

parseBoolean('yo'); // false
parseBoolean.addTruthy('yo');
parseBoolean('YO'); // true (case insensitive)

parseBoolean.removeTruthy('yo');
parseBoolean('yo'); // false again

Reset all custom additions back to defaults:

parseBoolean.addTruthy('custom');
parseBoolean('custom'); // true
parseBoolean.reset();
parseBoolean('custom'); // false
parseBoolean('yes');    // true (default values still work)

Strict mode

In strict mode parseBoolean throws TypeError when it sees a string that is neither numeric nor present in the truthy or falsy dictionaries. Useful for config parsing, where an unrecognized value should be an error, not silently coerced to false.

parseBoolean('yes',   { strict: true }); // true
parseBoolean('no',    { strict: true }); // false
parseBoolean('maybe', { strict: true }); // throws TypeError

Default falsy dictionary: false, f, no, n, off, disable, disabled. Extend it the same way as the truthy one:

parseBoolean.addFalsy('nope');
parseBoolean('nope', { strict: true }); // false

parseBoolean.removeFalsy('nope');

Isolated instances

The default parseBoolean shares its dictionary via globalThis (so bundler duplicates stay in sync). If you need an isolated parser — e.g. different parts of an app using different vocabularies — use createParseBoolean():

import { createParseBoolean } from '@marianmeres/parse-boolean';

const parse = createParseBoolean();
parse.addTruthy('si');
parse('si');         // true
parseBoolean('si');  // false (global is untouched)

API

parseBoolean(value: unknown, options?: { strict?: boolean }): boolean

Parses any input value to a boolean.

  • Non-string values: standard JavaScript truthy/falsy conversion (!!value).
  • Numeric strings: finite decimals only (integers, floats, scientific notation). Zero is false, non-zero is true. Partial numerics like "123abc" and non-finite values like "Infinity" / "NaN" fall through to the dictionary.
  • Truthy dictionary: "true", "t", "yes", "y", "on", "ok", "enable", "enabled" (case insensitive, trimmed, extensible).
  • Other strings: falsy in default mode; throw TypeError in strict mode unless listed in the falsy dictionary.

parseBoolean.addTruthy(value: string): void

Adds a string to the truthy dictionary. Normalized (lowercased and trimmed).

parseBoolean.removeTruthy(value: string): void

Removes a string from the truthy dictionary. Normalized.

parseBoolean.addFalsy(value: string): void

Adds a string to the falsy dictionary (used only by strict mode). Normalized.

parseBoolean.removeFalsy(value: string): void

Removes a string from the falsy dictionary. Normalized.

parseBoolean.reset(): void

Resets both truthy and falsy dictionaries to their defaults.

createParseBoolean(): ParseBoolean

Returns a fresh parseBoolean instance with its own isolated dictionaries. Has the same surface as the global parseBoolean.

Package Identity

  • Name: @marianmeres/parse-boolean
  • Author: Marian Meres
  • Repository: https://github.com/marianmeres/parse-boolean
  • License: MIT