Skip to content

Commit

Permalink
add tests, allow hex function to accept calculator argument
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsNickBarry committed Apr 30, 2019
1 parent 2402985 commit 1d38849
Show file tree
Hide file tree
Showing 6 changed files with 1,196 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ batch.srm('mosher');
// defaults to 'morey'
batch.ebc();
// => 28.9000740481361

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

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

### Options
Expand All @@ -82,7 +89,7 @@ Any one of the following options must be passed to the module:
| `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 the TODO option to specify which calculation method was used:
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 |
|-|-|-|
Expand Down
18 changes: 9 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,23 @@ Batch.prototype.l = Batch.prototype.lovibond = function (calculator) {
return (this.srm(calculator) + 0.6) / 1.35;
};

Batch.prototype.hex = function () {
let deciSRM = Math.max(0, Math.round(this.srm() * 10));
Batch.prototype.hex = function (calculator) {
let deciSRM = Math.max(0, Math.round(this.srm(calculator) * 10));
return DECI_SRM[Math.min(DECI_SRM.length - 1, deciSRM)];
};

Batch.srm = {
morey: (mcu) => 1.4922 * Math.pow(mcu, 0.6859),
daniels: (mcu) => 0.2 * mcu + 8.4,
mosher: (mcu) => 0.3 * mcu + 4.7,
barry: (mcu) => 1.5 * Math.pow(mcu, 0.7),
};

Batch.mcu = {
morey: (srm) => Math.pow(srm / 1.4922, 1 / 0.6859),
daniels: (srm) => Math.max(0, srm - 8.4) / 0.2,
mosher: (srm) => Math.max(0, srm - 4.7) / 0.3,
barry: (srm) => Math.pow(srm / 1.5, 1 / 0.7),
};

Batch.srm = {
morey: (mcu) => 1.4922 * Math.pow(mcu, 0.6859),
daniels: (mcu) => 0.2 * mcu + 8.4,
mosher: (mcu) => 0.3 * mcu + 4.7,
barry: (mcu) => 1.5 * Math.pow(mcu, 0.7),
};

module.exports = chromabrew;
Loading

0 comments on commit 1d38849

Please sign in to comment.