Skip to content

Commit

Permalink
Deploy sarahdayan/dinero.js to github.com/sarahdayan/dinero.js.git:ma…
Browse files Browse the repository at this point in the history
…ster
  • Loading branch information
traviscibot committed Apr 10, 2018
1 parent 0945446 commit 9e5d398
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 46 deletions.
46 changes: 26 additions & 20 deletions docs/dinero.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ <h1 class="page-title">
<article>
<pre class="prettyprint source linenums"><code>import { Defaults, Globals } from './services/settings'
import Format from './services/format'
import Calculator from './services/calculator'
import { isNumeric } from './services/helpers'

const calculator = Calculator()

/**
* A Dinero object is an immutable data structure representing a specific monetary value.
Expand Down Expand Up @@ -177,14 +181,7 @@ <h1 class="page-title">
}
},
isPercentage(percentage) {
if (
!(
!isNaN(parseInt(percentage)) &amp;&amp;
isFinite(percentage) &amp;&amp;
percentage &lt;= 100 &amp;&amp;
percentage >= 0
)
) {
if (!(isNumeric(percentage) &amp;&amp; percentage &lt;= 100 &amp;&amp; percentage >= 0)) {
throw new RangeError(
'You must provide a numeric value between 0 and 100.'
)
Expand Down Expand Up @@ -266,7 +263,7 @@ <h1 class="page-title">
add(addend) {
assert.hasSameCurrency.call(this, addend)
return create.call(this, {
amount: this.getAmount() + addend.getAmount()
amount: calculator.add(this.getAmount(), addend.getAmount())
})
},
/**
Expand All @@ -285,7 +282,7 @@ <h1 class="page-title">
subtract(subtrahend) {
assert.hasSameCurrency.call(this, subtrahend)
return create.call(this, {
amount: this.getAmount() - subtrahend.getAmount()
amount: calculator.subtract(this.getAmount(), subtrahend.getAmount())
})
},
/**
Expand All @@ -300,7 +297,9 @@ <h1 class="page-title">
* @return {Dinero}
*/
multiply(multiplier) {
return create.call(this, { amount: this.getAmount() * multiplier })
return create.call(this, {
amount: calculator.multiply(this.getAmount(), multiplier)
})
},
/**
* Returns a new Dinero object that represents the divided value by the given factor.
Expand All @@ -314,7 +313,9 @@ <h1 class="page-title">
* @return {Dinero}
*/
divide(divisor) {
return create.call(this, { amount: this.getAmount() / divisor })
return create.call(this, {
amount: calculator.divide(this.getAmount(), divisor)
})
},
/**
* Returns a new Dinero object that represents a percentage of this.
Expand All @@ -331,7 +332,7 @@ <h1 class="page-title">
*/
percentage(percentage) {
assert.isPercentage(percentage)
return this.multiply(percentage / 100)
return this.multiply(calculator.divide(percentage, 100))
},
/**
* Allocates the amount of a Dinero object according to a list of ratios.
Expand Down Expand Up @@ -364,18 +365,20 @@ <h1 class="page-title">
allocate(ratios) {
assert.areValidRatios(ratios)

const total = ratios.reduce((a, b) => a + b)
const total = ratios.reduce((a, b) => calculator.add(a, b))
let remainder = this.getAmount()

const shares = ratios.map(ratio => {
const share = Math.floor(this.getAmount() * ratio / total)
remainder = remainder - share
const share = Math.floor(
calculator.divide(calculator.multiply(this.getAmount(), ratio), total)
)
remainder = calculator.subtract(remainder, share)
return create.call(this, { amount: share })
})

for (let i = 0; remainder > 0; i++) {
shares[i] = shares[i].add(create.call(this, { amount: 1 }))
remainder = remainder - 1
remainder = calculator.subtract(remainder, 1)
}

return shares
Expand Down Expand Up @@ -553,7 +556,7 @@ <h1 class="page-title">
* @return {Boolean}
*/
hasCents() {
return this.getAmount() % 100 !== 0
return calculator.modulo(this.getAmount(), 100) !== 0
},
/**
* Checks whether the currency represented by this object equals to the other.
Expand Down Expand Up @@ -652,7 +655,7 @@ <h1 class="page-title">
* @return {Number}
*/
toUnit() {
return this.getAmount() / 100
return calculator.divide(this.getAmount(), 100)
},
/**
* Returns the amount represented by this object in rounded units.
Expand All @@ -666,7 +669,10 @@ <h1 class="page-title">
*/
toRoundedUnit(precision) {
const factor = Math.pow(10, precision)
return Math.round(this.toUnit() * factor) / factor
return calculator.divide(
Math.round(calculator.multiply(this.toUnit(), factor)),
factor
)
},
/**
* Return the object's data as an object literal.
Expand Down
52 changes: 26 additions & 26 deletions docs/module-Dinero.html
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ <h5>Parameters:</h5>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line4">line 4</a>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line8">line 8</a>
</li>
</ul>
</dd>
Expand Down Expand Up @@ -367,7 +367,7 @@ <h4 class="name" id="~getAmount">
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line109">line 109</a>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line106">line 106</a>
</li>
</ul>
</dd>
Expand Down Expand Up @@ -473,7 +473,7 @@ <h4 class="name" id="~getCurrency">
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line121">line 121</a>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line118">line 118</a>
</li>
</ul>
</dd>
Expand Down Expand Up @@ -579,7 +579,7 @@ <h4 class="name" id="~getLocale">
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line133">line 133</a>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line130">line 130</a>
</li>
</ul>
</dd>
Expand Down Expand Up @@ -740,7 +740,7 @@ <h5>Parameters:</h5>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line147">line 147</a>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line144">line 144</a>
</li>
</ul>
</dd>
Expand Down Expand Up @@ -901,7 +901,7 @@ <h5>Parameters:</h5>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line163">line 163</a>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line160">line 160</a>
</li>
</ul>
</dd>
Expand Down Expand Up @@ -1093,7 +1093,7 @@ <h5>Parameters:</h5>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line182">line 182</a>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line179">line 179</a>
</li>
</ul>
</dd>
Expand Down Expand Up @@ -1285,7 +1285,7 @@ <h5>Parameters:</h5>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line199">line 199</a>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line196">line 196</a>
</li>
</ul>
</dd>
Expand Down Expand Up @@ -1446,7 +1446,7 @@ <h5>Parameters:</h5>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line213">line 213</a>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line212">line 212</a>
</li>
</ul>
</dd>
Expand Down Expand Up @@ -1607,7 +1607,7 @@ <h5>Parameters:</h5>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line229">line 229</a>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line230">line 230</a>
</li>
</ul>
</dd>
Expand Down Expand Up @@ -1805,7 +1805,7 @@ <h5>Parameters:</h5>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line261">line 261</a>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line262">line 262</a>
</li>
</ul>
</dd>
Expand Down Expand Up @@ -2005,7 +2005,7 @@ <h5>Parameters:</h5>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line300">line 300</a>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line303">line 303</a>
</li>
</ul>
</dd>
Expand Down Expand Up @@ -2178,7 +2178,7 @@ <h5>Parameters:</h5>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line319">line 319</a>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line322">line 322</a>
</li>
</ul>
</dd>
Expand Down Expand Up @@ -2374,7 +2374,7 @@ <h5>Parameters:</h5>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line342">line 342</a>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line345">line 345</a>
</li>
</ul>
</dd>
Expand Down Expand Up @@ -2574,7 +2574,7 @@ <h5>Parameters:</h5>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line362">line 362</a>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line365">line 365</a>
</li>
</ul>
</dd>
Expand Down Expand Up @@ -2770,7 +2770,7 @@ <h5>Parameters:</h5>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line385">line 385</a>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line388">line 388</a>
</li>
</ul>
</dd>
Expand Down Expand Up @@ -2915,7 +2915,7 @@ <h4 class="name" id="~isZero">
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line401">line 401</a>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line404">line 404</a>
</li>
</ul>
</dd>
Expand Down Expand Up @@ -3025,7 +3025,7 @@ <h4 class="name" id="~isPositive">
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line419">line 419</a>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line422">line 422</a>
</li>
</ul>
</dd>
Expand Down Expand Up @@ -3139,7 +3139,7 @@ <h4 class="name" id="~isNegative">
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line437">line 437</a>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line440">line 440</a>
</li>
</ul>
</dd>
Expand Down Expand Up @@ -3253,7 +3253,7 @@ <h4 class="name" id="~hasCents">
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line452">line 452</a>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line455">line 455</a>
</li>
</ul>
</dd>
Expand Down Expand Up @@ -3418,7 +3418,7 @@ <h5>Parameters:</h5>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line469">line 469</a>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line472">line 472</a>
</li>
</ul>
</dd>
Expand Down Expand Up @@ -3583,7 +3583,7 @@ <h5>Parameters:</h5>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line486">line 486</a>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line489">line 489</a>
</li>
</ul>
</dd>
Expand Down Expand Up @@ -3797,7 +3797,7 @@ <h5>Parameters:</h5>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line529">line 529</a>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line532">line 532</a>
</li>
</ul>
</dd>
Expand Down Expand Up @@ -3915,7 +3915,7 @@ <h4 class="name" id="~toUnit">
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line551">line 551</a>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line554">line 554</a>
</li>
</ul>
</dd>
Expand Down Expand Up @@ -4076,7 +4076,7 @@ <h5>Parameters:</h5>
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line564">line 564</a>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line567">line 567</a>
</li>
</ul>
</dd>
Expand Down Expand Up @@ -4182,7 +4182,7 @@ <h4 class="name" id="~toObject">
<dd class="tag-source">
<ul class="dummy">
<li>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line577">line 577</a>
<a href="dinero.js.html">dinero.js</a>, <a href="dinero.js.html#line583">line 583</a>
</li>
</ul>
</dd>
Expand Down

0 comments on commit 9e5d398

Please sign in to comment.