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

nanbox

v3.0.0

Published

Encode hidden data within NaN IEEE 754 floats

Downloads

14

Readme

Version Tests Coverage Status License

Nan-box

IEEE 754 encodes 32-bit floating points with 1 bit for the sign, 8 bits for the exponent, and 23 bits for the number part (mantissa). For the specific case of NaN (e.g. the result of dividing 0 by 0, or the square root of a negative number), the spec encodes this as 11111111 in the exponent. The sign and the mantissa can be anything, and the spec suggests this can be used for "diagnostic information". One/some of these bits is/are commonly used to indicate a quiet NaN (qNaN) which could be expected vs. a signaling NaN (sNaN) which could be unexpected and should trigger an halting exception. This behavior is however sometimes different on different hardware.

23 bits isn't much space, but conveniently the max size of a Unicode codepoint is 0x10FFFF, making it a 22-bit charset. When you encode your strings in UTF-32, you're only going to be using 22 of those bits, so masking the top portion with the NaN signature makes all of your characters NaNs.

Installation

npm install --save nanbox

Usage

Use the named function toNaN to wrap your clandestine characters in NaNs, and then fromNaN to take them back out.

import { fromNaN, toNaN } from 'nanbox'

const data = '酷'.codePointAt(0)
// => 0x9177
const boxed = toNaN(data)
// => NaN
const unboxed = fromNaN(boxed)
// => 0x9177

You could use this to encode your string as an array of NaNs. There's also the generic default function nanbox, which will detect which way you want to go.

import nanbox from 'nanbox'

const str = '我的氣墊船裝滿了鰻魚'
const arr = str
  .split('')
  .map((c) => c.codePointAt(0))
  .map(nanbox)
// => [ NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN ]
String.fromCodePoint(...arr.map(nanbox))
// => '我的氣墊船裝滿了鰻魚'
  • Note: Usage does not entail useful.
  • Note: Be careful storing or transporting, JSON has no standard way to represent NaN.
  • Note: Sea Otters have evolved a pocket of loose skin under each forearm, which they use to store their favorite rock.

References

  • https://twitter.com/im889/status/1256770029812514817
  • https://anniecherkaev.com/the-secret-life-of-nan
  • https://www.doc.ic.ac.uk/~eedwards/compsys/float/nan.html
  • http://tom7.org/nand/
  • https://stackoverflow.com/questions/27415935/does-unicode-have-a-defined-maximum-number-of-code-points