Giter VIP home page Giter VIP logo

js-ascii's Introduction

js-ascii

Build Status npm dependencies Status devDependencies Status

(jsAscii) is a JavaScript utility library for serializing and rendering ASCII art in the browser. It takes ASCII art following the format of neofetch's ascii art, and converts it into a processable array.

The rendering engine can be used to render the arrays into various serialized formats, including HTML and most consoles. The library additionally allows the specification of custom output formats via an internal API.

Installing

via npm

npm i -S js-ascii

How to use

Node.js

Require the jsAscii module and use the api as demonstrated below:

const jsAscii = require('js-ascii');

// converts raw string art to a raw JavaScript array implementation
const formattedArt = jsAscii.convert("${c1}Hello ${c2}World");

const colorizedHTML = jsAcii.renderToHTML(formattedArt, {
	// any valid CSS color
	styles: {
		1: 'red',
		2: '#00f',
	},
});
// outputs: <span style="color:red">Hello </span><span style="color:#00f">World</span>

const colorizedConsole = jsAcii.renderToTTY(formattedArt, {
	// specific console color cold (Number) or
	// string name
	styles: {
		1: 'red',
		2: 'blue',
	}
});
// outputs: Hello World
// (colorized version logo for STDOUT/console)

Browser

If using a bundling utility, you can include the module the same way you would include the Node.js api. Otherwise, concatenated dist files can also be loaded in.

Pre-transpiled import (ES5)

If you are using browser modules (or not using babel), an ES5 friendly version can be included like so:

// standard import
import jsAscii from 'js-ascii';
import { convert, renderToHTML } from 'js-ascii';

// named imports (for improved tree shaking)
import convert from 'js-ascii/dist/lib/convert';
import renderToHTML from 'js-ascii/dist/lib/formats/html';

// full dist IFFE (for environments without bundlers)
import 'js-acii/dist/client';

Non-transpiled (ES2015+)

If you are using your own post-process transpiler, you can include the full non-transpiled implementation like so:

// standard import
import jsAscii from 'js-ascii/source';
import { convert, renderToHTML } from 'js-ascii/source';

// named imports (for improved tree shaking)
import convert from 'js-ascii/lib/convert';
import renderToHTML from 'js-ascii/lib/formats/html';

// full dist IFFE (for environments without bundlers)
import 'js-acii/dist/condensed';

API documentation

Coming soon (refer to included inline /lib documentation)

ASCII ART Editor

A simple single-page HTML application has also been included in /editor direactory of this repository.

At the bottom of the page, both of the compiled outputs will be updated as the input field changes (or when a page click occurs). Other useful functionality is shown within the editor itself.

js-ascii's People

Contributors

f1yn avatar

Stargazers

 avatar

Watchers

 avatar

js-ascii's Issues

Issue with RegExp not matching entire word

The regular expression that is intended to match catch the colour codes in a post processed string isn't fully functional. It matches single characters, even outside of the literal. I am looking for a solution.

dataNode.replace(/[^\$\{c\d\}]/g, renderBlock) : dataNode; // ToDO: fixed regex to replace all characters except mentioned pattern

Is returning specific characters (such as 'c' and digits).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.