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

numeros

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

numeros - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

README.md

1

index.js

@@ -6,2 +6,3 @@ const CurrencyFormatter = require("./js/currency_formatter");

module.exports = {

@@ -8,0 +9,0 @@ CurrencyFormatter,

56

js/csuf.js

@@ -7,30 +7,32 @@ "use strict";

var ComputerStorageUnitFormatter = /** @class */ (function () {
function ComputerStorageUnitFormatter() {
this.result = "";
this.unit = "";
this.storageUnits = [
{ value: 8, unit: "Byte" },
{ value: 1024, unit: "KB" },
{ value: Math.pow(1024, 2), unit: "MB" },
{ value: Math.pow(1024, 3), unit: "GB" },
{ value: Math.pow(1024, 4), unit: "TB" },
{ value: Math.pow(1024, 5), unit: "PB" },
];
function ComputerStorageUnitFormatter() {
this.result = "";
this.unit = "";
this.storageUnits = [
{ value: 8, unit: "Byte" },
{ value: 1024, unit: "KB" },
{ value: Math.pow(1024, 2), unit: "MB" },
{ value: Math.pow(1024, 3), unit: "GB" },
{ value: Math.pow(1024, 4), unit: "TB" },
{ value: Math.pow(1024, 5), unit: "PB" },
];
}
ComputerStorageUnitFormatter.prototype.formate = function (value, sep = ".") {
if (typeof value != "number") throw Error("value must be a number");
value = Math.abs(value);
// in case value was in bits return it as it its
if (value < 8) return value + "b";
// in other cases
for (var i = 1; i <= this.storageUnits.length - 1; i++) {
if (value < this.storageUnits[i].value * 8) {
this.result = (value / this.storageUnits[i - 1].value).toFixed(1);
this.unit = this.storageUnits[i - 1].unit;
break;
}
}
ComputerStorageUnitFormatter.prototype.formate = function (value) {
// in case value was in bits return it as it its
if (value < 8)
return value + "b";
// in other cases
for (var i = 1; i <= this.storageUnits.length - 1; i++) {
if (value < this.storageUnits[i].value * 8) {
this.result = (value / this.storageUnits[i - 1].value).toFixed(1);
this.unit = this.storageUnits[i - 1].unit;
break;
}
}
return "" + this.result + this.unit;
};
return ComputerStorageUnitFormatter;
}());
return this.result.replace(".", sep) + this.unit;
};
return ComputerStorageUnitFormatter;
})();
module.exports = ComputerStorageUnitFormatter;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var currenciesISO = "USD";
var CurrencyFormatter = /** @class */ (function () {
function CurrencyFormatter() {
this.result = 0;
this.unit = "";
this.currenciesList = {
USD: this.toCurrencySign(0x24),
EUR: this.toCurrencySign(0x20ac),
GBP: this.toCurrencySign(0xa3),
YEN: this.toCurrencySign(0xa5),
INR: this.toCurrencySign(0x20b9),
RUB: this.toCurrencySign(0x20bd),
YUA: this.toCurrencySign(0x5143),
};
this.currencies = [
{ value: 1000, unit: "K" },
{ value: Math.pow(10, 6), unit: "M" },
{ value: Math.pow(10, 9), unit: "B" },
{ value: Math.pow(10, 12), unit: "T" },
];
function CurrencyFormatter() {
this.result = 0;
this.unit = "";
this.currenciesList = {
USD: this.toCurrencySign(0x24),
EUR: this.toCurrencySign(0x20ac),
GBP: this.toCurrencySign(0xa3),
YEN: this.toCurrencySign(0xa5),
INR: this.toCurrencySign(0x20b9),
RUB: this.toCurrencySign(0x20bd),
YUA: this.toCurrencySign(0x5143),
};
this.currencies = [
{ value: 1000, unit: "K" },
{ value: Math.pow(10, 6), unit: "M" },
{ value: Math.pow(10, 9), unit: "B" },
{ value: Math.pow(10, 12), unit: "T" },
{ value: Math.pow(10, 15), unit: "Z"}
];
}
CurrencyFormatter.prototype.toCurrencySign = function (uniCode) {
return String.fromCodePoint(uniCode);
};
// this will include only one digit after the floating point
CurrencyFormatter.prototype.shortFormat = function (
value,
currency = "USD",
sep = ","
) {
if (typeof value != "number") throw Error("value must be a number");
// transform negative number to positive
value = Math.abs(value);
if (value < 1000) return "" + currency + value;
for (var i = 1; i <= this.currencies.length - 1; i++) {
if (value < this.currencies[i].value) {
this.result = value / this.currencies[i - 1].value;
this.unit = this.currencies[i - 1].unit;
return (
"" + currency + this.result.toFixed(1).replace(".", sep) + this.unit
);
}
}
CurrencyFormatter.prototype.toCurrencySign = function (uniCode) {
return String.fromCodePoint(uniCode);
};
// this will include only one digit after the floating point
CurrencyFormatter.prototype.shortFormat = function (value, currency, sep, asSign) {
if (sep === void 0) { sep = ","; }
if (asSign === void 0) { asSign = true; }
// put either the currency in a sign or in a ISO
var cur = asSign ? this.currenciesList[currency] : currency;
// transform negative number to positive
value = Math.abs(value);
if (value < 1000)
return "" + cur + value;
for (var i = 1; i <= this.currencies.length - 1; i++) {
if (value < this.currencies[i].value) {
this.result = value / this.currencies[i - 1].value;
this.unit = this.currencies[i - 1].unit;
return "" + cur + this.result.toFixed(1).replace(".", sep) + this.unit;
}
}
return "";
};
// the standard format will include the full number
// with a splite between the tens, hunderds, thousends, milions
// the standerd will follow only major currencies
CurrencyFormatter.prototype.standardFormat = function (value, currency, sep, asSign) {
if (sep === void 0) { sep = ","; }
if (asSign === void 0) { asSign = true; }
var cur = asSign ? this.currenciesList[currency] : currency;
value = Math.abs(value);
// get the integer part of value
var intPart = value.toString().split(".")[0];
// get the decima part
var decimalPoints = value.toString().split(".")[1] || "00";
// in case the integer part was only as equal or less then
// a hunderades then we return the value as it is
if (intPart.length <= 3)
return currency + intPart + "." + decimalPoints;
// in case the integer part was more then a hunderads
// we do slice it into parts
// each part equal one unit of bilions, hunderads, thousends ...
intPart = intPart.split("").reverse().join("");
for (var i = 0; i <= intPart.length - 1; i++) {
if (i % 3 == 0 && i != 0)
this.result += sep;
this.result += intPart[i];
}
return cur + " " + this.result
.split("")
.reverse()
.join("") + "." + decimalPoints;
};
return CurrencyFormatter;
}());
return "";
};
// the standard format will include the full number
// with a splite between the tens, hunderds, thousends, milions
// the standerd will follow only major currencies
CurrencyFormatter.prototype.standardFormat = function (
value,
currency = "USD",
sep = ","
) {
if (typeof value != "number") throw Error("value must be a number");
value = Math.abs(value);
// get the integer part of value
var intPart = value.toString().split(".")[0];
// get the decima part
var decimalPoints = value.toString().split(".")[1] || "00";
// in case the integer part was only as equal or less then
// a hunderades then we return the value as it is
if (intPart.length <= 3) return currency + intPart + "." + decimalPoints;
// in case the integer part was more then a hunderads
// we do slice it into parts
// each part equal one unit of bilions, hunderads, thousends ...
intPart = intPart.split("").reverse().join("");
for (var i = 0; i <= intPart.length - 1; i++) {
if (i % 3 == 0 && i != 0) this.result += sep;
this.result += intPart[i];
}
return (
currency +
" " +
this.result.split("").reverse().join("") +
"." +
decimalPoints
);
};
return CurrencyFormatter;
})();
module.exports = CurrencyFormatter;

@@ -45,3 +45,3 @@ "use strict";

this.result = value;
return "" + this.result + (this.unit + unit[0]);
return "" + ~~(this.result) + (this.unit + unit[0]);
};

@@ -48,0 +48,0 @@ return MetricSystemFormatter;

{
"name": "numeros",
"version": "1.0.3",
"version": "1.0.4",
"description": "small javascrip utility to format numbers in a short and standerd method including (currencies,timing,computer storage unit sizes, Metrics Systems)",

@@ -11,3 +11,3 @@ "main": "index.js",

"type": "git",
"url": "https://github.com/biloziti"
"url": "https://github.com/biloziti/numeros/tree/v1.0.4"
},

@@ -27,2 +27,2 @@ "keywords": [

"devDependencies": {}
}
}
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