Skip to content

Commit

Permalink
Merge 780bf2e into b369eaa
Browse files Browse the repository at this point in the history
  • Loading branch information
dotbear committed Aug 10, 2016
2 parents b369eaa + 780bf2e commit 98c9171
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
25 changes: 15 additions & 10 deletions lib/money.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
* file that was distributed with this source code.
*/

var _ = require('lodash');
var extend = require('lodash/extend');
var isFunction = require('lodash/isFunction');
var isNaN = require('lodash/isNaN');
var isObject = require('lodash/isObject');
var isPlainObject = require('lodash/isPlainObject');
var isString = require('lodash/isString');
var currencies = require('./currency');

var isInt = function (n) {
Expand Down Expand Up @@ -49,10 +54,10 @@ var assertOperand = function (operand) {
* @constructor
*/
function Money(amount, currency) {
if (_.isString(currency))
if (isString(currency))
currency = currencies[currency];

if (!_.isPlainObject(currency))
if (!isPlainObject(currency))
throw new TypeError('Invalid currency');

if (!isInt(amount))
Expand All @@ -64,7 +69,7 @@ function Money(amount, currency) {
}

Money.fromInteger = function (amount, currency) {
if (_.isObject(amount)) {
if (isObject(amount)) {
if (amount.amount === undefined || amount.currency === undefined)
throw new TypeError('Missing required parameters amount,currency');

Expand All @@ -81,18 +86,18 @@ Money.fromInteger = function (amount, currency) {
Money.fromDecimal = function (amount, currency) {
var multipliers = [1, 10, 100, 1000];

if (_.isObject(amount)) {
if (isObject(amount)) {
if (amount.amount === undefined || amount.currency === undefined)
throw new TypeError('Missing required parameters amount,currency');

currency = amount.currency;
amount = amount.amount;
}

if (_.isString(currency))
if (isString(currency))
currency = currencies[currency];

if (!_.isPlainObject(currency))
if (!isPlainObject(currency))
throw new TypeError('Invalid currency');

var decimals = decimalPlaces(amount);
Expand Down Expand Up @@ -155,7 +160,7 @@ Money.prototype.subtract = function (other) {
* @returns {Money}
*/
Money.prototype.multiply = function (multiplier, fn) {
if (!_.isFunction(fn))
if (!isFunction(fn))
fn = Math.round;

assertOperand(multiplier);
Expand All @@ -172,7 +177,7 @@ Money.prototype.multiply = function (multiplier, fn) {
* @returns {Money}
*/
Money.prototype.divide = function (divisor, fn) {
if (!_.isFunction(fn))
if (!isFunction(fn))
fn = Math.round;

assertOperand(divisor);
Expand Down Expand Up @@ -287,4 +292,4 @@ Money.prototype.toJSON = function () {
};
};

module.exports = _.extend(Money, currencies);
module.exports = extend(Money, currencies);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"url": "https://github.com/davidkalosi/js-money/issues"
},
"dependencies": {
"lodash": "3.x.x"
"lodash": "4.x.x"
},
"devDependencies": {
"mocha": "1.x.x",
Expand Down

0 comments on commit 98c9171

Please sign in to comment.