slice-ansi
Slice a string with ANSI escape codes
Last updated 6 days ago by sindresorhus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install slice-ansi 
SYNC missed versions from official npm registry.

slice-ansi XO: Linted

Slice a string with ANSI escape codes

Install

npm install slice-ansi

Usage

import chalk from 'chalk';
import sliceAnsi from 'slice-ansi';

const string = 'The quick brown ' + chalk.red('fox jumped over ') +
	'the lazy ' + chalk.green('dog and then ran away with the unicorn.');

console.log(sliceAnsi(string, 20, 30));

API

sliceAnsi(string, startSlice, endSlice?)

string

Type: string

String with ANSI escape codes. Like one styled by chalk.

startSlice

Type: number

Zero-based visible-column index at which to start the slice. Grapheme clusters (for example, emoji sequences and combining marks) are kept intact.

endSlice

Type: number

Zero-based visible-column index at which to end the slice. If a full grapheme cluster would cross endSlice, it is excluded.

Related

  • wrap-ansi - Wordwrap a string with ANSI escape codes
  • cli-truncate - Truncate a string to a specific width in the terminal
  • chalk - Terminal string styling done right

Maintainers

Current Tags

  • 9.0.0                                ...           latest (6 days ago)

16 Versions

  • 9.0.0                                ...           6 days ago
  • 8.0.0                                ...           2 months ago
  • 7.1.2                                ...           7 months ago
  • 7.1.0                                ...           2 years ago
  • 7.0.0                                ...           2 years ago
  • 6.0.0                                ...           3 years ago
  • 5.0.0                                ...           5 years ago
  • 4.0.0                                ...           6 years ago
  • 3.0.0                                ...           7 years ago
  • 2.1.0                                ...           7 years ago
  • 2.0.0                                ...           7 years ago
  • 1.0.0                                ...           9 years ago
  • 0.1.0                                ...           9 years ago
  • 0.0.4                                ...           11 years ago
  • 0.0.3                                ...           11 years ago
  • 0.0.2                                ...           11 years ago
Maintainers (1)
Downloads
Today 0
This Week 176
This Month 247
Last Day 35
Last Week 117
Last Month 717
Dependencies (2)
Dev Dependencies (5)

Copyright 2013 - present © cnpmjs.org | Home |