JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 939
  • Score
    100M100P100Q122897F
  • License MIT

Ansi codes for ascii-art

Package Exports

  • ascii-art-ansi

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ascii-art-ansi) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

                   _  _                       _
                  (_)(_)                     | |
  __ _  ___   ___  _  _  ______   __ _  _ __ | |_
 / _` |/ __| / __|| || ||______| / _` || '__|| __|
| (_| |\__ \| (__ | || |        | (_| || |   | |_
 \__,_||___/ \___||_||_|         \__,_||_|    \__|

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');

.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

Param Type Description
ansiString string input string to map across
handler function the 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

Param Type Description
ansiString string input 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

Param Type Description
ansiString string input 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

Param Type Description
ansiString string input 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

Param Type Description
ansiString string input string to measure

Example

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

.trimTo(ansiString)

Trim off the end of the string Kind: static property of ascii-art-ansi

Param Type Description
ansiString string input 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

Param Type Description
inputString(N) string input string to measure
callback function callback 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) [TBD]

Intersect/overlay any number of strings and include their styles Kind: static property of ascii-art-ansi

Param Type Description
inputString(N) string input string to measure
callback function callback 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'
    });

Roadmap

Goals

  • .substring(), .interstyle()

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