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 🙏

© 2024 – Pkg Stats / Ryan Hefner

radix-64

v1.0.4

Published

Fast and efficient number conversion library for arbitrary radix 64 alphabets.

Downloads

1,633

Readme

Description


Fast and efficient integer conversion library for arbitrary radix 64 alphabets designed. Allows you to convert any size integer to and from any 64 radix alphabet. Has options to format strings so that they are lexicographically sortable. This library was designed for ID generation.

Note: While similar radix64 is not the same as base64.

base64 is for converting binary data and so starts converting from the most significant byte to least. radix64 is for converting integers from base 10 to base 64 and so starts converting with the least significant byte to most.

With radix64 you can generate encoded strings of any length whereas base64 must always have encoded strings with a length that is a multiple of 4. Therefore radix64 doesn't need padding characters and can more efficiently represent the bits.

Example

Decimal | Radix64 | Base64 ------|------|------- 0 |- |AA== 1 |0 |AQ==
2 |1 |Ag==
4 |3 |BA==
8 |7 |CA==
16 |F |EA==
32 |V |IA==
64 |0- |QA==
128 |1- |gA==
256 |3- |AQA=
512 |7- |AgA= 1024 |F- |BAA= 2048 |V- |CAA= 4096 |0-- |EAA=

radix64.encodeBuffer(buffer[, length])

Encodes a buffer into a radix 64 string.

  • buffer - binary buffer
  • length [Optional] - Length of the desired encoded string. If not specified uses the minimum length needed to encode the buffer.

radix64.encodeInt(integer[, length])

Encodes an integer into a radix 64 string.

  • integer - Javascript integer
  • length [Optional] - Length of the desired encoded string. If not specified uses the minimum length needed to encode the integer.

radix64.decodeToInt(string[, bytes])

Decodes a radix 64 string to a buffer

  • string - radix 64 string
  • bytes [Optional] - Int of bytes of the desired decoded buffer. If not specified uses the minimum bytes needed to decode the string.

radix64.decodeToBuffer(string)

Decodes a radix 64 string to an integer

  • string - radix 64 string

var encoded = radix64.encodeInt(1234567890); console.log('%s', encoded); // 08_VAH

var encodedLexicographically = radix64.encodeInt(1234567890, 10); console.log('%s', encodedLexicographically); // ----08_VAH


<br>
### More integer precision
JavaScript numbers only have **53** bits of integer precision. To convert larger integers with more precision use encodeBuffer(). It takesany size buffers in Big Endian format. It is also compatible with bignum and bigint libraries.
```js
var radix64 = require('radix-64')();

var num = bignum.pow(2, 63);
var encoded = radix64.encodeBuffer(num.toBuffer());

var decoded = radix64.decodeToBuffer(encoded);
var decodedNum = bignum.fromBuffer(decoded);

Function | Time (Milliseconds) --------------------------------|---- radix64.encodeBuffer(buffer) |207 radix64.decodeToBuffer(string) |506 buffer.toString('base64') |254 new Buffer(string, 'base64') |1314 radix64.encodeInt(int) |1295 radix64.decodeToInt(string) |137