1.0.4 • Published 7 years ago

ascii-numbers v1.0.4

Weekly downloads
6
License
MIT
Repository
github
Last release
7 years ago

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.

1.0.4

7 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago