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

chromabrew

v1.0.1

Published

Predict the color of a batch of beer, and convert between known color values and web-friendly hex.

Downloads

14

Readme

Chromabrew

Convert SRM, EBC, or a list of Lovibond values to another color scale, or to a hex color.

Color values are provided by Barley Dog Brewery here

Usage

Install the library:

npm install --save chromabrew

Require the module:

let chromabrew = require('chromabrew');

Pass options which describe a batch to the Batch constructor, or directly to the required module. See the list of accepted options below. Call hex on the returned object to get a color:

new chromabrew.Batch({ srm: 4 }).hex();
// => '#ECE61A'

chromabrew({ srm: 4 }).hex();
// => '#ECE61A'

chromabrew({ ebc: 4 }).hex();
// => '#F8F753'

Convert between color scales:

let batch = chromabrew({ srm: 4 });

batch.srm();
// => 4

batch.ebc();
// => 7.88

batch.mcu();
// => 4.210535199414287

batch.lovibond();
// => 3.407407407407407

Specify which calculation method was used to determine the provided srm or ebc, or which method to use when converting between scales:

let batch = chromabrew({ srm: 14, calculator: 'daniels' });

batch.srm('daniels');
// => 14

// defaults to 'morey'
batch.srm();
// => 14.670088349307665

batch.srm('mosher');
// => 13.099999999999998

// defaults to 'morey'
batch.ebc();
// => 28.9000740481361

batch.hex('daniels');
// => '#B26033'

// defaults to 'morey'
batch.hex();
// => '#A85C37'

Options

Primary Options

Any one of the following options must be passed to the module:

| option | description | type | |-|-|-| | srm | the SRM of a batch | Number | | ebc | the EBC of a batch | Number | | l or lovibond | the degrees Lovibond of a batch | Number | | batch | options describing a batch in detail (see below) | Object |

This option may be used in combination with a known color value (srm, ebc, or l) to specify which calculation method was used:

| option | description | type | |-|-|-| | calculator | the SRM calculation method used: 'morey' (default), 'daniels', 'mosher', or 'barry' † | String |

† apparently they let anyone create a beer color scale

Batch Options

The following options define the batch primary option:

| option | description | type | |-|-|-| | mcu | the MCU of the batch, if it is already known | Number | | v or volume | the total liquid volume of the wort (required) | Number | | ingredients | an Array of ingredient options (see below; required) | Array[Object] | | litres or liters | whether volume is expressed in litres | Boolean | | kilograms or kilos | whether weight of each item in ingredients is expressed in kilograms | Boolean | | metric | shortcut to apply both litres and kilograms options | Boolean |

Ingredient Options

The following options define each ingredient in the ingredients batch option:

| option | description | type | |-|-|-| | l or lovibond | the value in degrees Lovibond of the ingredient (required) | Number | | w or weight | the weight of the ingredient used (required) | Number |

Functional Domain

The domain of valid inputs is 0 through 40 SRM. Input values are rounded to the nearest 0.1 SRM within this domain:

chromabrew({ srm: -1 }).hex() === chromabrew({ srm: 0 }).hex();
// => true

chromabrew({ srm: Number.MAX_VALUE }).hex() === chromabrew({ srm: 40 }).hex();
// => true

chromabrew({ srm: Math.PI }).hex() === chromabrew({ srm: 3.1 }).hex();
// => true  

The 'daniels' and 'mosher' SRM calculation scales have a minimum result of 8.4 and 4.7, respectively. Where a provided srm would result in a negative mcu, the mcu is set to 0:

let daniels = chromabrew({ srm: 4, calculator: 'daniels' });

daniels.mcu();
// => 0

daniels.srm();
// => 0

daniels.srm('daniels');
// => 8.4

let mosher = chromabrew({ srm: 4, calculator: 'mosher' });

mosher.mcu();
// => 0

mosher.srm();
// => 0

mosher.srm('mosher');
// => 4.7