npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@ibad.one/basex

v1.0.2

Published

Arbitrary-Base Buffer Utility

Downloads

7

Readme


Description

A pure javascript library for Arbitrary-Base Buffer operations.

Built-in support for: Base16 (Hexadecimal), Base32, Base58, Base62, Base64, Base64URI

Installing

npm install --save @ibad.one/basex

API

Class: BaseX

Class: IntegralBaseX

Class: BaseCustomX

Class: BaseX

An Arbitrary-Base Buffer Utility

Static method: from_int(src[, base, endian])

  • src: <number>
  • base: <number>
  • endian: <number> <0 (default) for little-endian, >=0 for big-endian
  • Returns: <Uint8Array>

Static method: to_int(src[, base, endian])

  • src: <Uint8Array>
  • base: <number>
  • Returns: <number>

Static method: from(src[, decode_cb, state_init, endian])

  • src: <string>
  • decode_cb: <CallableFunction> | <string> | null (default, null)
  • state_init: <Object> Initial state for decoder (default, {})
  • endian: <number> <0 (default) for little-endian, >=0 for big-endian
  • Returns: <Uint8Array>

Static method: from_str(src)

  • src: <string>
  • Returns: <Uint8Array>

Static method: from_b64(buff[, alphabet, pad])

  • buff: <string>
  • alphabet: <string> (default, BaseX.ALPHABET.base64)
  • pad: <string> (default, "=")
  • Returns: <Uint8Array>

Static method: from_b32(buff[, alphabet, pad])

  • buff: <string>
  • alphabet: <string> (default, BaseX.ALPHABET.base32)
  • pad: <string> (default, "=")
  • Returns: <Uint8Array>

Static method: to(src[, encode_cb, state_init, endian])

  • src: <Uint8Array>
  • encode_cb: <CallableFunction> | <string> | null (default, null)
  • state_init: <Object> Initial state for encoder (default, {})
  • endian: <number> <0 (default) for little-endian, >=0 for big-endian
  • Returns: <string>

Static method: to_str(x);

  • x: <Uint8Array>
  • Returns: <string>

Static method: to_b64(buff[, alphabet, pad])

  • buff: <Uint8Array>
  • alphabet: <string> (default, BaseX.ALPHABET.base64)
  • pad: <string> (default, "=")
  • Returns: <string>

Static method: to_b32(buff[, alphabet, pad])

  • buff: <Uint8Array>
  • alphabet: <string> (default, BaseX.ALPHABET.base32)
  • pad: <string> (default, "=")
  • Returns: <string>

Static method: shift(x, c)

  • x: <Uint8Array>
  • c: <number> No. of bits to shift left. Use negative c to shift right.
  • Returns: <Uint8Array>

Static method: cmp(x_a, x_b)

  • x_a: <Uint8Array> Left buffer
  • x_b: <Uint8Array> Right buffer
  • Returns: <number> 0 for equal, <0 for x_a < x_b, >0 for x_a > x_b

Static method: add(x_a, x_b[, base])

  • x_a: <Uint8Array> Buffer Addend
  • x_b: <Uint8Array> Buffer Addend
  • base: <number> (default, 256)
  • Returns: <Uint8Array> The sum of the two buffers

Static method: sub(x_a, x_b[, base])

  • x_a: <Uint8Array> Buffer Minuend
  • x_b: <Uint8Array> Buffer Subtrahend
  • base: <number> (default, 256)
  • Returns: <Uint8Array> The difference of the two buffers

Static method: mult_byte(x_a, c[, base])

  • x: <Uint8Array> Buffer Multiplicand
  • c: <number> Scalar Multiplicand
  • base: <number> (default, 256)
  • Returns: <Uint8Array> Scalar product

Static method: mult(x_a, x_b[, base])

  • x_a: <Uint8Array> Buffer Multiplicand
  • x_b: <Uint8Array> Buffer Multiplicand
  • base: <number> (default, 256)
  • Returns: <Uint8Array> The cross product of the two buffers

Static method: div_byte(x_a, c[, base])

  • x: <Uint8Array> Buffer Dividend
  • c: <number> Scalar Divisor
  • base: <number> (default, 256)
  • Returns: <Uint8Array> Quotient

Static method: convert(x, base_s, base_d)

  • x: <Uint8Array> Buffer
  • base_s: <number> Source base
  • base_d: <number> Destination base
  • Returns: <Uint8Array> Buffer converted from bases_s to base_d

Static method: make_encoder(alphabet[, mode])

  • alphabet: <string>
  • mode: <{0|1}> 0 (default) for encode, 1 for decode
  • Returns: <CallableFunction> Encoder or decoder function

Static field: ALPHABET

List of built-in alphabets for encoding, as follows:

  • base16: "0123456789ABCDEF"
  • base32: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"
  • base58: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
  • base62: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
  • base64: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
  • base64uri: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"

Class: IntegralBaseX

A template for a Base interpreter using a specified base and alphabet, using an integral approach. That is, string inputs will be treated as a big endian buffer stream, that will first be converted to little-endian before conversions.

Instance method: constructor(base, alphabet)

  • base: <number>
  • alphabet: <string>|null (default, null)

Instance method: from_buff(x)

  • x: <Uint8Array> Plaintext buffer
  • Returns: <string> BaseX encoded Encodes a plaintext buffer into the instance's encoding scheme

Instance method: from(src)

  • src: <string> Plaintext string
  • Returns: <string> BaseX encoded Encodes a plaintext string into the instance's encoding scheme

Instance method: from_int(val)

  • val: <number> Plaintext integer
  • Returns: <string> BaseX encoded Encodes a plaintext integer into the instance's encoding scheme

Instance method: to_buff(src)

  • src: <string> BaseX encoded string
  • Returns: <Uint8Array> Buffer Decodes a BaseX encoded string into a buffer

Instance method: to(src)

  • src: <string> BaseX encoded string
  • Returns: <string> Plaintext string Decodes a BaseX encoded string into a plaintext string

Instance method: to_int(src)

  • src: <string> BaseX encoded string
  • Returns: <number> Plaintext integer Decodes a BaseX encoded string into a plaintext number

Instance: Base16

Instance: Base58

Instance: Base62

Class: BaseCustomX

A template for a Base interpreter using a specified base and alphabet, using an arbitrary encoder and decoder. Buffer and alphabet will be fed to the encoder / decoder as-is.

Instance method: constructor(base, alphabet)

  • base: <number>
  • alphabet: <string>|null (default, null)

Instance method: from_buff(x)

  • x: <Uint8Array> Plaintext buffer
  • Returns: <string> BaseX encoded Encodes a plaintext buffer into the instance's encoding scheme

Instance method: from(src)

  • src: <string> Plaintext string
  • Returns: <string> BaseX encoded Encodes a plaintext string into the instance's encoding scheme

Instance method: from_int(val)

  • val: <number> Plaintext integer
  • Returns: <string> BaseX encoded Encodes a plaintext integer into the instance's encoding scheme

Instance method: to_buff(src)

  • src: <string> BaseX encoded string
  • Returns: <Uint8Array> Buffer Decodes a BaseX encoded string into a buffer

Instance method: to(src)

  • src: <string> BaseX encoded string
  • Returns: <string> Plaintext string Decodes a BaseX encoded string into a plaintext string

Instance method: to_int(src)

  • src: <string> BaseX encoded string
  • Returns: <number> Plaintext integer Decodes a BaseX encoded string into a plaintext number

Instance: Base32

Instance: Base64

Instance: Base64URI

License

Copyright © 2024 Josh Ibad. All rights reserved.

REFER to Ibad.one Commercial & Proprietary License in "LICENSE"