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

@frostoven/randomart

v1.3.2

Published

OpenSSH randomart images library in JS, now with CLI!

Downloads

11

Readme

randomart-generator

Generate OpenSSH style "randomart" images based on any data.

This project was originally based on a cli port of slapresta's work by therebelrobot. The original code was based on calmh/randomart, a randomart library written in Go. This project adds additional functionality.

All features:

  • Generate ASCII art from data such as cryptographic keys or other data.
  • Generate bitmaps images instead.
  • Optionally get raw data instead of conversion to visual data.
  • Override ASCII symbols for custom ASCII output.
  • Supports the browser (via bundling) and Node.js.

Installation

npm install @frostoven/randomart

Documentation

The function returned by require('@frostoven/randomart') optionally accepts two arguments: the first one, data, is expected to be an array of integers between 0 and 255, while the second one, options, has the following structure, in which all parent elements are optional.

Basic usage

Example:

const randomart = require('@frostoven/randomart')

console.log(randomart([
  0x9b, 0x4c, 0x7b, 0xce, 0x7a, 0xbd, 0x0a, 0x13,
  0x61, 0xfb, 0x17, 0xc2, 0x06, 0x12, 0x0c, 0xed,
]))

Result:

    .+.
      o.
     .. +
      Eo =
        S + .
       o B . .
        B o..
         *...
        .o+...

Overriding ASCII symbols

const randomart = require('@frostoven/randomart')

const options = {
  bounds: {
    width: 17,
    height: 9,
  },
  symbols: {
    '-2': 'E', // End
    '-1': 'S', // Start
    '0': ' ',
    '1': '.',
    // [...]
    '13': '/',
    '14': '^',
  },
  // This is false by default, set to true to get raw data instead of text.
  getRawData: false,
}

const randomartString = randomart(
  [/* your byte array */],
  options,
)

Generating a bitmap instead of text

Example:

const randomart = require('@frostoven/randomart')

const options = {
  bounds: {
    width: 48,
    height: 48,
  },
  asBitmap: true,
  darkMode: false,
}

const buffer = randomart(
  [/* 4096-bit RSA key */],
  options,
)
// If saving the image from Node.js
// ================================

const fs = require('fs')
const randomart = require('@frostoven/randomart')

const buffer = randomart(/* your options with `asBitmap: true` */)
fs.writeFile('/tmp/your_image.bmp', buffer, console.log)
// Generating an image inside from a browser
// =========================================

import randomart from '@frostoven/randomart'

function arrayBufferToString (ab) {
  // https://stackoverflow.com/questions/39725716/how-to-convert-javascript-array-to-binary-data-and-back-for-websocket
  return new Uint8Array(ab).reduce((p, c) => p + String.fromCharCode(c), '')
}

const buffer = randomart(/* your options with `asBitmap: true` */)
const data = `data:image/bmp;base64,${window.btoa(arrayBufferToString(buffer))}`

const img = document.getElementById('your-image')
img.src = data

Light mode example results:

Dark mode example results:

Credits

Thanks to @calmh for their hard work! May the opensource gods reward them with seventy-two non-terrible window managers.