1.0.1 • Published 6 years ago

cow-price v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

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

  1. 'flat': every perCount of the original price has a perDiscount, the max discount amount is maxDiscount
{
  category: 'flat',
  condition: {
    perCount: 100,
    perDiscount: 10,
    maxDiscount: 15,
  },
}
  1. 'percentage': original price has a percentage perDiscount discount when price is over the perCount, the max discount amount is maxDiscount
{
  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