brauhausjs

所属分类:数值算法/人工智能
开发工具:CoffeeScript
文件大小:0KB
下载次数:0
上传日期:2014-09-28 16:16:43
上 传 者sh-1993
说明:  在服务器和浏览器上用于家庭酿造的啤酒配方计算器
(A beer recipe calculator for homebrewing on servers and in browsers)

文件列表:
.npmignore (51, 2014-09-28)
.travis.yml (169, 2014-09-28)
Gulpfile.coffee (1484, 2014-09-28)
dist/ (0, 2014-09-28)
dist/brauhaus.min.js (20813, 2014-09-28)
img/ (0, 2014-09-28)
img/logo.html (413, 2014-09-28)
img/logo.png (21333, 2014-09-28)
img/weizen.png (42168, 2014-09-28)
package.json (1731, 2014-09-28)
src/ (0, 2014-09-28)
src/base.coffee (2590, 2014-09-28)
src/fermentable.coffee (2738, 2014-09-28)
src/globals.coffee (1280, 2014-09-28)
src/mash.coffee (1112, 2014-09-28)
src/mashStep.coffee (2608, 2014-09-28)
src/recipe.coffee (17468, 2014-09-28)
src/spice.coffee (1884, 2014-09-28)
src/util.coffee (4588, 2014-09-28)
src/yeast.coffee (585, 2014-09-28)
test/ (0, 2014-09-28)
test/color.coffee (1355, 2014-09-28)
test/conversions.coffee (4025, 2014-09-28)
test/fermentable.coffee (2213, 2014-09-28)
test/recipe.coffee (10292, 2014-09-28)
test/test.html (712, 2014-09-28)

