slice-ansi 4.0.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +9 -7
  2. package/package.json +11 -10
  3. package/readme.md +3 -3
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
- 'use strict';
2
- const isFullwidthCodePoint = require('is-fullwidth-code-point');
3
- const astralRegex = require('astral-regex');
4
- const ansiStyles = require('ansi-styles');
1
+ import isFullwidthCodePoint from 'is-fullwidth-code-point';
2
+ import ansiStyles from 'ansi-styles';
3
+
4
+ const astralRegex = /^[\uD800-\uDBFF][\uDC00-\uDFFF]$/;
5
5
 
6
6
  const ESCAPES = [
7
7
  '\u001B',
@@ -41,6 +41,8 @@ const checkAnsi = (ansiCodes, isEscapes, endAnsiCode) => {
41
41
 
42
42
  if (endAnsiCode !== undefined) {
43
43
  const fistEscapeCode = wrapAnsi(ansiStyles.codes.get(Number.parseInt(endAnsiCode, 10)));
44
+ // TODO: Remove the use of `.reduce` here.
45
+ // eslint-disable-next-line unicorn/no-array-reduce
44
46
  output = output.reduce((current, next) => next === fistEscapeCode ? [next, ...current] : [...current, next], []);
45
47
  }
46
48
  }
@@ -48,7 +50,7 @@ const checkAnsi = (ansiCodes, isEscapes, endAnsiCode) => {
48
50
  return output.join('');
49
51
  };
50
52
 
51
- module.exports = (string, begin, end) => {
53
+ export default function sliceAnsi(string, begin, end) {
52
54
  const characters = [...string];
53
55
  const ansiCodes = [];
54
56
 
@@ -81,7 +83,7 @@ module.exports = (string, begin, end) => {
81
83
  visible++;
82
84
  }
83
85
 
84
- if (!astralRegex({exact: true}).test(character) && isFullwidthCodePoint(character.codePointAt())) {
86
+ if (!astralRegex.test(character) && isFullwidthCodePoint(character.codePointAt())) {
85
87
  visible++;
86
88
 
87
89
  if (typeof end !== 'number') {
@@ -100,4 +102,4 @@ module.exports = (string, begin, end) => {
100
102
  }
101
103
 
102
104
  return output;
103
- };
105
+ }
package/package.json CHANGED
@@ -1,12 +1,14 @@
1
1
  {
2
2
  "name": "slice-ansi",
3
- "version": "4.0.0",
3
+ "version": "5.0.0",
4
4
  "description": "Slice a string with ANSI escape codes",
5
5
  "license": "MIT",
6
6
  "repository": "chalk/slice-ansi",
7
7
  "funding": "https://github.com/chalk/slice-ansi?sponsor=1",
8
+ "type": "module",
9
+ "exports": "./index.js",
8
10
  "engines": {
9
- "node": ">=10"
11
+ "node": ">=12"
10
12
  },
11
13
  "scripts": {
12
14
  "test": "xo && ava"
@@ -38,15 +40,14 @@
38
40
  "text"
39
41
  ],
40
42
  "dependencies": {
41
- "ansi-styles": "^4.0.0",
42
- "astral-regex": "^2.0.0",
43
- "is-fullwidth-code-point": "^3.0.0"
43
+ "ansi-styles": "^6.0.0",
44
+ "is-fullwidth-code-point": "^4.0.0"
44
45
  },
45
46
  "devDependencies": {
46
- "ava": "^2.1.0",
47
- "chalk": "^3.0.0",
48
- "random-item": "^3.0.0",
49
- "strip-ansi": "^6.0.0",
50
- "xo": "^0.26.1"
47
+ "ava": "^3.15.0",
48
+ "chalk": "^4.1.0",
49
+ "random-item": "^4.0.0",
50
+ "strip-ansi": "^7.0.0",
51
+ "xo": "^0.38.2"
51
52
  }
52
53
  }
package/readme.md CHANGED
@@ -1,4 +1,4 @@
1
- # slice-ansi [![Build Status](https://travis-ci.org/chalk/slice-ansi.svg?branch=master)](https://travis-ci.org/chalk/slice-ansi) [![XO: Linted](https://img.shields.io/badge/xo-linted-blue.svg)](https://github.com/xojs/xo)
1
+ # slice-ansi [![XO: Linted](https://img.shields.io/badge/xo-linted-blue.svg)](https://github.com/xojs/xo)
2
2
 
3
3
  > Slice a string with [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles)
4
4
 
@@ -11,8 +11,8 @@ $ npm install slice-ansi
11
11
  ## Usage
12
12
 
13
13
  ```js
14
- const chalk = require('chalk');
15
- const sliceAnsi = require('slice-ansi');
14
+ import chalk from 'chalk';
15
+ import sliceAnsi from 'slice-ansi';
16
16
 
17
17
  const string = 'The quick brown ' + chalk.red('fox jumped over ') +
18
18
  'the lazy ' + chalk.green('dog and then ran away with the unicorn.');