Socket
Book a DemoInstallSign in
Socket

bool2str

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bool2str

(cond ? yes : no) but throw if arg types are not (bool, string, string).

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
0
Created
Source

bool2str

(cond ? yes : no) but throw if arg types are not (bool, string, string).

Why?

  • To help with situations like YAML bool/string accidents: When you evaluate an unquoted YAML no as a naive if () condition in JavaScript or PHP, it becomes equivalent to yes, since both are non-empty strings.

API

This module exports one function that holds some others:

bool2str(cond, yes, no, trace)

If cond is a boolean, and yes and no both are strings, return (cond ? yes : no). If any of the arguments have the wrong type, instead throw an error complaining about them. The trace (ideally a string with a hint) will be appended to the error message in order to help you find where the problem originated.

bool2str.curry(yes, no, trace) (alias: .c)

Verify that the yes and no arguments are strings. Throw an error otherwise. If they are, prepare (and return) a function that takes one argument cond in order to then call bool2str with the other, pre-defined arguments.

Usage

see test/usage.mjs.

Known issues

  • Needs more/better tests and docs.

 

License

ISC

Keywords

boolean

FAQs

Package last updated on 10 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts