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

@navpreetdevpuri/base-2-n

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@navpreetdevpuri/base-2-n - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

24

lib/index.js

@@ -8,6 +8,6 @@ var Base2N = /** @class */ (function () {

}
if (n == 0) {
if (n === 0) {
throw new Error("n can't be zero.");
}
if (maxNoOfDigits == 0) {
if (maxNoOfDigits === 0) {
throw new Error("maxNoOfDigits can't be zero.");

@@ -25,3 +25,3 @@ }

this.charset = [];
for (var i = 0; i < this.base; i++) {
for (var i = 0; i < this.base; i += 1) {
this.charset[i] = String.fromCharCode(i);

@@ -34,4 +34,4 @@ }

: new Uint16Array(this.maxNoOfDigits);
if (typeof digits == 'string') {
for (var i = digits.length, j = maxNoOfDigits; i > -1; i--, j--) {
if (typeof digits === 'string') {
for (var i = digits.length, j = maxNoOfDigits; i > -1; i -= 1, j -= 1) {
this.digits[j] = digits.charCodeAt(i);

@@ -46,3 +46,3 @@ if (this.digits[j] > this.base) {

var result = '';
for (var i = 0; i < this.maxNoOfDigits; i++) {
for (var i = 0; i < this.maxNoOfDigits; i += 1) {
result += this.charset[this.digits[i]];

@@ -58,3 +58,3 @@ }

var carry = 0;
for (var i = this.maxNoOfDigits - 1; i > -1; i--) {
for (var i = this.maxNoOfDigits - 1; i > -1; i -= 1) {
if (this.digits[i] < other.digits[i]) {

@@ -73,3 +73,3 @@ result[i] = this.digits[i] - carry + this.base - other.digits[i];

var carry = 0;
for (var i = this.maxNoOfDigits - 1; i > -1; i--) {
for (var i = this.maxNoOfDigits - 1; i > -1; i -= 1) {
var curr = this.digits[i] + other.digits[i] + carry;

@@ -84,3 +84,3 @@ carry = curr > this.base ? 1 : 0;

var carry = 0;
for (var i = 0; i < this.maxNoOfDigits; i++) {
for (var i = 0; i < this.maxNoOfDigits; i += 1) {
var curr = (this.digits[i] >> 1) | (carry << 15);

@@ -93,8 +93,8 @@ carry = curr & 1 ? 1 : 0;

Base2N.prototype.average = function (other) {
if (this.maxNoOfDigits != other.maxNoOfDigits) {
if (this.maxNoOfDigits !== other.maxNoOfDigits) {
throw new Error('Operands are not of the same length');
}
var bothOddFlag = 0;
if (this.digits[this.digits.length - 1] % 2 == 1 &&
other.digits[other.digits.length - 1] % 2 == 1) {
if (this.digits[this.digits.length - 1] % 2 === 1 &&
other.digits[other.digits.length - 1] % 2 === 1) {
bothOddFlag = 1;

@@ -101,0 +101,0 @@ }

{
"name": "@navpreetdevpuri/base-2-n",
"version": "1.0.0",
"version": "1.0.1",
"description": "To work with base 2^n numbers",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -15,7 +15,7 @@ class Base2N {

if (n == 0) {
if (n === 0) {
throw new Error(`n can't be zero.`);
}
if (maxNoOfDigits == 0) {
if (maxNoOfDigits === 0) {
throw new Error(`maxNoOfDigits can't be zero.`);

@@ -31,3 +31,3 @@ }

this.n = n;
this.base = Math.pow(2, n);
this.base = 2 ** n;

@@ -42,3 +42,3 @@ const noOf1sInBaseBinary = this.base.toString(2).split('1').length - 1;

this.charset = [];
for (let i = 0; i < this.base; i++) {
for (let i = 0; i < this.base; i += 1) {
this.charset[i] = String.fromCharCode(i);

@@ -52,4 +52,4 @@ }

if (typeof digits == 'string') {
for (let i = digits.length, j = maxNoOfDigits; i > -1; i--, j--) {
if (typeof digits === 'string') {
for (let i = digits.length, j = maxNoOfDigits; i > -1; i -= 1, j -= 1) {
this.digits[j] = digits.charCodeAt(i);

@@ -67,3 +67,3 @@ if (this.digits[j] > this.base) {

let result = '';
for (let i = 0; i < this.maxNoOfDigits; i++) {
for (let i = 0; i < this.maxNoOfDigits; i += 1) {
result += this.charset[this.digits[i]];

@@ -80,3 +80,3 @@ }

let carry = 0;
for (let i = this.maxNoOfDigits - 1; i > -1; i--) {
for (let i = this.maxNoOfDigits - 1; i > -1; i -= 1) {
if (this.digits[i] < other.digits[i]) {

@@ -96,3 +96,3 @@ result[i] = this.digits[i] - carry + this.base - other.digits[i];

let carry = 0;
for (let i = this.maxNoOfDigits - 1; i > -1; i--) {
for (let i = this.maxNoOfDigits - 1; i > -1; i -= 1) {
const curr = this.digits[i] + other.digits[i] + carry;

@@ -108,3 +108,3 @@ carry = curr > this.base ? 1 : 0;

let carry = 0;
for (let i = 0; i < this.maxNoOfDigits; i++) {
for (let i = 0; i < this.maxNoOfDigits; i += 1) {
const curr = (this.digits[i] >> 1) | (carry << 15);

@@ -118,3 +118,3 @@ carry = curr & 1 ? 1 : 0;

average(other: Base2N): Base2N {
if (this.maxNoOfDigits != other.maxNoOfDigits) {
if (this.maxNoOfDigits !== other.maxNoOfDigits) {
throw new Error('Operands are not of the same length');

@@ -124,4 +124,4 @@ }

if (
this.digits[this.digits.length - 1] % 2 == 1 &&
other.digits[other.digits.length - 1] % 2 == 1
this.digits[this.digits.length - 1] % 2 === 1 &&
other.digits[other.digits.length - 1] % 2 === 1
) {

@@ -128,0 +128,0 @@ bothOddFlag = 1;

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