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 🙏

© 2024 – Pkg Stats / Ryan Hefner

boolish

v1.1.0

Published

A utility library for Boolean operations in JavaScript.

Downloads

141

Readme

boolish

boolish is a simple npm package providing utilities for working with Boolean operations. The package includes easy-to-use functions to handle Boolean values and logical coercions in JavaScript projects.

Installation

Install the package via npm:

npm install boolish

Usage

Import and use boolish functions in your project:

// ES6+ Import
import { Not } from 'boolish';

// CommonJS Import
const { Not } = require('boolish');

// Usage example
console.log(Not(true)); // false
console.log(Not(false)); // true

API

Not(value: any): boolean

Description: Returns the logical negation of the provided value. Arguments:

value: Any type of value, which will be coerced to a Boolean.

  • Return Value:

true if value is falsy; otherwise, false.

Example:

Not(true);       // false
Not('');         // true
Not(0);          // true
Not('hello');    // false

And(a: unknown, b: unknown): boolean

Description: Returns true if both a and b are truthy, otherwise returns false. Arguments:

a: Any value to evaluate. b: Any value to evaluate.

Returns:

true if both values are truthy, otherwise false.

Example:

And(true, 1);       // true
And(true, 0);       // false
And("hello", {});   // true

AndAll(...args: unknown[]): boolean

Description: Applies logical AND (&&) to all provided arguments and returns true only if all values are truthy. Arguments:

args: A list of any values to evaluate. The function requires at least one argument.

Returns:

true if all arguments are truthy, otherwise false.

Throws:

An error if no arguments are provided.

Example:

AndAll(true, 1, "hello");     // true
AndAll(true, 1, 0);           // false
AndAll({});                   // true

AndAllValue(...args: unknown[]): unknown

Description: Applies logical AND (&&) to all provided arguments, returning the last truthy value if all are truthy, or the first falsy value encountered. Arguments:

args: A list of any values to evaluate. The function requires at least one argument.

Returns:

The last truthy value if all values are truthy, otherwise the first falsy value encountered.

Throws:

An error if no arguments are provided.

Example:

AndAllValue(true, "Hello", 42);          // 42 (last truthy)
AndAllValue(true, "Hello", 0);           // 0 (first falsy)
AndAllValue(undefined, null, false);     // undefined (first falsy)

AndValue<L, R>(a: L, b: R): L | R

Description: Returns b if both a and b are truthy; otherwise, returns a. Arguments:

a: Any value to evaluate. b: Any value to evaluate.

Returns:

b if both values are truthy; otherwise, a.

Example:

AndValue(true, "Hello");     // "Hello" (both are truthy)
AndValue(true, 0);           // true (0 is falsy)
AndValue(0, "Hello");        // 0 (first falsy)

TypeScript Support

This package is written in TypeScript, providing type definitions for all functions to ensure ease of use and compatibility in TypeScript projects.

Testing

The package uses Jest for testing. To run the tests, use the command:

npm test

Build

boolish is bundled with Rollup for compatibility with both Node.js and browser environments. Use the following command to build the project:

npm run build

Contributing

Contributions are welcome! Please open issues or submit pull requests to improve boolish.

License

This project is licensed under the MIT License. See the LICENSE file for details.