Socket
Socket
Sign inDemoInstall

@thi.ng/base-n

Package Overview
Dependencies
Maintainers
1
Versions
99
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thi.ng/base-n - npm Package Compare versions

Comparing version 2.5.9 to 2.5.10

4

16.js

@@ -1,4 +0,4 @@

import { defBase } from "./base.js";
import { __B16_LC_CHARS, defBase } from "./base.js";
export const B16_UC_CHARS = "0123456789ABCDEF";
export const B16_LC_CHARS = "0123456789abcdef";
export const B16_LC_CHARS = __B16_LC_CHARS;
/**

@@ -5,0 +5,0 @@ * Alias for {@link B16_LC_CHARS}

import type { IBase } from "./api.js";
export declare const defBase: (chars: string) => BaseN;
/** @internal */
export declare const __B16_LC_CHARS = "0123456789abcdef";
export declare class BaseN implements IBase {

@@ -4,0 +6,0 @@ readonly base: string;

@@ -1,3 +0,7 @@

import { U8 } from "@thi.ng/hex";
export const defBase = (chars) => new BaseN(chars);
const ZERO = BigInt(0);
const MASK = BigInt(255);
const SHIFT = BigInt(8);
/** @internal */
export const __B16_LC_CHARS = "0123456789abcdef";
export class BaseN {

@@ -24,7 +28,7 @@ constructor(base) {

const { base, N } = this;
if (x === BigInt(0))
if (x === ZERO)
return __pad(base[0], size, base[0]);
const NN = BigInt(N);
let res = "";
while (x > 0) {
while (x > ZERO) {
res = base[Number(x % NN)] + res;

@@ -36,6 +40,6 @@ x /= NN;

encodeBytes(buf, size = 0) {
let hex = "";
let hex = "0x";
for (let i = 0, n = buf.length; i < n; i++)
hex += U8(buf[i]);
return this.encodeBigInt(BigInt(`0x${hex}`), size);
hex += __u8(buf[i]);
return this.encodeBigInt(BigInt(hex), size);
}

@@ -53,3 +57,3 @@ decode(x) {

const NN = BigInt(N);
let res = BigInt(0);
let res = ZERO;
for (let n = x.length - 1, i = 0; i <= n; i++) {

@@ -62,6 +66,4 @@ res += BigInt(index[x[i]]) * NN ** BigInt(n - i);

let y = this.decodeBigInt(x);
const M = BigInt(255);
const SHIFT = BigInt(8);
for (let i = buf.length; i-- > 0;) {
buf[i] = Number(y & M);
buf[i] = Number(y & MASK);
y >>= SHIFT;

@@ -78,2 +80,5 @@ }

}
/** @internal */
const __pad = (x, size, fill) => size - x.length > 0 ? fill.repeat(size - x.length) + x : x;
/** @internal */
const __u8 = (x) => __B16_LC_CHARS[(x >>> 4) & 0xf] + __B16_LC_CHARS[x & 0xf];
# Change Log
- **Last updated**: 2023-08-10T12:25:09Z
- **Last updated**: 2023-08-12T13:14:08Z
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)

@@ -12,2 +12,8 @@

### [2.5.10](https://github.com/thi-ng/umbrella/tree/@thi.ng/base-n@2.5.10) (2023-08-12)
#### ♻️ Refactoring
- remove deps, minor internal updates ([c675cba](https://github.com/thi-ng/umbrella/commit/c675cba))
## [2.5.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/base-n@2.5.0) (2023-03-17)

@@ -14,0 +20,0 @@

{
"name": "@thi.ng/base-n",
"version": "2.5.9",
"version": "2.5.10",
"description": "Arbitrary base-n conversions w/ presets for base8/16/32/36/58/62/64/85, support for bigints and encoding/decoding of byte arrays",

@@ -36,8 +36,5 @@ "type": "module",

},
"dependencies": {
"@thi.ng/hex": "^2.3.14"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.36.3",
"@thi.ng/testament": "^0.3.20",
"@microsoft/api-extractor": "^7.36.4",
"@thi.ng/testament": "^0.3.21",
"rimraf": "^5.0.1",

@@ -114,3 +111,3 @@ "tools": "^0.0.1",

},
"gitHead": "ad9ac3232c6fc5fc8a0df75ac82fc1e0e9fb0258\n"
"gitHead": "399f8c53d66b9b763d16c21bb59f145df5f59514\n"
}

@@ -54,7 +54,7 @@ <!-- This file is generated - DO NOT EDIT! -->

Package sizes (brotli'd, pre-treeshake): ESM: 931 bytes
Package sizes (brotli'd, pre-treeshake): ESM: 944 bytes
## Dependencies
- [@thi.ng/hex](https://github.com/thi-ng/umbrella/tree/develop/packages/hex)
None

@@ -61,0 +61,0 @@ ## API

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