Cold Brew
A set of helpful JavaScript functions and plugins.
Usage
install
npm i -g cold-brew-plugin
config
configure the chill.json file with the script you want to run
"run": ,
Or you can just run it with the script option:
chill --script myscript.js
run
you can run your script with the key word chill
in which case it will look for a chill.json
script in your current directory, otherwise you can specify a json
script in the second argument.
examples:
- Basic usage:chill
- Specify json script:chill name.json
- Run a singular script with default config scriptchill --script name.js
chill.json
Here is the default chill.json script:
Adding scripts
When cold-brew compiles, it combines all the scripts in the run
array sequentially. Then compiles the whole script. This means that if you define a variable in one script, it will also exist in any scripts after that.
Modules and Plugins
All of the modules and babel plugins, can be removed at any time. If you would like to add another module or babel plug in, just add it to either the scripts or babel array. Cold-brew reads these arrays sequentially, so if your script depends on other features of cold brew make sure to add it last.
Features
So far these are the features that cold-brew includes, however new features are being added daily.
console.color
usage
You can use console.color
to stylize what you log to the console. console.color
is based off of chalk, so anything that works for chalk should work with this.
examples
consolecolorbold consolecolor chalk + 'World' + chalk
process.child
usage
This spawns a child process using thread.js
example
process processchild ;
callbacks
usage
You can pass a callback into any function in cold-brew because every function in cold-brew automatically has a callback appended to it and run when the function is created. The callback name is _callback
.
example
{} ;
Math.tools
usage
Math.tools
uses the mathjs library. For more information on mathjs, please refer to their docs.
examples
Mathtools Mathtools ;
Math.eval
usage
Math.eval
is used to evaluate equations that are strings.
example
Math
Array manipulation
Array.prototype.remove
usage
This removes an element from an array based on its value.
example
let arr = 'foo' 'bar' 'baz'; arr; //[foo, baz]
Array.prototype.findIndex
usage
This produces the index of an array based on an object identifier. It takes in two values, the first is the string identifier and the second is the value that you are looking for.
example
let arr = hello: 'foo' hello: 'baz' hello: 'bar' ; arr; //1
Enum switch
usage
Enum
is used to run a function for all of the elements in an object that you choose. Enum
takes in two values, an object to sort through and another object that instructs it what to do for every element in the first object.
NOTE: Enum
, unlike switch
will run the given function on every element that it runs into, not just the first one.
example
let obj = one: 1 three: 3 //outputs: 1, 3
tests
For more examples, look through the tests
folder.
Contributing
There are no current contributing guidelines.