1.0.1 • Published 6 years ago
cow-price v1.0.1
Cow Price
a elegant way to calculation product price according to some discount rules
Install
npm install cow-price
Usage
import Cow from 'cow-price'
const originalPrice = 200
const discountRule = {
category: 'percentage',
condition: {
perCount: 100,
perDiscount: 90,
maxDiscount: 10,
},
}
const c = new Cow(originalPrice, discountRule)
const actualPrice = c.cost()
console.log(actualPrice) // 190
Discount Rules
for now, two kinds of discount rule are supported
- 'flat': every
perCount
of the original price has aperDiscount
, the max discount amount ismaxDiscount
{
category: 'flat',
condition: {
perCount: 100,
perDiscount: 10,
maxDiscount: 15,
},
}
- 'percentage': original price has a percentage
perDiscount
discount when price is over theperCount
, the max discount amount ismaxDiscount
{
category: 'percentage',
condition: {
perCount: 100,
perDiscount: 90,
maxDiscount: 100,
},
}
Dev in local
git clone git@github.com:kimochg/cow-price.git
cd cow-price
npm install
npm run watch
Test
npm run test
LICENSE
MIT © Cheng Liu