2.0.2 • Published 1 year ago

@wkovacs64/booleanize v2.0.2

Weekly downloads
12
License
MIT
Repository
github
Last release
1 year ago

@wkovacs64/booleanize

A small utility to coerce a value to its boolean equivalent.

npm Version Build Status Code Coverage

Installation

npm install @wkovacs64/booleanize

Usage

The primary purpose of this package is to deal with environment variables received as strings. For example, SOME_CONDITIONAL=false will be truthy if you just pass it to the Boolean constructor as it comes through as a non-empty string. Instead, pass it to booleanize and you will get the value back that I expect. Please note that it may not be the value YOU expect, but I created this primarily for myself. 🙂

Basically, the following strings are considered falsy:

  • 'null'
  • 'undefined'
  • 'false'
  • 'no'
  • '0'

Example

# .env
SOME_CONDITIONAL=false
import { booleanize } from '@wkovacs64/booleanize';

Boolean(process.env.SOME_CONDITIONAL); // true 😕
booleanize(process.env.SOME_CONDITIONAL); // false 😊

License

This module is distributed under the MIT License.

2.0.2

1 year ago

2.0.1

2 years ago

2.0.0

4 years ago

1.0.0

4 years ago