Methods
forInterval(min, max) → {function}
Create a function than calculate the amount between the bounds of the interval (min, max]. That means how much
money is concerned by the interval.
If max is not passed at function then input amount is considered as max so the bounds are (min, amount].
If max is not passed at function then input amount is considered as max so the bounds are (min, amount].
Parameters:
Name | Type | Description |
---|---|---|
min |
Number | start of the interval |
max |
Number | end of the interval (optional, if not set use amount as max) |
- Source:
Returns:
The interval calculator
- Type
- function
Example
const interval1000_2000 = forInterval(1000, 2000)
interval1000_2000(3000) // => 1000 all amount is in the interval
interval1000_2000(1500) // => 500 are in the interval
interval1000_2000(1000) // => 0 the amount out of interval
// without max
const intervalFrom1000 = forInterval(1000)
intervalFrom1000(3000) // => 2000
netAfter(tax, amount) → {Number}
Calculate the net amount after apply a tax.
is currified
is currified
Parameters:
Name | Type | Description |
---|---|---|
tax |
function | to be applied |
amount |
Number | gross value |
- Source:
Returns:
net value after tax
- Type
- Number
Example
netAfter(rateAt(0.2), 1000) //=> 800
netAfter(rateAt(0.2))(1000) //=> 800
rateAt(rate, amount) → {Number}
Calculate the amount of a tax rate.
is currified
is currified
Parameters:
Name | Type | Description |
---|---|---|
rate |
Number | decimal from 0 to 1 |
amount |
Number |
Returns:
- Type
- Number
Example
rateAt(0.2)(1000) //=> 200
rateAt(0,2, 1000) //=> 200
tax(taxBrackets) → {function}
Parameters:
Name | Type | Description |
---|---|---|
taxBrackets |
Array |
- Source:
- See:
Returns:
The tax function
- Type
- function
Example
// 10% for the first 2000 e
const bracket1 = taxBracket(rateAt(0.1), forInterval(0, 2000)) // bracket1(5000)=> 200
// 20% form 2000 e
const bracket2 = taxBracket(rateAt(0.2), forInterval(2000)) // bracket2(5000)=> 600
tax([bracket1, bracket2])(5000)/ //=> 800
taxApply(amount, tax) → {Number}
Calculate the tax amount after apply a tax.
is currified
is internal
is currified
is internal
Parameters:
Name | Type | Description |
---|---|---|
amount |
Number | profit imposed on tax |
tax |
function | function witch calculate the tax |
- Source:
Returns:
tax amount
- Type
- Number
Example
const tax = rateAt(0.2)
const taxApply(1000)(rateAt(0.2)) //=> 200
taxBracket(rateAt, forInterval) → {function}
Create a function than apply a tax rate for an interval.
Parameters:
Name | Type | Description |
---|---|---|
rateAt |
function | tax rate |
forInterval |
function | bracket |
- Source:
- See:
Returns:
- Type
- function
Example
taxBracket(rateAt(0.2), forInterval(1000, 2000))(3000) //=> 200
taxDetail(taxBracket) → {function}
Create a function that calculate the tax of each tax bracket
Parameters:
Name | Type | Description |
---|---|---|
taxBracket |
Array |
- Source:
- See:
Returns:
- Type
- function
Example
const bracket1 = taxBracket(rateAt(0.1), forInterval(0, 2000)) // bracket1(5000)=> 200
const bracket2 = taxBracket(rateAt(0.2), forInterval(2000)) // bracket2(5000)=> 600
taxDetail([bracket1, bracket2])(5000) //=> [200, 600]