Skip to content

chengcyber/cow-price

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

elegant way to calculate product price

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published