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

hexagram-encode

v1.0.0

Published

Represent binary data as I Ching hexagrams

Downloads

15

Readme

hexagram-encode

Convert binary data to a string of I Ching hexagrams and back. Bits in the original data are represented visually as broken or unbroken lines in the resulting hexagram. For example, the binary sequence 0b00000000, 0b01010101, 0b11111111 becomes "䷁䷣䷄䷀".

This is essentially Base64 encoding, replacing alphanumeric characters with different code points which make the original bits visible. Each hexagram represents a single Base64 character (i.e. a binary number from 0 to 63 inclusive), with the most significant bit at the top. With analogy to electronic circuits, a broken line represents 0 and an unbroken line represents 1.

䷁䷗䷆䷒䷎䷣䷭䷊ ䷏䷲䷧䷵䷽䷶䷟䷡ ䷇䷂䷜䷻䷦䷾䷯䷄ ䷬䷐䷮䷹䷞䷰䷛䷪ ䷖䷚䷃䷨䷳䷕䷑䷙ ䷢䷔䷿䷥䷷䷝䷱䷍ ䷓䷩䷺䷼䷴䷤䷸䷈ ䷋䷘䷅䷉䷠䷌䷫䷀

Base64 uses a 65th character for padding; here, we use U+262F YIN YANG, "☯". As with Base64, the presence of "☯" at the end of a hexagram-encoded string means "ignore the lowermost two broken lines in the final hexagram", and the presence of "☯☯" at the end means "ignore the lowermost four broken lines".

Clearly, this has negligible practical use. The resulting string is significantly larger than the original Base64 in UTF-8 (although the same size in UTF-16 or UTF-32), it does not render in most fonts, and the original 8-bit bytes are just as obfuscated by the 6-bit dicing as they are in Base64.

Apologies to those who use these code points for their intended purpose.

Installation

npm install hexagram-encode

Usage

import { encode, decode } from 'hexagram-encode'

const buf = Buffer.from('ABCDEFGH456789+/', 'base64')

const str = encode(buf)
console.log(str) // "䷁䷗䷆䷒䷎䷣䷭䷊䷋䷘䷅䷉䷠䷌䷫䷀"

const buf2 = decode(str)
console.log(buf.equals(buf2)) // true

Notes

I Ching hexagrams appear in Unicode at code points U+4DC0 to U+4DFF inclusive.

Wikipedia presents this image which suggests the yin/yang symbol as "Hexagram 0", but gives no obvious rationale for this. Still, in the absence of a better idea it seemed a reasonable choice of padding character.

Relatively few fonts render I Ching hexagrams; I tend to use Segoe UI Symbol.

I have discovered at least one font which renders I Ching hexagrams incorrectly: Code2000. Compare the renderings of U+4DF4 HEXAGRAM FOR DEVELOPMENT and U+4DF5 HEXAGRAM FOR THE MARRYING MAIDEN in the Unicode chart (correct) and in the Code2000 chart (incorrect). They have been swapped; or, equivalently, flipped upside-down. Unfortunately it seems that Code2000 is no longer under active development, so it is unlikely that this will ever be corrected. This hurts the already-negligible practicality of this encoding.