Comparing version 1.0.3 to 1.0.4
@@ -6,2 +6,3 @@ const CurrencyFormatter = require("./js/currency_formatter"); | ||
module.exports = { | ||
@@ -8,0 +9,0 @@ CurrencyFormatter, |
@@ -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": {} | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
13109
8
219
1
135