Skip to content

Having trouble manipulating strings with ANSI styles (eg: chalk) or certain Unicode characters? Hammer that nail with an anvil—make an AST out of it!

Notifications You must be signed in to change notification settings

rozzzly/string-ast

Repository files navigation

string-ast

Ever tried to manipulate a string containing weird Unicode characters (emojis, CJK, etc) or the ANSI escape sequences used to make console output colorized? It can be a real pain. This package is my attempt to make that easier. By building a comprehensive AST, it becomes possible to preform declarative operations on ANSI/Unicode strings as if they were just ASCII.


Installation

npm install string-ast

Usage

import parse from 'string-ast';
import chalk from 'chalk';

const str = `normal ${chalk.bold('bold')} ${chalk.red(`red ${chalk.bold('both')}`)}`;
console.log(parse(str));
Prior Art & Resources Used

About

Having trouble manipulating strings with ANSI styles (eg: chalk) or certain Unicode characters? Hammer that nail with an anvil—make an AST out of it!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published