Socket
Socket
Sign inDemoInstall

chromabrew

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    chromabrew

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


Version published
Weekly downloads
4
decreased by-20%
Maintainers
1
Install size
19.8 kB
Created
Weekly downloads
 

Readme

Source

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:

optiondescriptiontype
srmthe SRM of a batchNumber
ebcthe EBC of a batchNumber
l or lovibondthe degrees Lovibond of a batchNumber
batchoptions 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:

optiondescriptiontype
calculatorthe 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:

optiondescriptiontype
mcuthe MCU of the batch, if it is already knownNumber
v or volumethe total liquid volume of the wort (required)Number
ingredientsan Array of ingredient options (see below; required)Array[Object]
litres or literswhether volume is expressed in litresBoolean
kilograms or kiloswhether weight of each item in ingredients is expressed in kilogramsBoolean
metricshortcut to apply both litres and kilograms optionsBoolean
Ingredient Options

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

optiondescriptiontype
l or lovibondthe value in degrees Lovibond of the ingredient (required)Number
w or weightthe 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

Keywords

FAQs

Last updated on 13 May 2019

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc