Skip to content

Commit

Permalink
Require Node.js 12 and move to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Apr 16, 2021
1 parent d08a774 commit 4481b21
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/funding.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github: [sindresorhus,Qix-]
github: [sindresorhus, Qix-]
tidelift: npm/wrap-ansi
3 changes: 1 addition & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ jobs:
node-version:
- 14
- 12
- 10
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
Expand Down
20 changes: 9 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
'use strict';
const stringWidth = require('string-width');
const stripAnsi = require('strip-ansi');
const ansiStyles = require('ansi-styles');
import stringWidth from 'string-width';
import stripAnsi from 'strip-ansi';
import ansiStyles from 'ansi-styles';

const ESCAPES = new Set([
'\u001B',
'\u009B'
]);

const END_CODE = 39;

const ANSI_ESCAPE_BELL = '\u0007';
const ANSI_CSI = '[';
const ANSI_OSC = ']';
const ANSI_SGR_TERMINATOR = 'm';
const ANSI_ESCAPE_LINK = `${ANSI_OSC}8;;`;

const wrapAnsi = code => `${ESCAPES.values().next().value}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
const wrapAnsiCode = code => `${ESCAPES.values().next().value}${ANSI_CSI}${code}${ANSI_SGR_TERMINATOR}`;
const wrapAnsiHyperlink = uri => `${ESCAPES.values().next().value}${ANSI_ESCAPE_LINK}${uri}${ANSI_ESCAPE_BELL}`;

// Calculate the length of words split on ' ', ignoring
Expand Down Expand Up @@ -163,7 +161,7 @@ const exec = (string, columns, options = {}) => {
}

if (options.trim !== false) {
rows = rows.map(stringVisibleTrimSpacesRight);
rows = rows.map(row => stringVisibleTrimSpacesRight(row));
}

const pre = [...rows.join('\n')];
Expand All @@ -189,11 +187,11 @@ const exec = (string, columns, options = {}) => {
}

if (escapeCode && code) {
returnValue += wrapAnsi(code);
returnValue += wrapAnsiCode(code);
}
} else if (character === '\n') {
if (escapeCode && code) {
returnValue += wrapAnsi(escapeCode);
returnValue += wrapAnsiCode(escapeCode);
}

if (escapeUrl) {
Expand All @@ -206,11 +204,11 @@ const exec = (string, columns, options = {}) => {
};

// For each newline, invoke the method separately
module.exports = (string, columns, options) => {
export default function wrapAnsi(string, columns, options) {
return String(string)
.normalize()
.replace(/\r\n/g, '\n')
.split('\n')
.map(line => exec(line, columns, options))
.join('\n');
};
}
22 changes: 12 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
"email": "sindresorhus@gmail.com",
"url": "https://sindresorhus.com"
},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=10"
"node": ">=12"
},
"scripts": {
"test": "xo && nyc ava"
Expand Down Expand Up @@ -47,16 +49,16 @@
"text"
],
"dependencies": {
"ansi-styles": "^4.0.0",
"string-width": "^4.1.0",
"strip-ansi": "^6.0.0"
"ansi-styles": "^6.0.0",
"string-width": "^5.0.0",
"strip-ansi": "^7.0.0"
},
"devDependencies": {
"ava": "^2.1.0",
"chalk": "^4.0.0",
"coveralls": "^3.0.3",
"has-ansi": "^4.0.0",
"nyc": "^15.0.1",
"xo": "^0.29.1"
"ava": "^3.15.0",
"chalk": "^4.1.0",
"coveralls": "^3.1.0",
"has-ansi": "^5.0.0",
"nyc": "^15.1.0",
"xo": "^0.38.2"
}
}
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ $ npm install wrap-ansi
## Usage

```js
const chalk = require('chalk');
const wrapAnsi = require('wrap-ansi');
import chalk from 'chalk';
import wrapAnsi from 'wrap-ansi';

const input = 'The quick brown ' + chalk.red('fox jumped over ') +
'the lazy ' + chalk.green('dog and then ran away with the unicorn.');
Expand Down
3 changes: 1 addition & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import test from 'ava';
import chalk from 'chalk';
import hasAnsi from 'has-ansi';
import stripAnsi from 'strip-ansi';
import wrapAnsi from '.';
import wrapAnsi from './index.js';

chalk.enabled = true;
chalk.level = 1;

// When "hard" is false
Expand Down

0 comments on commit 4481b21

Please sign in to comment.