![Brauhaus.js](https://raw.github.com/homebrewing/brauhausjs/master/img/logo.png) [![Dependency Status](https://gemnasium.com/homebrewing/brauhausjs.png)](https://gemnasium.com/homebrewing/brauhausjs) [![Build Status](https://travis-ci.org/homebrewing/brauhausjs.png)](https://travis-ci.org/homebrewing/brauhausjs) [![Coverage Status](https://coveralls.io/repos/homebrewing/brauhausjs/badge.png?branch=master)](https://coveralls.io/r/homebrewing/brauhausjs?branch=master) [![NPM version](https://badge.fury.io/js/brauhaus.png)](http://badge.fury.io/js/brauhaus) A javascript library for homebrew beer calculations both in the browser and on the server. Features include: * Support for multiple Javascript runtimes * Node.js 0.6.x, 0.8.x, 0.10.x, 0.11.x * Chrome, Firefox, Internet Explorer 9+, Safari, Opera, etc * Calculate estimated OG, FG, IBU, ABV, SRM color, calories, and more * Tinseth and Rager IBU calculation formula support * Pellets vs. whole hops support * Late addition boil support * Dry hopping support * Automatically generated recipe instructions and timeline * Estimate monetary recipe cost in USD based on ingredients * Grade recipes based on recipe completeness * Built-in unit conversions (kg <-> lb/oz, liter <-> gallon, temps, etc) * Color in °SRM to name, °EBC, °Lovibond, RGB conversions, CSS color, etc * Plugin support to add additional features * Lightweight - about 28kb when minified Plugins provide the following features: * [BeerXML import / export (brauhaus-beerxml)](https://github.com/homebrewing/brauhaus-beerxml) * [BJCP style catalog (brauhaus-styles)](https://github.com/homebrewing/brauhaus-styles) * [Recipe diffs (brauhaus-diff)](https://github.com/homebrewing/brauhaus-diff) Brauhaus.js was developed with and for [Malt.io](http://www.malt.io/), a community website for homebrewers to create recipes and share their love of homebrewing beer. Interactive Examples -------------------- * [Basic Example (Javascript)](http://jsfiddle.net/danielgtaylor/wPYGw/) * [Basic Example (Coffeescript)](http://jsfiddle.net/danielgtaylor/47Uqu/) * [Recipe Timeline (Coffeescript)](http://jsfiddle.net/danielgtaylor/3FEBX/) * [BeerXML import (Coffeescript)](http://jsfiddle.net/danielgtaylor/6cj3N/) * [BJCP Styles (Coffeescript)](http://jsfiddle.net/danielgtaylor/q5rHF/) Installation ------------ There are two ways to use Brauhaus.js - either in a web browser (client-side) or on e.g. Node.js (server-side). ### Web Browser (client-side use) To use Brauhaus.js in a web browser, simply download the following file and include it as you would any other script: * [Download the latest brauhaus.min.js](https://raw.github.com/homebrewing/brauhausjs/master/dist/brauhaus.min.js) Plugins: * [Download the latest brauhaus-beerxml.min.js](https://raw.github.com/homebrewing/brauhaus-beerxml/master/dist/brauhaus-beerxml.min.js) * [Download the latest brauhaus-styles.min.js](https://raw.github.com/homebrewing/brauhaus-styles/master/dist/brauhaus-styles.min.js) * [Download the latest brauhaus-diff.min.js](https://raw.github.com/homebrewing/brauhaus-diff/master/dist/brauhaus-diff.min.js) ```html ``` ### Node.js (server-side use) For Node.js, you can easily install Brauhaus.js and plugins using `npm`: ```bash npm install brauhaus ``` Quick Example (CoffeeScript) ---------------------------- Here is an example of how to use the library from CoffeeScript: ```coffeescript # The following line is NOT required for web browser use Brauhaus = require 'brauhaus' # Import plugins here, e.g. require 'brauhaus-beerxml' # Create a recipe r = new Brauhaus.Recipe name: 'My test brew' description: 'A new test beer using Brauhaus.js!' batchSize: 20.0 boilSize: 10.0 # Add ingredients r.add 'fermentable', name: 'Extra pale malt' color: 2.5 weight: 4.2 yield: 78.0 r.add 'hop', name: 'Cascade hops' weight: 0.028 aa: 5.0 use: 'boil' form: 'pellet' r.add 'yeast' name: 'Wyeast 3724 - Belgian Saison' type: 'ale' form: 'liquid' attenuation: 80 # Set up a simple infusion mash r.mash = new Brauhaus.Mash name: 'My mash' ph: 5.4 r.mash.addStep name: 'Saccharification' type: 'Infusion' time: 60 temp: 68 waterRatio: 2.75 # Calculate values r.calculate() # Print out calculated values console.log "Original Gravity: #{ r.og.toFixed 3 }" console.log "Final Gravity: #{ r.fg.toFixed 3 }" console.log "Color: #{ r.color.toFixed 1 }° SRM (#{ r.colorName() })" console.log "IBU: #{ r.ibu.toFixed 1 }" console.log "Alcohol: #{ r.abv.toFixed 1 }% by volume" console.log "Calories: #{ Math.round r.calories } kcal" ``` Quick Example (Javascript) -------------------------- Here is an example of how to use the library form Javascript: ```javascript // The following line is NOT required for web browser use var Brauhaus = require('brauhaus'); // Import plugins here, e.g. require('brauhaus-beerxml'); // Create a recipe var r = new Brauhaus.Recipe({ name: 'My test brew', description: 'A new test beer using Brauhaus.js!', batchSize: 20.0, boilSize: 10.0 }); // Add ingredients r.add('fermentable', { name: 'Extra pale malt', color: 2.5, weight: 4.2, yield: 78.0 }); r.add('hop', { name: 'Cascade hops', weight: 0.028, aa: 5.0, use: 'boil', form: 'pellet' }); r.add('yeast', { name: 'Wyeast 3724 - Belgian Saison', type: 'ale', form: 'liquid', attenuation: 80 }); // Set up a simple infusion mash r.mash = new Brauhaus.Mash({ name: 'My mash', ph: 5.4 }); r.mash.addStep({ name: 'Saccharification', type: 'Infusion', time: 60, temp: 68, waterRatio: 2.75 }); // Calculate values r.calculate(); // Print out calculated values console.log('Original Gravity: ' + r.og.toFixed(3)); console.log('Final Gravity: ' + r.fg.toFixed(3)); console.log('Color: ' + r.color.toFixed(1) + '° SRM (' + r.colorName() + ')'); console.log('IBU: ' + r.ibu.toFixed(1)); console.log('Alcohol: ' + r.abv.toFixed(1) + '% by volume'); console.log('Calories: ' + Math.round(r.calories) + ' kcal'); ``` Brauhaus Configuration ---------------------- The following values may be configured and will apply to all recipes, ingredients, etc. | Property | Type | Default | Description | | ---------------------- | ------ | ------- | ---------------------------------------------------- | | BURNER_ENERGY | number | 9000 | Heat source output in kilojoules per hour | | COLOR_NAMES | array | ... | An array of color names for °SRM color ranges | | MASH_HEAT_LOSS | number | 5 | Degrees C lost per hour during mash | | RELATIVE_SUGAR_DENSITY | object | ... | Keys are types of sugar, values are relative density | | ROOM_TEMP | number | 23 | Room temperature in degrees C | Duration Functions ------------------ The following functions are available to parse and display durations of time: ### Brauhaus.parseDuration (value) Parse a string value into a duration in minutes. Supports many optional suffixes like `w`, `wk`, `wks`, `week`, `weeks`, `d`, `day`, `days`, `h`, `hr`, `hrs`, `hour`, `hours`, `m`, `min`, `mins`, `minute`, `minutes`, `s`, `sec`, `second`, and `seconds`. ```javascript >>> Brauhaus.parseDuration('2 days') 2880 >>> Brauhaus.parseDuration('1hr 3 minutes') 63 >>> Brauhaus.parseDuration('12') 12 ``` ### Brauhaus.displayDuration (minutes, [approximate]) Generates a human-friendly display string from a number of minutes. Approximate, if set, determines the maximum number of units to return, rounding the last unit. For example, a setting of `2` would return days and hours; or hours and minutes; but never days, hours, and minutes. ```javascript >>> Brauhaus.displayDuration(65) '1 hour 5 minutes' >>> Brauhaus.displayDuration(2833) '1 day 23 hours 13 minutes' >>> Brauhaus.displayDuration(2833, 2) '1 day 23 hours' >>> Brauhaus.displayDuration(2833, 1) '2 days' ``` Conversion Functions -------------------- The following functions are available to convert between various forms: ### Brauhaus.kgToLb (number) Convert kilograms to pounds. ```javascript >>> Brauhaus.kgToLb(2.5) 5.51155 ``` ### Brauhaus.lbToKg (number) Convert pounds to kilograms. ```javascript >>> Brauhaus.lbToKg(5.51155) 2.5 ``` ### Brauhaus.kgToLbOz (number) Convert kilograms to pounds and ounces. ```javascript >>> Brauhaus.kgToLbOz(2.5) { lb: 5, oz: 8.184799999999996 } ``` ### Brauhaus.lbOzToKg (numberLbs, numberOz) Convert pounds and ounces to kilograms. ```javascript >>> Brauhaus.lbOzToKg(5, 8.184799999999996) 2.5 ``` ### Brauhaus.litersToGallons (number) Convert liters to gallons. ```javascript >>> Brauhaus.litersToGallons(20.0) 5.283440000000001 ``` ### Brauhaus.gallonsToLiters (number) Convert gallons to liters. ```javascript >>> Brauhaus.gallonsToLiters(5.283440000000001) 20.0 ``` ### Brauhaus.litersPerKgToQuartsPerLb (number) Convert l/kg to qt/lb. ```javascript >>> Brauhaus.litersPerKgToQuartsPerLb(5.0) 2.3965285450000002 ``` ### Brauhaus.quartsPerLbToLitersPerKg (number) Convert qt/lb to l/kg. ```javascript >>> Brauhaus.quartsPerLbToLitersPerKg(2.3965285450000002) 5.0 ``` ### Brauhaus.cToF (number) Convert a temperature from celcius to fahrenheit. ```javascript >>> Brauhaus.cToF(20.0) 68.0 ``` ### Brauhaus.fToC (number) Convert a temperature from fahrenheit to celcius. ```javascript >>> Brauhaus.fToC(68.0) 20.0 ``` ### Brauhaus.yieldToPpg (number) Convert a yield percentage to parts per gallon. ```javascript >>> Brauhaus.yieldToPpg(75) 34.6605 ``` ### Brauhaus.ppgToYield (number) Convert parts per gallon to a yield percentage. ```javascript >>> Brauhaus.ppgToYield(34.6605) 75.0001 ``` Color Conversions ----------------- Colors can be easily converted into various useful formats for the screen and web. ### Brauhaus.srmToEbc (number) Convert a color in °SRM to °EBC. ```javascript >>> Brauhaus.srmToEbc(10) 19.7 ``` ### Brauhaus.ebcToSrm (number) Convert a color in °EBC to °SRM. ```javascript >>> Brauhaus.ebcToSrm (20) 10.16 ``` ### Brauhaus.srmToLovibond (number) Convert a color in °SRM to °Lovibond. ```javascript >>> Brauhaus.srmToLovibond(10) 7.9433042964712826 ``` ### Brauhaus.lovibondToSrm (number) Convert a color in °Lovibond to °SRM. ```javascript >>> Brauhaus.lovibondToSrm(3.5) 3.9811000000000005 ``` ### Brauhaus.srmToRgb (number) Convert a color in °SRM to a RGB triplet. ```javascript >>> Brauhaus.srmToRgb(8) [208, 88, 13] ``` ### Brauhaus.srmToCss (number) Convert a color in °SRM to a form usable in a CSS color string. ```javascript >>> Brauhaus.srmToCss(8) 'rgb(208, 88, 14)' ``` ### Brauhaus.srmToName (number) Convert a color in °SRM to a human-readable color. ```javascript >>> Brauhaus.srmToName(8) 'deep gold' ``` Other Utilities --------------- ### Brauhaus.timeToHeat (liters, degrees) Get the time in minutes to heat a volume of water in liters by a number of degrees C given the heat source defined by `Brauhaus.BURNER_ENERGY`. ```javascript >>> Brauhaus.timeToHeat(10.0, 80.0) 22.34666666666667 ``` Brauhaus Objects ---------------- The following list of objects are available within Brauhaus: * Fermentable * Spice * Yeast * MashStep * Mash * Recipe Serialization ------------- A Brauhaus object can be easily serialized and deserialized from a JSON format. Deserialization can be from a JSON string or an object (i.e. the value given by `JSON.parse(...)`). For example, to serialize and deserialize a recipe object: ```javascript var r, serialized; // Serialize r = new Brauhaus.Recipe(...); serialized = JSON.stringify(r); // Deserialize from JSON string serialized = '...'; r = new Brauhaus.Recipe(serialized); // Deserialize from parsed object serialized = JSON.parse('...'); r = new Brauhaus.Recipe(serialized); ``` Note: there is also a [BeerXML plugin](https://github.com/homebrewing/brauhaus-beerxml) available which can serialize / deserialize BeerXML 1.0. Brauhaus.Fermentable -------------------- A fermentable is some kind of a sugar that yeast can metabolize into CO2 and alcohol. Fermentables can be malts, malt extracts, honey, sugar, etc. Each fermentable can have the following properties: | Property | Type | Default | Description | | -------- | ------ | --------------- | ----------------------- | | color | number | 2.0 | Color in °SRM | | late | bool | false | Late addition | | name | string | New fermentable | Name of the fermentable | | weight | number | 1.0 | Weight in kilograms | | yield | number | 75.0 | Percentage yield | ### Fermentable.prototype.addition () Get the addition type of fermentable, one of `mash`, `steep`, or `boil`. ```javascript >>> f.addition() 'steep' ``` ### Fermentable.prototype.colorRgb () Get the color triplet for this fermentable. Shortcut for `Brauhaus.srmToRgb(f.color)`. ```javascript >>> f.colorRgb() [233, 157, 63] ``` ### Fermentable.prototype.colorCss () Get the CSS-friendly color string for this fermentable. Shortcut for `Brauhaus.srmToCss(f.color)`. ```javascript >>> f.colorCss() 'rgb(233, 157, 63)' ``` ### Fermentable.prototype.colorName () Get the human-readable name for the color of this fermentable. Shortcut for `Brauhaus.srmToName(f.color)`. ```javascript >>> f.colorName() 'deep gold' ``` ### Fermentable.prototype.gu (number) Get the gravity units of this fermentable for a number of liters, based on the weight and yield. These units make the original gravity when divided by 1000 and added to one. ```javascript >>> f.gu(20.0) 32 ``` ### Fermentable.prototype.plato (number) Get the gravity in degrees plato for this fermentable for a number of liters, based on the weight and yield. ```javascript >>> f.plato(20.0) 7.5301 ``` ### Fermentable.prototype.ppg () Get the parts per gallon from the yield percentage. ```javascript >>> f.ppg() 36 ``` ### Fermentable.prototype.price () Guess the price in USD per kilogram of this fermentable, based on the name. Prices are an approximation based on multiple online homebrew supply store prices. You should use `toFixed(2)` to display these. ```javascript >>> f.price() 13.5025 ``` ### Fermentable.prototype.type () Get the type of fermentable, either `extract` or `grain`. ```javascript >>> f.type() 'grain' ``` ### Fermentable.prototype.weightLb () A shortcut for `Brauhaus.kgToLb(f.weight)` to get the weight in pounds. ```javascript >>> f.weightLb() 2.2 ``` ### Fermentable.prototype.weightLbOz () A shortcut for `Brauhaus.kgToLbOz(f.weight)` to get the weight in pounds and ounces. ```javascript >>> f.weightLbOz() { lb: 2, oz: 4.3 } ``` Brauhaus.Spice -------------- A spice is some kind of substance added to flavor or protect a brew. Spices can be hops, coriander, orange peel, cinnamon, whirlfloc, Irish moss, rose hips, etc. Each spice can have the following properties: | Property | Type | Default | Description | | -------- | ------ | --------- | ------------------------------------------------ | | aa | number | 0.0 | Alpha-acid percentage (0 - 100) | | form | string | pellet | Form, like pellet, whole, ground, crushed, etc | | name | string | New spice | Name of the spice | | time | number | 60 | Time in minutes to add the spice | | use | string | boil | When to use the spice (mash, boil, primary, etc) | | weight | number | 1.0 | Weight in kilograms | ### Spice.prototype.bitterness (ibuMethod, earlyOg, batchSize) Calculate the IBU of a spice for the given method, early OG, and batch size in liters. Available methods are `'tinseth'` and `'rager'`. The early OG is usually calculated as the sum of gravity values for all non-late fermentables. ```javascript >>> s.bitterness('tinseth', 1.045, 19) 12.4 ``` ### Spice.prototype.dry () True if the spice is added after the boil, otherwise false. This is useful for determining if dry hopping is taking place. ```javascript >>> s.dry() false ``` ### Spice.prototype.price () Guess the price in USD per kilogram of this spice, based on the name. Prices are an approximation based on multiple online homebrew supply store prices. You should use `toFixed(2)` to display these. ```javascript >>> s.price() 2.5318 ``` ### Spice.prototype.utilizationFactor () Get the utilization factor based on the form of a spice. For example, pellets are easier to utilize than whole leaf hops. ```javascript >>> s.utilizationFactor() 1.15 ``` ### Spice.prototype.weightLb () A shortcut for `Brauhaus.kgToLb(s.weight)` to get the weight in pounds. ```javascript >>> s.weightLb() 0.0625 ``` ### Spice.prototype.weightLbOz () A shortcut for `Brauhaus.kgToLbOz(s.weight)` to get the weight in pounds and ounces. ```javascript >>> s.weightLbOz() { lb: 0, oz: 1 } ``` Brauhaus.Yeast -------------- Yeast are the biological workhorse that transform sugars into alcohol. Yeast can be professional strains like Wyeast 3068, harvested from bottles, harvested from the air, or other bugs like bacteria that produce acid. | Property | Type | Default | Description | | ----------- | ------ | --------- | ------------------------------------------ | | attenuation | number | 75.0 | Percentage of sugars the yeast can convert | | form | string | liquid | Liquid or dry | | name | string | New yeast | Name of the yeast | | type | string | ale | Ale, lager, or other | ### Yeast.prototype.price () Guess the price in USD per packet of this yeast, based on the name. Prices are an approximation based on multiple online homebrew supply store prices. You should use `toFixed(2)` to display these. ```javascript >>> y.price() 7 ``` Brauhaus.MashStep ----------------- A single step in a multi-step mash, such as infusing water, changing the temperature, or decocting mash to boil. | Property | Type | Default | Description | | ----------- | ------ | ---------------- | ------------------------------------------------------------ | | endTemp | number | unset | Temperature in degrees C after this step | | name | string | Saccharification | A name to give this step | | rampTime | number | unset | Time in minutes to ramp to the given temperature | | temp | number | 68 | Temperature in degrees C to hold the mash | | time | number | 60 | Duration of this step in minutes | | type | string | Infusio ... ...

近期下载者

相关文件


收藏者