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

allbases

v0.4.1

Published

Transform values of abritrary size to an arbritrary base

Downloads

19

Readme

allbases

Build Status npm version

Sauce Test Status

Allow safe transformations on arbitrary bases with inputs of arbitrary length.

Getting Started

var allbases = require("allbases");

var num = new allbases.BigNumber("90813095330284320");
var hex = allbases.encode(num); //142a207701d8320
console.log(allbases.decode(hex)); //90813095330284320
var b62 = allbases.encodeBase62(num); //6HVlt7fNpS
console.log(allbases.decode(b62)); //90813095330284320

var randHex = allbases.random(32); //ce82f9fbf8d7d7d4ce05815e5632e32d
var randBase62 = allbases.randomBase62(10); //SrfxoMwKqQ

Why?

There are a few other projects in node that deal with encoding and decoding of numbers into different representations (octal, hex, base 64, etc.). However all the major libraries in use rely upon regular javascript integers to for these transformations. While this works fine for data that can reliably fit within a Number it becomes a problem when dealing with much larger values.

Therefor the goal of this library is to allow arbritrary base transformations, using arbritrary groups of characters, with an arbritrary level of precision.

Known Limitations

In order to calculate the bits needed for a random number we use Math.pow to generate combos of values as a floating point and then Math.log to get number of bits. This will break as soon as combo hits the largest number that Math.pow can handle. For a base62 value this will happen after 171 characters. Current implemntation will detect when combos has exhausted floating point maximum and throw an appropriate error during random number generation.

The cause of limitation is we are using Math.log, which the big.js library has no equivalent function for. We must use some numerical method that will allow use to calculate log's for arbritrary large numbers, or find another way to estimate number of random bits needed. Whatever method used does not need to be exact but must be computationally practical.

Note: Another Idea I'm just documenting here. We can use big.js to get the true number of combos, then we can detect if it will overflow JS Number and break it down to calculate number of bits until we reach a number less then Number.MAX_VALUE.

TODO

  • Add all major encodings.
  • Allow ignoring of case (i.e. to handle uppercase and lowercae hex).
  • Create new object for random generation, will allow optimization so we don't perform duplicate operations when not needed.
  • Probably need to add opts param to tweak things in encode & decode
  • Other style/performance optimizations documented in code.
  • emphasize must use allbases.bignum or will get type errors.