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

hashwork

v1.0.4

Published

Generate a simple ASCII artwork with strings

Downloads

35

Readme

Hashwork

Generate a simple ASCII artwork with strings. :art:

await Hashwork("Hello, World!", {
  wrap: true,
  charset: // ...
});
charset: Hashwork.CHARSET_RAIN
+----------+
| ,,       |
| ,,       |
|, ,  ,    |
|,      , ,|
|   ,     ,|
+----------+
charset: Hashwork.CHARSET_EGGS
+----------+
|_00_______|
|_00_______|
|0_0__0____|
|0______0_0|
|___0_____0|
+----------+

Installation :package:

Install hashwork using npm and import it with require.

npm install hashwork
const Hashwork = require("hashwork");

If you're using vanilla javascript, download the hashwork.js file and import it or use jsdelivr cdn:

<script src="https://cdn.jsdelivr.net/gh/creuserr/hashwork/dist/hashwork.js"></script>

After importing, hashwork will appear on window.Hashwork.

Usage :books:

Hashwork accepts two arguments: the string that generates the artwork, and a configuration object.

await Hashwork(String, Object?);

Example usage:

await Hashwork("Hello, World");
// This will return a list
// of string

Configuration

Configuration is optional and it should be an object.

Algorithm

This configuration changes the hashing algorithm. It is SHA-1 by default.

await Hashwork("Hello, World", {
  algorithm: "SHA-256"
});

Height

This configuration changes the column size. It is 5 by default. Take note that the height is limited depending on the generated hash buffer.

await Hashwork("Hello, World", {
  height: 7
});

Width

This configuration changes the row size. It is 10 by default. Take note that the width is limited depending on the sine result of the hash.

await Hashwork("Hello, World", {
  width: 10
});

Wrap

This configuration allows hashwork to wrap the artwork into a frame. It is not allowed by default.

Without wrap, Hashwork returns a list of string.

On the other hand, using wrap will produce a string like this:

+----------+
|          |
| Artwork  |
| Here     |
|          |
|          |
+----------+

Charset

This configuration changes the characters that makes the artwork. It is Hashwork.CHARSET_DEFAULT by default. Take note that this should be an array of string that has only one character in it.

await Hashwork("Hello, World", {
  charset: ["0", "1"]
});

Built-in Charset :fallen_leaf:

Hashwork has 15 built-in charset that can be accessed through the variable Hashwork.CHARSET_<NAME>.

Default

// Variable
Hashwork.CHARSET_DEFAULT

// List
[" ", " ", " ", ".", "x", "+"]

// Example
`
+----------+
|x.    +.. |
|    x x+. |
|.  .x+ +  |
|.  +..    |
|..     x  |
+----------+
`

Rain

// Variable
Hashwork.CHARSET_RAIN

// List
[" "," "," "," ",","]

// Example
`
+----------+
|,,     ,  |
|    , , , |
|,  ,,     |
|    ,     |
|,,     ,  |
+----------+
`

Eggs

// Variable
Hashwork.CHARSET_EGGS

// List
["_","_","_","_","0"]

// Example
`
+----------+
|00_____0__|
|____0_0_0_|
|0__00_____|
|____0_____|
|00_____0__|
+----------+
`

Pin

// Variable
Hashwork.CHARSET_PIN

// List
["0","1","2","3","4","5","6","7","8","9"]

// Example
`
+----------+
|4910215938|
|6160404591|
|9129452507|
|3215938602|
|9928726480|
+----------+
`

Sea

// Variable
Hashwork.CHARSET_SEA

// List
["~","~","~","≥","~","~","~"]

// Example
`
+----------+
|~~~~~~~~≥~|
|~~~~~~~~~~|
|~~~~~~~~~~|
|≥~~~~≥~~~~|
|~~~~~~~~~~|
+----------+
`

Huh

// Variable
Hashwork.CHARSET_HUH

// List
[" "," "," "," ","?"]

// Example
`
+----------+
|??     ?  |
|    ? ? ? |
|?  ??     |
|    ?     |
|??     ?  |
+----------+
`

WTF

// Variable
Hashwork.CHARSET_WTF

// List
[" "," "," ","!","?"]

// Example
`
+----------+
|??     ?!!|
|    ? ? ? |
|?  ??     |
|!   ?!!   |
|?? !   ?! |
+----------+
`

Emote

// Variable
Hashwork.CHARSET_EMOTE

// List
[" "," "," ",":","(",")"]

// Example
`
+----------+
|(:    ):: |
|    ( (): |
|:  :() )  |
|:  )::    |
|::     (  |
+----------+
`

Glitter

// Variable
Hashwork.CHARSET_GLITTER

// List
[":",":",":",":","."]

// Example
`
+----------+
|..:::::.::|
|::::.:.:.:|
|.::..:::::|
|::::.:::::|
|..:::::.::|
+----------+
`

Morse

// Variable
Hashwork.CHARSET_MORSE

// List
[".","-","/"]

// Example
`
+----------+
|-.-./-/../|
|.-..-.-/.-|
|.-/.-///.-|
|./-/../../|
|..//-/.-/.|
+----------+
`

Note

// Variable
Hashwork.CHARSET_NOTE

// List
["_","_","_","_","_","a","b","c"]

// Example
`
+----------+
|______a___|
|b_b____a__|
|_____a_a_c|
|___a___b__|
|____c_b___|
+----------+
`

Math

// Variable
Hashwork.CHARSET_MATH

// List
["+","-","*","/","="]

// Example
`
+----------+
|==-+*-+=//|
|---+=+=+=-|
|=-*==+*++*|
|/*-+=//-+*|
|==*/**-=/+|
+----------+
`

Hair

// Variable
Hashwork.CHARSET_HAIR

// List
["|","|","|","!"]

// Example
`
+----------+
|||||||||!||
||||||||||||
||||||||||!|
|!||||!|||||
|||||!||||||
+----------+
`

Under the Hood :robot:

This is how the process done to generate the artwork:

  1. Convert the text to a hash (SHA-1 by default) that produces a list of number.
  2. Slice the list by the configuration of height (5 by default).
  3. Map each number, get its sine ratio, use its decimal part, and slice it by the configuration of width (10 by default).
  4. Map each decimal parts, convert it to string, and split kt by characters.
  5. Map each characters, get the character from charset by its number (0-9). Modulo by the length of charset if the number is greater than the length of the list.