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

biggystring

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

biggystring - npm Package Compare versions

Comparing version 4.0.0 to 4.1.0

lib/test/biggystring.test.d.ts

5

lib/index.d.ts

@@ -16,4 +16,7 @@ /**

declare function max(x1: string, y1: string, base?: number): string;
declare const floor: (x1: string, precision: number) => string;
declare const ceil: (x1: string, precision: number) => string;
declare const round: (x1: string, precision: number) => string;
declare function toFixed(x1: string, minPrecision?: number, maxPrecision?: number): string;
declare function log10(x: string): number;
export { add, sub, mul, div, gt, lt, gte, lte, eq, min, max, log10, toFixed, abs, };
export { add, sub, mul, div, gt, lt, gte, lte, eq, min, max, log10, toFixed, abs, floor, ceil, round, };

62

lib/index.js

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.abs = exports.toFixed = exports.log10 = exports.max = exports.min = exports.eq = exports.lte = exports.gte = exports.lt = exports.gt = exports.div = exports.mul = exports.sub = exports.add = void 0;
exports.round = exports.ceil = exports.floor = exports.abs = exports.toFixed = exports.log10 = exports.max = exports.min = exports.eq = exports.lte = exports.gte = exports.lt = exports.gt = exports.div = exports.mul = exports.sub = exports.add = void 0;
const bn_js_1 = __importDefault(require("bn.js"));

@@ -309,2 +309,59 @@ // const MAX_DECIMALS = 10

exports.max = max;
function precisionAdjust(type, x1, precision = 0) {
var _a;
validate(x1);
let negative = false;
let out = '';
let x = x1;
if (x.includes('-')) {
negative = true;
// Remove any leading '-' signs
x = x.replace(/^-+/, '');
}
const [whole, decimal = ''] = x.split('.');
// Number of decimal places number has
const decimalPos = x.indexOf('.');
const checkIndex = decimalPos !== -1 ? decimalPos - precision : x.length - precision;
const combined = whole + decimal;
if (type === 'round') {
const checkValue = (_a = combined[checkIndex]) !== null && _a !== void 0 ? _a : '0';
if (gte(checkValue, '5')) {
type = 'ceil';
}
else {
type = 'floor';
}
}
// Zero out lower precision places
const numZeros = Math.max(combined.length - checkIndex + 1, 0);
const zeroString = new Array(numZeros).join('0');
let outCombined = combined.substring(0, checkIndex) + zeroString;
const bumpUp = gt(combined.substring(checkIndex), '0');
if (type === 'ceil' && bumpUp) {
const addValue = '1' + zeroString;
outCombined = add(outCombined, addValue);
}
const newDecimalPos = decimalPos + (outCombined.length - combined.length);
// Add back the decimal
if (decimalPos !== -1) {
out =
outCombined.substring(0, newDecimalPos) +
'.' +
outCombined.substring(newDecimalPos);
}
else {
out = outCombined;
}
out = trimEnd(out);
if (negative && out !== '0') {
out = '-' + out;
}
return out;
}
const floor = (x1, precision) => precisionAdjust('floor', x1, precision);
exports.floor = floor;
const ceil = (x1, precision) => precisionAdjust('ceil', x1, precision);
exports.ceil = ceil;
const round = (x1, precision) => precisionAdjust('round', x1, precision);
exports.round = round;
function toFixed(x1, minPrecision = 2, maxPrecision = 8) {

@@ -340,3 +397,3 @@ validate(x1);

out = out.replace(/\.+$/, '');
if (negative) {
if (negative && out !== '0') {
out = '-' + out;

@@ -360,1 +417,2 @@ }

exports.log10 = log10;
//# sourceMappingURL=index.js.map
{
"name": "biggystring",
"version": "4.0.0",
"version": "4.1.0",
"description": "Full floating point big number library using regular Javascript string",

@@ -41,2 +41,4 @@ "keywords": [

"@types/bn.js": "^4.11.6",
"@types/chai": "^4.3.4",
"@types/mocha": "^10.0.1",
"@types/node": "^14.0.23",

@@ -47,2 +49,3 @@ "@typescript-eslint/eslint-plugin": ">=2.0.0",

"babel-eslint": "^7.2.3",
"chai": "^4.3.7",
"eslint": ">=6.2.2",

@@ -58,3 +61,3 @@ "eslint-config-standard-kit": ">=0.14.4",

"husky": "^0.14.3",
"mocha": "^3.1.2",
"mocha": "^10.1.0",
"prettier": "^2.0.5",

@@ -61,0 +64,0 @@ "sucrase": "^3.12.1",

@@ -15,30 +15,44 @@ # biggystring

console.log(bs.add('32', '10') // => '42'
console.log(bs.sub('32', '10') // => '22'
console.log(bs.mul('32', '10') // => '320'
console.log(bs.div('32', '10') // => '3' Truncates remainder
bs.add('32', '10') // => '42'
bs.sub('32', '10') // => '22'
bs.mul('32', '10') // => '320'
bs.div('32', '10') // => '3' Truncates remainder
### Hex
console.log(bs.add('0xa', '10') // => '20'
console.log(bs.add('0xa', '0x20') // => '42'
console.log(bs.add('10', '0x10') // => '26'
bs.add('0xa', '10') // => '20'
bs.add('0xa', '0x20') // => '42'
bs.add('10', '0x10') // => '26'
### Comparisons
console.log(bs.gt('32', '10') // => True
console.log(bs.lt('32', '10') // => False
console.log(bs.gte('32', '32') // => True
console.log(bs.lte('32', '10') // => False
console.log(bs.eq('32', '10') // => False
console.log(bs.eq('32', '32') // => True
bs.gt('32', '10') // => True
bs.lt('32', '10') // => False
bs.gte('32', '32') // => True
bs.lte('32', '10') // => False
bs.eq('32', '10') // => False
bs.eq('32', '32') // => True
### Floating point operations (base 10 only)
console.log(bs.add('3.2', '1.3') // => '4.5'
console.log(bs.sub('3.2', '1.3') // => '1.9'
console.log(bs.mul('3.2', '1.3') // => '4.16'
bs.add('3.2', '1.3') // => '4.5'
bs.sub('3.2', '1.3') // => '1.9'
bs.mul('3.2', '1.3') // => '4.16'
// For `div`, 3rd arg is base, 4th arg is decimal precision
console.log(bs.div('10', '3.0', 10, 5) // => '3.33333'
console.log(bs.div('1.23', '3.3', 10, 5) // => '0.37272'
// For `div`, 3rd arg is decimal precision, 4th arg is base
bs.div('10', '3.0', 5, 10) // => '3.33333'
bs.div('1.23', '3.3', 5, 10) // => '0.37272'
### Rounding functions (base 10 only)
bs.floor('123.456', 0) => '123'
bs.floor('123.456', 1) => '120'
bs.floor('123.456', -1) => '123.4'
bs.ceil('123.456', 0) => '124'
bs.ceil('123.456', 1) => '130'
bs.ceil('123.456', -1) => '123.5'
bs.round('123.456', 0) => '123'
bs.round('125.456', 1) => '130'
bs.round('123.456', -1) => '123.5'

Sorry, the diff of this file is not supported yet

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