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

@1ky/n64

v1.0.5

Published

Extremely fast number to radix64 converting

Downloads

22

Readme

n64

Extremely fast number to radix64 converting.

NPM versionBuild Status

Features

  • Converts all values of javascript safe integers range (from -9007199254740991 to 9007199254740991)
  • Extremely fast due to bitwise operations
  • Does not add extra padding characters for more efficient compression
  • ES3 compatible

Number | Result -----------------|------------ 0 | A 63 | / 64 | BA 4095 | // 262143 | /// 16777215 | //// 68719476735 | ////// 281474976710655 | //////// 9007199254740991 | f//////// -9007199254740991| -f////////

Installation

npm install https://gitee.com/i8gua/n64.git

API

ntob(number)

Takes a number, discards a fractional part and returns a string.

bton(base64)

Takes a string and returns a number.

Usage

Browser directly

<script src="https://unpkg.com/n64/dist/n64.min.js"></script>

<script>
  var number = -9007199254740991;
  var base64 = numberToBase64.ntob(number);
  var back = numberToBase64.bton(base64);
  console.log('%s -> "%s" -> %s (%s)', number, base64, back, back === number);
</script>

Output

-9007199254740991 -> "-f////////" -> -9007199254740991 (true)

ES6

import { ntob, bton } from 'n64';

const test = (number) => {
  const base64 = ntob(number);
  const back = bton(base64);
  console.log('%s -> "%s" -> %s (%s)', number, base64, back, back === number);
};

[0, 1, -1, 255, 65535, 4294967295, 4294967296, Date.now(), 9007199254740991].forEach(number =>
  test(number)
);

Output

0 -> "A" -> 0 (true)
1 -> "B" -> 1 (true)
-1 -> "-B" -> -1 (true)
255 -> "D/" -> 255 (true)
65535 -> "P//" -> 65535 (true)
4294967295 -> "D/////" -> 4294967295 (true)
4294967296 -> "EAAAAA" -> 4294967296 (true)
1516612803738 -> "WEdKtya" -> 1516612803738 (true)
9007199254740991 -> "f////////" -> 9007199254740991 (true)

Benchmarking

Converting 1 -> "B" -> 1
----------------------------------------------------------------
n64 x 12,522,220 ops/sec ±1.16% (79 runs sampled)
        radix-64 x 5,646,873 ops/sec ±0.53% (90 runs sampled)
         radixer x 9,247,606 ops/sec ±1.01% (88 runs sampled)

Converting -1 -> "-B" -> -1
----------------------------------------------------------------
n64 x 7,085,183 ops/sec ±0.65% (86 runs sampled)
        radix-64 - error
         radixer - error

Converting 255 -> "D/" -> 255
----------------------------------------------------------------
n64 x 7,105,757 ops/sec ±1.04% (86 runs sampled)
        radix-64 x 1,625,993 ops/sec ±0.75% (88 runs sampled)
         radixer x 3,096,584 ops/sec ±1.20% (89 runs sampled)

Converting 65535 -> "P//" -> 65535
----------------------------------------------------------------
n64 x 5,823,782 ops/sec ±1.11% (88 runs sampled)
        radix-64 x 1,394,050 ops/sec ±1.40% (90 runs sampled)
         radixer x 1,998,073 ops/sec ±0.55% (87 runs sampled)

Converting 4294967295 -> "D/////" -> 4294967295
----------------------------------------------------------------
n64 x 3,510,849 ops/sec ±0.52% (88 runs sampled)
        radix-64 x 941,715 ops/sec ±1.35% (91 runs sampled)
         radixer x 1,003,687 ops/sec ±0.54% (91 runs sampled)

Converting 4294967296 -> "EAAAAA" -> 4294967296
----------------------------------------------------------------
n64 x 3,284,146 ops/sec ±1.20% (89 runs sampled)
        radix-64 x 931,296 ops/sec ±2.61% (87 runs sampled)
         radixer x 1,561,844 ops/sec ±1.44% (85 runs sampled)

Converting 1516613323746 -> "WEdMsvi" -> 1516613323746
----------------------------------------------------------------
n64 x 3,041,711 ops/sec ±0.62% (90 runs sampled)
        radix-64 x 866,496 ops/sec ±1.53% (89 runs sampled)
         radixer x 1,143,080 ops/sec ±0.60% (89 runs sampled)

Converting 9007199254740991 -> "f////////" -> 9007199254740991
----------------------------------------------------------------
n64 x 2,490,628 ops/sec ±0.71% (89 runs sampled)
        radix-64 x 721,063 ops/sec ±1.29% (86 runs sampled)
         radixer x 659,930 ops/sec ±0.44% (90 runs sampled)

Converting -9007199254740991 -> "-f////////" -> -9007199254740991
----------------------------------------------------------------
n64 x 2,283,304 ops/sec ±1.07% (90 runs sampled)
        radix-64 - error
         radixer - error