From 3adc4e156258a6f27ed138268986ed5e43dc80e0 Mon Sep 17 00:00:00 2001 From: Nick Barry Date: Sun, 28 Apr 2019 20:07:30 -0500 Subject: [PATCH] initialize repository --- LICENSE.md | 19 +++ README.md | 38 +++++ decisrm.json | 403 +++++++++++++++++++++++++++++++++++++++++++++++++++ index.js | 23 +++ package.json | 27 ++++ 5 files changed, 510 insertions(+) create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 decisrm.json create mode 100644 index.js create mode 100644 package.json diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..506be8c --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,19 @@ +Copyright (c) 2019 Zymulator + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..1e72bef --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +# Beer Color + +Convert SRM or EBC to hex color. + +Color values are provided by Barley Dog Brewery [here](https://www.barleydogbrewery.com/xml/colors.xml) + +## Usage + +Install the library: + +``` +npm install --save beer-color +``` + +Require the module and call one of the conversion functions: + +```javascript +let beerColor = require('beer-color'); + +beerColor.fromSRM(4); +// => '#ECE61A' + +beerColor.fromEBC(4); +// => '#F8F753' +``` + +The domain of valid inputs is 0 through 40 SRM. Input values are rounded to the nearest 0.1 SRM within this domain: + +```javascript +beerColor.fromSRM(-1) === beerColor.fromSRM(0); +// => true + +beerColor.fromSRM(Number.MAX_VALUE) === beerColor.fromSRM(40); +// => true + +beerColor.fromSRM(Math.PI) === beerColor.fromSRM(3.1); +// => true +``` diff --git a/decisrm.json b/decisrm.json new file mode 100644 index 0000000..28b5d5c --- /dev/null +++ b/decisrm.json @@ -0,0 +1,403 @@ +[ + "#FFFFFF", + "#F8F8E6", + "#F8F8DC", + "#F7F7C7", + "#F4F9B9", + "#F7F9B4", + "#F8F9B2", + "#F4F6A9", + "#F5F7A6", + "#F6F79C", + "#F3F993", + "#F6F88D", + "#F6F988", + "#F5FA80", + "#F6F979", + "#F8F972", + "#F3F968", + "#F6F86B", + "#F8F763", + "#F5F75C", + "#F8F753", + "#F4F848", + "#F8F749", + "#F6F73E", + "#F1F835", + "#F4F730", + "#F6F928", + "#F3F922", + "#F5F71E", + "#F8F516", + "#F6F513", + "#F4F216", + "#F4F015", + "#F3F213", + "#F4EE18", + "#F4ED1D", + "#EEE916", + "#F0E917", + "#EEE719", + "#EAE615", + "#ECE61A", + "#E6E118", + "#E8E119", + "#E6DD1B", + "#E0DA17", + "#E5D81F", + "#E5D61E", + "#DFD51A", + "#E2D51C", + "#DFD11D", + "#E0D01B", + "#E0CC20", + "#DDCC21", + "#DCCB1D", + "#DAC820", + "#DCC522", + "#DAC429", + "#D9C22B", + "#D8C027", + "#D5BE25", + "#D5BC26", + "#D4B827", + "#D6B72B", + "#D5B42D", + "#D2B329", + "#D0B22A", + "#D0B02E", + "#CCAC30", + "#CCAC34", + "#CDAA37", + "#C9A732", + "#CAA734", + "#C9A633", + "#C7A236", + "#C6A038", + "#C89E3C", + "#C29C36", + "#C49B36", + "#C6973C", + "#C1963C", + "#BF923B", + "#BE9339", + "#BE933B", + "#BE913C", + "#BA9438", + "#BE913A", + "#C1913B", + "#BE913A", + "#BF8F3B", + "#BF8D3D", + "#BE8C3A", + "#C08C3D", + "#C18A3E", + "#C0893B", + "#C1883B", + "#C3873F", + "#BF883A", + "#BF8643", + "#C18343", + "#BE823A", + "#BF813A", + "#BF8339", + "#BF813A", + "#BF813A", + "#BE8137", + "#BF7F3B", + "#C27E3B", + "#BC8036", + "#BE7C37", + "#C17A37", + "#BE7C37", + "#C2793B", + "#C17838", + "#BE7734", + "#B67536", + "#C4743B", + "#BF7638", + "#BE7439", + "#BF733A", + "#BD7338", + "#BF7138", + "#BF7135", + "#BC7039", + "#BE7037", + "#B86E34", + "#BC6D37", + "#BD6D37", + "#BA6A32", + "#BE6734", + "#BD6836", + "#BC6733", + "#BC6733", + "#BA6533", + "#BA6638", + "#B96438", + "#B9623B", + "#B76236", + "#B56435", + "#B66137", + "#B16133", + "#B26033", + "#B06031", + "#B16037", + "#B25F37", + "#AB5E37", + "#AB5C38", + "#AC5D3B", + "#A85C37", + "#A95A36", + "#A85839", + "#A55936", + "#A65836", + "#A5583A", + "#A15834", + "#A35537", + "#A05638", + "#9E5539", + "#9E5636", + "#9F5439", + "#9C5335", + "#985336", + "#965337", + "#965138", + "#925138", + "#934F36", + "#934F37", + "#924E36", + "#8E4D33", + "#8F4F35", + "#8E4D36", + "#8D4C32", + "#8C4B32", + "#8A4931", + "#87462D", + "#884731", + "#8C4831", + "#80462D", + "#81472E", + "#82452F", + "#7B452D", + "#7C452D", + "#794228", + "#784328", + "#774026", + "#743F22", + "#783F23", + "#783E25", + "#703F23", + "#6F3E24", + "#6D3C22", + "#6B3A1E", + "#6A391F", + "#6B381F", + "#69381C", + "#69381C", + "#68341F", + "#66351B", + "#64351A", + "#633419", + "#5D3518", + "#5D341A", + "#593114", + "#5A3215", + "#5B3014", + "#53300F", + "#583011", + "#562E11", + "#512D0F", + "#532C0F", + "#512D0F", + "#4E2A0C", + "#4D2B0C", + "#4B290C", + "#4A2905", + "#4E2817", + "#532B2E", + "#4E2B29", + "#4E2829", + "#4C2929", + "#4A2727", + "#4A2727", + "#452723", + "#462525", + "#442624", + "#402322", + "#402322", + "#3E2120", + "#3A211F", + "#3D211F", + "#3A2121", + "#361F1B", + "#341D1C", + "#341D1C", + "#311C1B", + "#301B1A", + "#301B1A", + "#2C1919", + "#2C1917", + "#2A181A", + "#281716", + "#261716", + "#261716", + "#261716", + "#261716", + "#261716", + "#261716", + "#261716", + "#261716", + "#261716", + "#261716", + "#261716", + "#261716", + "#261716", + "#261716", + "#261716", + "#261716", + "#261718", + "#19100F", + "#19100F", + "#19100F", + "#19100F", + "#19100F", + "#19100F", + "#19100F", + "#19100F", + "#19100F", + "#19100F", + "#19100F", + "#19100F", + "#19100F", + "#19100F", + "#19100F", + "#19100F", + "#120D0C", + "#120D0C", + "#120D0C", + "#120D0C", + "#120D0C", + "#120D0C", + "#120D0C", + "#120D0C", + "#120D0C", + "#120D0C", + "#120D0C", + "#120D0C", + "#120D0C", + "#120D0C", + "#110D0A", + "#120D0C", + "#100B0A", + "#100B0A", + "#100B0A", + "#100B0A", + "#100B0A", + "#100B0A", + "#100B0A", + "#100B0A", + "#100B0A", + "#100B0A", + "#100B0A", + "#100B0A", + "#100B0A", + "#100B0A", + "#100B0A", + "#100B0A", + "#0E0908", + "#0F0A09", + "#0E0908", + "#0E0908", + "#0E0908", + "#0E0908", + "#0E0908", + "#0E0908", + "#0E0908", + "#0E0908", + "#0E0908", + "#0E0908", + "#0E0908", + "#0E0908", + "#0E0908", + "#0F0B08", + "#0C0907", + "#0C0907", + "#0C0907", + "#0C0907", + "#0C0907", + "#0C0907", + "#0C0907", + "#0C0907", + "#0C0907", + "#0C0907", + "#0C0907", + "#0C0907", + "#0C0907", + "#0C0907", + "#0C0907", + "#0C0907", + "#0A0707", + "#0A0705", + "#080707", + "#080707", + "#080707", + "#080707", + "#080707", + "#080707", + "#080707", + "#080707", + "#080707", + "#080707", + "#080707", + "#080707", + "#080707", + "#080707", + "#070606", + "#070606", + "#070606", + "#070606", + "#070606", + "#070606", + "#070606", + "#070606", + "#070606", + "#070606", + "#070606", + "#070606", + "#070606", + "#070606", + "#070704", + "#060603", + "#060505", + "#040504", + "#040504", + "#040504", + "#040504", + "#040504", + "#040504", + "#040504", + "#040504", + "#040504", + "#040504", + "#040504", + "#040504", + "#040504", + "#040504", + "#040504", + "#030403", + "#040504", + "#030403", + "#030403", + "#030403", + "#030403", + "#030403", + "#030403", + "#030403", + "#030403", + "#030403", + "#030403", + "#030403", + "#030403", + "#030403", + "#030403" +] diff --git a/index.js b/index.js new file mode 100644 index 0000000..1b33391 --- /dev/null +++ b/index.js @@ -0,0 +1,23 @@ +// decisrm.json sourced from https://www.barleydogbrewery.com/xml/colors.xml +// each index represents an increment of 0.1 SRM; 0.0 to 40.0, inclusive +const DECI_SRM = require('./decisrm'); + +const EBC_TO_SRM = 0.508; + +let beerColor = { + fromSRM: function (srm) { + srm = Math.max(0, srm); + + let deciSRM = Math.round(srm * 10); + + deciSRM = Math.min(DECI_SRM.length - 1, deciSRM); + + return DECI_SRM[deciSRM]; + }, + + fromEBC: function (ebc) { + return this.fromSRM(ebc * EBC_TO_SRM); + }, +}; + +module.exports = beerColor; diff --git a/package.json b/package.json new file mode 100644 index 0000000..5042120 --- /dev/null +++ b/package.json @@ -0,0 +1,27 @@ +{ + "name": "beer-color", + "version": "1.0.0", + "description": "Convert SRM or EBC color values to web-friendly hex.", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/zymulator/beer-color.git" + }, + "keywords": [ + "beer", + "color", + "srm", + "ebc", + "lovibond", + "hex" + ], + "author": "Nick Barry", + "license": "MIT", + "bugs": { + "url": "https://github.com/zymulator/beer-color/issues" + }, + "homepage": "https://github.com/zymulator/beer-color#readme" +}