Skip to content

machaj/ascii-numbers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ascii-numbers

Greenkeeper badge Build Status Coverage Status

a simple lib for converting numbers to ASCII art text.

Usage

import font from 'ascii-numbers/fonts/ANSI_Shadow';
import ASCIINumbers from 'ascii-numbers';

const asciiNumbersWithFont = new ASCIINumbers(font);

console.log(asciiNumbersWithFont.getNumber(123))

/* Output
     ██╗  ██████╗  ██████╗
    ███║  ╚════██╗ ╚════██╗
    ╚██║   █████╔╝  █████╔╝
     ██║  ██╔═══╝   ╚═══██╗
     ██║  ███████╗ ██████╔╝
     ╚═╝  ╚══════╝ ╚═════╝
*/

Options

You can pass second parameter with options to ASCIINumbers constructor.

const config = {
	lineLength: 80,
	minDigits: null,
	space: ''
};

const asciiNumbersWithFont = new ASCIINumbers(font, config);

lineLength defines the maximum usable space for ascii text output. Default is 80 characters.

minDigits defines number alignment. If the printed number has fewer than 'minDigits' digits, then is prefixed by spaces.

...

const asciiNumbersWithFont = new ASCIINumbers(font, { minDigits: 6 });
console.log(asciiNumbersWithFont.getNumber(123))

/* Output
                                ██╗  ██████╗  ██████╗
                               ███║  ╚════██╗ ╚════██╗
                               ╚██║   █████╔╝  █████╔╝
                                ██║  ██╔═══╝   ╚═══██╗
                                ██║  ███████╗ ██████╔╝
                                ╚═╝  ╚══════╝ ╚═════╝
*/

space defines separator between digits.

...

const asciiNumbersWithFont = new ASCIINumbers(font, { space: '***' });
console.log(asciiNumbersWithFont.getNumber(123))

/* Output
     ██╗ *** ██████╗ *** ██████╗
    ███║ *** ╚════██╗*** ╚════██╗
    ╚██║ ***  █████╔╝***  █████╔╝
     ██║ *** ██╔═══╝ ***  ╚═══██╗
     ██║ *** ███████╗*** ██████╔╝
     ╚═╝ *** ╚══════╝*** ╚═════╝
*/

Fonts

This lib use ANSI Shadow font from figlet, but you can simply create your own font. Check ANSI_Shadow.js for font structure.

About

Convert numbers to ASCI art text

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •