1.5.5 • Published 2 years ago
boolean-jokes v1.5.5
boolean-jokes
ℹ Some useful functions to work with boolean.
Javascript ESModule.
Index of Contents
Installation
npm install boolean-jokes
Functions & Examples
true_false(Buffer:string):boolean
Converts only the strings "true" and "false" to boolean respectively.
// only string true or false are parsed
import { true_false } from 'boolean-jokes'
const converted = await bool( 'true' )
console.log( converted )
map(object, string|number):boolean
Given an object it will map the property name to the corresponding boolean value set.
ℹ It accepts only type object for the
logic
parameter, and it will check if any of the value set for the property is a boolean and not any other type.
ℹ It accepts only type string or number for theagainst
parameter
This will return false
import { map } from 'boolean-jokes'
/**
* @type {string}
*/
const against = 'no'
/**
* @type {{no: boolean, yes: boolean, true: boolean, false: boolean}}
*/
const logic = {
true: true,
false: false,
yes: true,
no: false
}
const matchBool = await map( logic, against )
console.log( matchBool ) // return 'false'
This will reject with:
your against
value haven't matched any of your logic
object. given against
: ok
import { map } from 'boolean-jokes'
/**
* @type {string}
*/
const against = 'ok'
/**
* @type {{no: boolean, yes: boolean, true: boolean, false: boolean}}
*/
const logic = {
true: true,
false: false,
yes: true,
no: false
}
const matchBool = await map( logic, against )
console.log( matchBool ) // reject -> your `against` value haven't matched any of your `logic` object. given `against`: ok