Socket
Socket
Sign inDemoInstall

currency-formatter

Package Overview
Dependencies
1
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.1 to 1.0.2

39

index.js
var currencies = require('./currencies')
var accounting = require('accounting')
var find = require('lodash.find')
/*
This polyfill intends to emulate the Array.prototy.find() method
for browsers who don't support it yet.
*/
if (!Array.prototype.find) {
Array.prototype.find = function(predicate) {
if (this === null) {
throw new TypeError('Array.prototype.find called on null or undefined');
}
if (typeof predicate !== 'function') {
throw new TypeError('predicate must be a function');
}
var list = Object(this);
var length = list.length >>> 0;
var thisArg = arguments[1];
var value;
for (var i = 0; i < length; i++) {
value = list[i];
if (predicate.call(thisArg, value, i, list)) {
return value;
}
}
return undefined;
};
}
exports.defaultCurrency = {

@@ -17,3 +42,3 @@ symbol: '',

exports.format = function (value, options) {
var currency = find(currencies, function (c) { return c.code === options.code }) || exports.defaultCurrency
var currency = findCurrency(options.code) || exports.defaultCurrency

@@ -26,7 +51,7 @@ var symbolOnLeft = currency.symbolOnLeft

format = spaceBetweenAmountAndSymbol
? '%s %v'
? '%s %v'
: '%s%v'
} else {
format = spaceBetweenAmountAndSymbol
? '%v %s'
? '%v %s'
: '%v%s'

@@ -58,8 +83,10 @@ }

exports.findCurrency = function (currencyCode) {
return find(currencies, function (c) { return c.code === currencyCode })
function findCurrency (currencyCode) {
return currencies.find(function (c) { return c.code === currencyCode })
}
exports.findCurrency = findCurrency
function isUndefined (val) {
return typeof val === 'undefined'
}

5

package.json
{
"name": "currency-formatter",
"version": "1.0.1",
"version": "1.0.2",
"description": "A simple Javascript utility that helps you to display currency properly",

@@ -29,5 +29,4 @@ "main": "index.js",

"dependencies": {
"accounting": "^0.4.1",
"lodash.find": "^4.0.0"
"accounting": "^0.4.1"
}
}

@@ -38,3 +38,3 @@ var chai = require('chai')

var result = currencyFormatter.format(10, { code: 'ARS' })
assert.equal(result, '$ 10,00')
assert.equal(result, '$ 10,00')
})

@@ -44,3 +44,3 @@

var result = currencyFormatter.format(100, { code: 'ARS' })
assert.equal(result, '$ 100,00')
assert.equal(result, '$ 100,00')
})

@@ -50,3 +50,3 @@

var result = currencyFormatter.format(1000, { code: 'ARS' })
assert.equal(result, '$ 1.000,00')
assert.equal(result, '$ 1.000,00')
})

@@ -56,3 +56,3 @@

var result = currencyFormatter.format(10000, { code: 'ARS' })
assert.equal(result, '$ 10.000,00')
assert.equal(result, '$ 10.000,00')
})

@@ -62,3 +62,3 @@

var result = currencyFormatter.format(1000000, { code: 'ARS' })
assert.equal(result, '$ 1.000.000,00')
assert.equal(result, '$ 1.000.000,00')
})

@@ -99,3 +99,3 @@ })

var result = currencyFormatter.format(10, { code: 'EUR' })
assert.equal(result, '10,00 €')
assert.equal(result, '10,00 €')
})

@@ -105,3 +105,3 @@

var result = currencyFormatter.format(100, { code: 'EUR' })
assert.equal(result, '100,00 €')
assert.equal(result, '100,00 €')
})

@@ -111,3 +111,3 @@

var result = currencyFormatter.format(1000, { code: 'EUR' })
assert.equal(result, '1 000,00 €')
assert.equal(result, '1 000,00 €')
})

@@ -117,3 +117,3 @@

var result = currencyFormatter.format(10000, { code: 'EUR' })
assert.equal(result, '10 000,00 €')
assert.equal(result, '10 000,00 €')
})

@@ -123,3 +123,3 @@

var result = currencyFormatter.format(1000000, { code: 'EUR' })
assert.equal(result, '1 000 000,00 €')
assert.equal(result, '1 000 000,00 €')
})

@@ -126,0 +126,0 @@ })

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc