This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (werkstatt) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Werkstatt
🛠 Useful functions to encapsulate common scenarios.
As described here, is good to encapsulate conditionals to make our code more readable, reusable and avoid ambiguities. Also to avoid potential bugs due to some javascript features are error-prone:
let name =null;typeof name;// "object"
Clearly, null is not an object. More of that 👉🏼here.
This is then, a package that encapsulates conditionals, but also other util functions.
⚠️ WARNING: This is also a proof of concept. Some of the functions' names may not make all the sense to you or also may be many breaking changes.
Whenever JavaScript expects a boolean value (e.g. for the condition of an if statement), any value can be used. It will be interpreted as either true or false. The following values are interpreted as false:
undefined, null
Boolean: false
Number: -0, NaN
String: ''
Speaking JavaScript by Alex Rauschmayer
That means that those values tend to to be false. So if you pass as parameter to isTruthy function any of those values, it will return false. All other values are considered true.
Note: isEmpty currently supports array, object and string only.
has
Arguments
argument
type
description
returns
firstArgument
number
first value to be evaluated
boolean
secondArgument
number
second value to be evaluated
boolean
const{ has }=require("werkstatt");has([3,5],3);// -> truehas(["Hola","adios"],"true");// -> falsehas("Jorge","e");// -> true
isNull
Arguments
argument
type
description
returns
value
any
value to be evaluated
boolean
const{ isNull }=require("werkstatt");var name =null;isNull(name);// -> trueisNull("Hola");// -> false
every
Arguments
argument
type
description
returns
args
array
arguments to match to a specific type
boolean
const{ every }=require("werkstatt");every("adios"==="adios","hola"==="hola").is.true;// -> trueevery("adios","hola").is.string;// -> trueevery(1,2).is.number;// -> true
compose
Arguments
argument
type
description
returns
fns
array
functions to be executed
function
const{ compose }=require("werkstatt");consth=(n)=> n /2;constg=(n)=> n +1;constf=(n)=> n *2;compose(f, g, h)(20);// -> 22
removeFrom
Arguments
argument
type
description
returns
item
array, object
item on where to remove from
copy of item with props or values removed
const{ removeFrom }=require("werkstatt");const object ={name:"Jorge",age:20,sex:"M",};// pass an array of propsconst props =["name","sex"];const newObject =removeFrom(object, props);// or one prop as stringconst newObject =removeFrom(object,"name");// pass an array of valuesconst array =["red","blue","pink"];const values =["blue","red"];const newArray =removeFrom(array, values);// or one value as stringconst array =["red","blue"];const value ="blue";const newArray =removeFrom(array, value);
more coming soon ✨
🙌🏽 Contribute
Fork and clone the repo
Run npm install to install dependencies
Create a branch for your PR with git checkout -b your-branch-name
To keep master branch pointing to remote repository and make
pull requests from branches on your fork. To do this, run: