Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ascii-art-ansi

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ascii-art-ansi

Ansi codes for ascii-art

  • 1.4.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
593
decreased by-51.07%
Maintainers
1
Weekly downloads
 
Created
Source
                   _  _                       _
                  (_)(_)                     | |
  __ _  ___   ___  _  _  ______   __ _  _ __ | |_
 / _` |/ __| / __|| || ||______| / _` || '__|| __|
| (_| |\__ \| (__ | || |        | (_| || |   | |_
 \__,_||___/ \___||_||_|         \__,_||_|    \__|

ascii-art-ansi.js

NPM version npm Travis

This module allows you to work with ansi strings in a style aware way, so you aren't constantly doing string manipulation and scanning when working with terminal strings. It offers a clean abstraction to build ascii-art utilities on top of.

Installation

npm install ascii-art-ansi

Usage

require('ascii-art-ansii')

To do anything with it, you'll need to include the library:

    const ansi = require('ascii-art-ansi');
    const color = require('ascii-art-ansi/color');

.map(ansiString, handler)

Map through an ansi string one character at a time, without any of those characters being styles.

Kind: static property of ascii-art-ansi

ParamTypeDescription
ansiStringstringinput string to map across
handlerfunctionthe function to map through the string

Example

    var result = ansi.map(
        ansiString,
        function(chr, codes, rowcol, pos, shortcircuit){
            // chr : the character
            // codes : a list of the active ansi codes as strings
            // rowcol: array of the 2D position of chr in a multiline string
            // pos : the position of the character
            // shortcircuit : function which stops processing after return
        }
    );

.length(ansiString)

The number of non ansi code characters in the string

Kind: static property of ascii-art-ansi

ParamTypeDescription
ansiStringstringinput string to measure

Example

    var result = ansi.length(ansiString);

.strip(ansiString)

Remove any ansi codes from the string

Kind: static property of ascii-art-ansi

ParamTypeDescription
ansiStringstringinput string to measure

Example

    var result = ansi.strip(ansiString);

.length(ansiString)

convert this string to an array of characters

Kind: static property of ascii-art-ansi

ParamTypeDescription
ansiStringstringinput string to measure

Example

    var result = ansi.toArray(ansiString);

.charAt(ansiString)

Extract a specific character from the string, by position Kind: static property of ascii-art-ansi

ParamTypeDescription
ansiStringstringinput string to measure

Example

    var chr = ansi.charAt(ansiString, 4);

.substring(ansiString, start, stop)

Like the javascript built-in substring, but ansi aware

Kind: static property of ascii-art-ansi

ParamTypeDescription
ansiStringstringinput string to measure

Example

    var chr = ansi.trimTo(ansiString, 4);

.intersect(ansiString)

Intersect/overlay any number of strings

Kind: static property of ascii-art-ansi

ParamTypeDescription
inputString(N)stringinput string to measure
callbackfunctioncallback to handle asynchronous return, if omitted, a promise is returned

Example

    var chr = ansi.intersect(s1, s2, s3, function(err, result){
        // ['A  ', ' B ', '  C'] -> 'ABC'
    });

.interstyle(ansiString)

Intersect/overlay any number of strings and include their styles

Kind: static property of ascii-art-ansi

ParamTypeDescription
inputString(N)stringinput string to measure
callbackfunctioncallback to handle asynchronous return, if omitted, a promise is returned

Example

    var chr = ansi.interstyle(s1, s2, s3, function(err, result){
        // ['A  ', ' B ', '  C'] -> 'ABC'
    });

.Color(options)

Intersect/overlay any number of strings and include their styles

Kind: static property of ascii-art-ansi

ParamTypeDescription
optionsObjectoptions

Example

    var color = new Color('#FFFFFF')

.Color.code(value)

Compute the code for the given hex color (closest within the active palette)

Kind: static property of ascii-art-ansi/color

ParamTypeDescription
valuestringthe hex value color of the color

Example

    var ansiCode = Color.code('#FF0000');

.Color.name(value)

Compute the code for the given named color (closest within the active palette)

Kind: static property of ascii-art-ansi/color

ParamTypeDescription
valuestringthe name of the color

Example

    var ansiCode = Color.name('red');

.Color.is256

If set colors will be computed using 256 colors instead of 16. Colors are averaged according to a color averaging scheme which can be changed with Color.useDistance(name); where name is one of euclideanDistance, classic, ratioDistance, classicByValue, CIE76Difference, closestByIntensity, rankedChannel, simple, original

Kind: static property of ascii-art-ansi/color

Example

    Color.is256 = true;

.Color.isTrueColor

If set colors will be computed using millions of colors

Kind: static property of ascii-art-ansi/color

Example

    Color.isTrueColor = true;

Roadmap

Goals
  • color reducer
  • streaming
  • pluggable colorsets/encodings

Testing

In the root directory run:

npm run test

Please make sure to run the tests before submitting a patch and report any rough edges. Thanks!

Enjoy,

-Abbey Hawk Sparrow

Keywords

FAQs

Package last updated on 29 Jun 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc