couponable
Advanced tools
Comparing version 4.0.0 to 5.0.0
{ | ||
"name": "couponable", | ||
"version": "4.0.0", | ||
"version": "5.0.0", | ||
"description": "Helper functions for dealing with coupons.", | ||
@@ -5,0 +5,0 @@ "main": [ "index.js" ], |
22
index.js
@@ -1,4 +0,6 @@ | ||
function priceFormat(amountInCents) { | ||
// TODO: use numeraljs when this needs internationalization? or formatjs ? | ||
return '$' + (amountInCents / 100).toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ','); | ||
// if the comma or decimal portions of the price need internationalization | ||
// then considering switching to numbro or formatjs | ||
function priceFormat(amountInCents, currencySymbol) { | ||
currencySymbol = currencySymbol || '$'; | ||
return currencySymbol + (amountInCents / 100).toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ','); | ||
} | ||
@@ -48,3 +50,3 @@ | ||
// TODO: figure out i18n story here | ||
function totalLineOne(orderItem) { | ||
function totalLineOne(orderItem, currencySymbol) { | ||
var total, totalWithInterval; | ||
@@ -54,3 +56,3 @@ if (totalDueNow(orderItem) === 0) { | ||
} else { | ||
total = priceFormat(totalDueNow(orderItem)); | ||
total = priceFormat(totalDueNow(orderItem), currencySymbol); | ||
totalWithInterval = total + ' / ' + orderItem.interval; | ||
@@ -72,5 +74,5 @@ } | ||
function totalLineTwo(orderItem) { | ||
function totalLineTwo(orderItem, currencySymbol) { | ||
if (orderItem.purchasableType === 'bundle' && !orderItem.gift && orderItem.coupon && orderItem.coupon.duration !== 'forever') { | ||
return priceFormat(totalRecurring(orderItem)) + ' / ' + orderItem.interval; | ||
return priceFormat(totalRecurring(orderItem), currencySymbol) + ' / ' + orderItem.interval; | ||
} else { | ||
@@ -81,5 +83,5 @@ return null; | ||
function totalDescription(orderItem) { | ||
var lineOne = totalLineOne(orderItem), | ||
lineTwo = totalLineTwo(orderItem); | ||
function totalDescription(orderItem, currencySymbol) { | ||
var lineOne = totalLineOne(orderItem, currencySymbol), | ||
lineTwo = totalLineTwo(orderItem, currencySymbol); | ||
@@ -86,0 +88,0 @@ if (lineTwo) { |
{ | ||
"name": "couponable", | ||
"description": "Helper functions for dealing with coupons.", | ||
"version": "4.0.0", | ||
"version": "5.0.0", | ||
"author": "Chris McC", | ||
@@ -6,0 +6,0 @@ "license": "MIT", |
30
test.js
@@ -60,2 +60,11 @@ var couponable = require('.'); | ||
it('returns an alternate currency symbol', function() { | ||
assert.equal(totalLineOne({ | ||
quantity: 1, | ||
purchasableType: 'bundle', | ||
interval: 'month', | ||
priceInCents: 200 | ||
}, '£'), '£2.00 / month'); | ||
}); | ||
it('returns the price without the interval if it is a gift', function() { | ||
@@ -158,2 +167,13 @@ assert.equal(totalLineOne({ | ||
it('returns an alternate currency symbol', function() { | ||
assert.equal(totalLineTwo({ | ||
quantity: 1, | ||
purchasableType: 'bundle', | ||
interval: 'month', | ||
coupon: {amountOffInCents: 4, duration: 'once'}, | ||
priceInCents: 6 | ||
}, '£'), '£0.06 / month'); | ||
}); | ||
it('returns null if there is a forever coupon', function() { | ||
@@ -191,2 +211,12 @@ assert.equal(totalLineTwo({ | ||
it('returns an alternate currency symbol', function() { | ||
assert.equal(totalDescription({ | ||
quantity: 1, | ||
purchasableType: 'bundle', | ||
interval: 'month', | ||
coupon: {amountOffInCents: 4, duration: 'once'}, | ||
priceInCents: 6 | ||
}, '£'), '£0.02 for the first month, then £0.06 / month'); | ||
}); | ||
it('returns just line one if line two is not set', function() { | ||
@@ -193,0 +223,0 @@ assert.equal(totalDescription({ |
12546
366