Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nlo/currency-formatter

Package Overview
Dependencies
Maintainers
7
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nlo/currency-formatter - npm Package Compare versions

Comparing version 1.0.8 to 1.1.0

4

dist/currency-formatter.d.ts
declare class CurrencyFormatter {
private userFormatter;
private gtmFormatter;
formatCents(inputCents: number | string, allowNegative?: boolean): string | undefined;
formatCentsForUser(inputCents: number): string;
formatCentsForGTM(inputCents: number): string;
formatCentsRounded(cents: number | string, allowNegative?: boolean): string | undefined;

@@ -4,0 +8,0 @@ formatCentsForText(cents: number | string, allowNegative?: boolean): string | undefined;

47

dist/currency-formatter.js

@@ -6,3 +6,9 @@ "use strict";

function CurrencyFormatter() {
// The currency style isn't used here because it requires a currency and we don't want to prefix with a € sign
this.userFormatter = new Intl.NumberFormat('nl-NL', { style: 'decimal', minimumFractionDigits: 2, maximumFractionDigits: 2 });
this.gtmFormatter = new Intl.NumberFormat('us-US', { useGrouping: false, style: 'decimal', minimumFractionDigits: 2, maximumFractionDigits: 2 });
}
/* @deprecated from of 7-2-2023, it's still used in production environments
* Replaced by formatCentsForUser and formatCentsForGTM
*/
CurrencyFormatter.prototype.formatCents = function (inputCents, allowNegative) {

@@ -14,38 +20,13 @@ if (allowNegative === void 0) { allowNegative = true; }

}
var isNegative = false;
if (cents < 0) {
isNegative = true;
if (cents < 0 && !allowNegative) {
cents *= -1;
}
var centsStr = null;
if (!cents) {
centsStr = '000';
}
else if (cents < 10) {
centsStr = '00' + cents;
}
else if (cents < 100) {
centsStr = '0' + cents;
}
var money = (centsStr || cents + '')
.split('')
.reverse()
.map(function (element, index) {
if (index === 2) {
// This is the last cent digit, so add a comma before it.
return element + ',';
}
if (index > 3 && ((index + 1) % 3) === 0) {
// Add period character at the thousand indicator.
return element + '.';
}
// This is a regular character.
return element;
})
.reverse().join('');
if (isNegative && allowNegative) {
money = '-' + money;
}
return money;
return this.formatCentsForUser(cents);
};
CurrencyFormatter.prototype.formatCentsForUser = function (inputCents) {
return this.userFormatter.format(inputCents / 100);
};
CurrencyFormatter.prototype.formatCentsForGTM = function (inputCents) {
return this.gtmFormatter.format(inputCents / 100);
};
CurrencyFormatter.prototype.formatCentsRounded = function (cents, allowNegative) {

@@ -52,0 +33,0 @@ var money = this.formatCents(cents, allowNegative);

{
"name": "@nlo/currency-formatter",
"version": "1.0.8",
"version": "1.1.0",
"description": "",

@@ -27,3 +27,3 @@ "main": "dist/index.js",

},
"gitHead": "0c50485a48183bfeed8a6caef6d4a376d0a42349"
"gitHead": "8160d27a0be6286b57d48787001ee1052c299b77"
}
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc