[Pkg-javascript-commits] [node-wrap-ansi] 01/03: New upstream version 3.0.1

Paolo Greppi paolog-guest at moszumanska.debian.org
Tue Sep 19 04:49:17 UTC 2017


This is an automated email from the git hooks/post-receive script.

paolog-guest pushed a commit to branch master
in repository node-wrap-ansi.

commit 0319def219c011089cb8fde060a0fdd7dcdfe218
Author: Paolo Greppi <paolo.greppi at libpf.com>
Date:   Tue Sep 19 06:11:20 2017 +0200

    New upstream version 3.0.1
---
 .editorconfig  |   2 +-
 .gitattributes |   1 +
 .gitignore     |   1 +
 .npmrc         |   1 +
 .travis.yml    |   3 +-
 index.js       | 229 ++++++++++++++++++++++++++++++++-------------------------
 license        |  20 +----
 package.json   |  26 +++----
 readme.md      |  22 +++++-
 test.js        |  79 ++++++++++++--------
 10 files changed, 216 insertions(+), 168 deletions(-)

diff --git a/.editorconfig b/.editorconfig
index 98a761d..1c6314a 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -7,6 +7,6 @@ charset = utf-8
 trim_trailing_whitespace = true
 insert_final_newline = true
 
-[{package.json,*.yml}]
+[*.yml]
 indent_style = space
 indent_size = 2
diff --git a/.gitattributes b/.gitattributes
index 176a458..391f0a4 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1 +1,2 @@
 * text=auto
+*.js text eol=lf
diff --git a/.gitignore b/.gitignore
index c9106a7..748ccb6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
 node_modules
+yarn.lock
 .nyc_output
diff --git a/.npmrc b/.npmrc
new file mode 100644
index 0000000..43c97e7
--- /dev/null
+++ b/.npmrc
@@ -0,0 +1 @@
+package-lock=false
diff --git a/.travis.yml b/.travis.yml
index be8a96a..ea5900d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,5 +1,6 @@
 language: node_js
 node_js:
+  - '8'
+  - '6'
   - '4'
-  - 'node'
 after_success: npm run coveralls
diff --git a/index.js b/index.js
index ff62543..d2ae454 100755
--- a/index.js
+++ b/index.js
@@ -1,68 +1,71 @@
 'use strict';
-var stringWidth = require('string-width');
-var stripAnsi = require('strip-ansi');
-
-var ESCAPES = [
-	'\u001b',
-	'\u009b'
-];
-
-var END_CODE = 39;
-
-var ESCAPE_CODES = {
-	0: 0,
-	1: 22,
-	2: 22,
-	3: 23,
-	4: 24,
-	7: 27,
-	8: 28,
-	9: 29,
-	30: 39,
-	31: 39,
-	32: 39,
-	33: 39,
-	34: 39,
-	35: 39,
-	36: 39,
-	37: 39,
-	90: 39,
-	40: 49,
-	41: 49,
-	42: 49,
-	43: 49,
-	44: 49,
-	45: 49,
-	46: 49,
-	47: 49
-};
-
-function wrapAnsi(code) {
-	return ESCAPES[0] + '[' + code + 'm';
-}
-
-// calculate the length of words split on ' ', ignoring
-// the extra characters added by ansi escape codes.
-function wordLengths(str) {
-	return str.split(' ').map(function (s) {
-		return stringWidth(s);
-	});
-}
-
-// wrap a long word across multiple rows.
-// ansi escape codes do not count towards length.
-function wrapWord(rows, word, cols) {
-	var insideEscape = false;
-	var visible = stripAnsi(rows[rows.length - 1]).length;
-
-	for (var i = 0; i < word.length; i++) {
-		var x = word[i];
-
-		rows[rows.length - 1] += x;
+const stringWidth = require('string-width');
+const stripAnsi = require('strip-ansi');
+
+const ESCAPES = new Set([
+	'\u001B',
+	'\u009B'
+]);
+
+const END_CODE = 39;
+
+const ESCAPE_CODES = new Map([
+	[0, 0],
+	[1, 22],
+	[2, 22],
+	[3, 23],
+	[4, 24],
+	[7, 27],
+	[8, 28],
+	[9, 29],
+	[30, 39],
+	[31, 39],
+	[32, 39],
+	[33, 39],
+	[34, 39],
+	[35, 39],
+	[36, 39],
+	[37, 39],
+	[90, 39],
+	[40, 49],
+	[41, 49],
+	[42, 49],
+	[43, 49],
+	[44, 49],
+	[45, 49],
+	[46, 49],
+	[47, 49]
+]);
+
+const wrapAnsi = code => `${ESCAPES.values().next().value}[${code}m`;
+
+// Calculate the length of words split on ' ', ignoring
+// the extra characters added by ansi escape codes
+const wordLengths = str => str.split(' ').map(s => stringWidth(s));
+
+// Wrap a long word across multiple rows
+// Ansi escape codes do not count towards length
+const wrapWord = (rows, word, cols) => {
+	const arr = Array.from(word);
+
+	let insideEscape = false;
+	let visible = stringWidth(stripAnsi(rows[rows.length - 1]));
+
+	for (const item of arr.entries()) {
+		const i = item[0];
+		const char = item[1];
+		const charLength = stringWidth(char);
+
+		if (visible + charLength <= cols) {
+			rows[rows.length - 1] += char;
+		} else {
+			rows.push(char);
+			visible = 0;
+		}
 
-		if (ESCAPES.indexOf(x) !== -1) {
+		if (ESCAPES.has(char)) {
 			insideEscape = true;
-		} else if (insideEscape && x === 'm') {
+		} else if (insideEscape && char === 'm') {
 			insideEscape = false;
 			continue;
 		}
@@ -71,49 +74,63 @@ function wrapWord(rows, word, cols) {
 			continue;
 		}
 
-		visible++;
+		visible += charLength;
 
-		if (visible >= cols && i < word.length - 1) {
+		if (visible === cols && i < arr.length - 1) {
 			rows.push('');
 			visible = 0;
 		}
 	}
 
-	// it's possible that the last row we copy over is only
-	// ansi escape characters, handle this edge-case.
+	// It's possible that the last row we copy over is only
+	// ansi escape characters, handle this edge-case
 	if (!visible && rows[rows.length - 1].length > 0 && rows.length > 1) {
 		rows[rows.length - 2] += rows.pop();
 	}
-}
+};
 
-// the wrap-ansi module can be invoked
-// in either 'hard' or 'soft' wrap mode.
+// The wrap-ansi module can be invoked
+// in either 'hard' or 'soft' wrap mode
 //
 // 'hard' will never allow a string to take up more
-// than cols characters.
+// than cols characters
 //
-// 'soft' allows long words to expand past the column length.
-function exec(str, cols, opts) {
-	var options = opts || {};
+// 'soft' allows long words to expand past the column length
+const exec = (str, cols, opts) => {
+	const options = opts || {};
+
+	if (str.trim() === '') {
+		return options.trim === false ? str : str.trim();
+	}
 
-	var pre = '';
-	var ret = '';
-	var escapeCode;
+	let pre = '';
+	let ret = '';
+	let escapeCode;
 
-	var lengths = wordLengths(str);
-	var words = str.split(' ');
-	var rows = [''];
+	const lengths = wordLengths(str);
+	const words = str.split(' ');
+	const rows = [''];
 
-	for (var i = 0, word; (word = words[i]) !== undefined; i++) {
-		var rowLength = stringWidth(rows[rows.length - 1]);
+	for (const item of Array.from(words).entries()) {
+		const i = item[0];
+		const word = item[1];
+
+		rows[rows.length - 1] = options.trim === false ? rows[rows.length - 1] : rows[rows.length - 1].trim();
+		let rowLength = stringWidth(rows[rows.length - 1]);
+
+		if (rowLength || word === '') {
+			if (rowLength === cols && options.wordWrap === false) {
+				// If we start with a new word but the current row length equals the length of the columns, add a new row
+				rows.push('');
+				rowLength = 0;
+			}
 
-		if (rowLength) {
 			rows[rows.length - 1] += ' ';
 			rowLength++;
 		}
 
-		// in 'hard' wrap mode, the length of a line is
-		// never allowed to extend past 'cols'.
+		// In 'hard' wrap mode, the length of a line is
+		// never allowed to extend past 'cols'
 		if (lengths[i] > cols && options.hard) {
 			if (rowLength) {
 				rows.push('');
@@ -131,38 +148,46 @@ function exec(str, cols, opts) {
 			rows.push('');
 		}
 
+		if (rowLength + lengths[i] > cols && options.wordWrap === false) {
+			wrapWord(rows, word, cols);
+			continue;
+		}
+
 		rows[rows.length - 1] += word;
 	}
 
-	pre = rows.map(function (r) {
-		return r.trim();
-	}).join('\n');
+	pre = rows.map(r => options.trim === false ? r : r.trim()).join('\n');
 
-	for (var j = 0; j < pre.length; j++) {
-		var y = pre[j];
+	for (const item of Array.from(pre).entries()) {
+		const i = item[0];
+		const char = item[1];
 
-		ret += y;
+		ret += char;
 
-		if (ESCAPES.indexOf(y) !== -1) {
-			var code = parseFloat(/[0-9][^m]*/.exec(pre.slice(j, j + 4)));
+		if (ESCAPES.has(char)) {
+			const code = parseFloat(/\d[^m]*/.exec(pre.slice(i, i + 4)));
 			escapeCode = code === END_CODE ? null : code;
 		}
 
-		if (escapeCode && ESCAPE_CODES[escapeCode]) {
-			if (pre[j + 1] === '\n') {
-				ret += wrapAnsi(ESCAPE_CODES[escapeCode]);
-			} else if (y === '\n') {
+		const code = ESCAPE_CODES.get(Number(escapeCode));
+
+		if (escapeCode && code) {
+			if (pre[i + 1] === '\n') {
+				ret += wrapAnsi(code);
+			} else if (char === '\n') {
 				ret += wrapAnsi(escapeCode);
 			}
 		}
 	}
 
 	return ret;
-}
+};
 
-// for each line break, invoke the method separately.
-module.exports = function (str, cols, opts) {
-	return String(str).split('\n').map(function (substr) {
-		return exec(substr, cols, opts);
-	}).join('\n');
+// For each newline, invoke the method separately
+module.exports = (str, cols, opts) => {
+	return String(str)
+		.normalize()
+		.split('\n')
+		.map(line => exec(line, cols, opts))
+		.join('\n');
 };
diff --git a/license b/license
index 654d0bf..e7af2f7 100644
--- a/license
+++ b/license
@@ -1,21 +1,9 @@
-The MIT License (MIT)
+MIT License
 
 Copyright (c) Sindre Sorhus <sindresorhus at gmail.com> (sindresorhus.com)
 
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/package.json b/package.json
index 35754d4..79e8b3a 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "wrap-ansi",
-  "version": "2.1.0",
+  "version": "3.0.1",
   "description": "Wordwrap a string with ANSI escape codes",
   "license": "MIT",
   "repository": "chalk/wrap-ansi",
@@ -9,14 +9,8 @@
     "email": "sindresorhus at gmail.com",
     "url": "sindresorhus.com"
   },
-  "maintainers": [
-    "Sindre Sorhus <sindresorhus at gmail.com> (sindresorhus.com)",
-    "Joshua Appelman <jappelman at xebia.com> (jbnicolai.com)",
-    "JD Ballard <i.am.qix at gmail.com> (github.com/qix-)",
-    "Benjamin Coe <ben at npmjs.com> (github.com/bcoe)"
-  ],
   "engines": {
-    "node": ">=0.10.0"
+    "node": ">=4"
   },
   "scripts": {
     "test": "xo && nyc ava",
@@ -53,16 +47,16 @@
     "text"
   ],
   "dependencies": {
-    "string-width": "^1.0.1",
-    "strip-ansi": "^3.0.1"
+    "string-width": "^2.1.1",
+    "strip-ansi": "^4.0.0"
   },
   "devDependencies": {
-    "ava": "^0.16.0",
-    "chalk": "^1.1.0",
+    "ava": "^0.21.0",
+    "chalk": "^2.0.1",
     "coveralls": "^2.11.4",
-    "has-ansi": "^2.0.0",
-    "nyc": "^6.2.1",
-    "strip-ansi": "^3.0.0",
-    "xo": "*"
+    "has-ansi": "^3.0.0",
+    "nyc": "^11.0.3",
+    "strip-ansi": "^4.0.0",
+    "xo": "^0.18.2"
   }
 }
diff --git a/readme.md b/readme.md
index 59fc96b..2982e5a 100644
--- a/readme.md
+++ b/readme.md
@@ -1,12 +1,12 @@
 # wrap-ansi [![Build Status](https://travis-ci.org/chalk/wrap-ansi.svg?branch=master)](https://travis-ci.org/chalk/wrap-ansi) [![Coverage Status](https://coveralls.io/repos/github/chalk/wrap-ansi/badge.svg?branch=master)](https://coveralls.io/github/chalk/wrap-ansi?branch=master)
 
-> Wordwrap a string with [ANSI escape codes](http://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles)
+> Wordwrap a string with [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles)
 
 
 ## Install
 
 ```
-$ npm install --save wrap-ansi
+$ npm install wrap-ansi
 ```
 
 
@@ -45,6 +45,8 @@ Number of columns to wrap the text to.
 
 #### options
 
+Type: `Object`
+
 ##### hard
 
 Type: `boolean`<br>
@@ -59,6 +61,13 @@ Default: `true`
 
 By default, an attempt is made to split words at spaces, ensuring that they don't extend past the configured columns. If wordWrap is `false`, each column will instead be completely filled splitting words as necessary.
 
+##### trim
+
+Type: `boolean`<br>
+Default: `true`
+
+Whitespace on all lines is removed by default. Set this option to `false` if you don't want to trim.
+
 
 ## Related
 
@@ -68,6 +77,13 @@ By default, an attempt is made to split words at spaces, ensuring that they don'
 - [jsesc](https://github.com/mathiasbynens/jsesc) - Generate ASCII-only output from Unicode strings. Useful for creating test fixtures.
 
 
+## Maintainers
+
+- [Sindre Sorhus](https://github.com/sindresorhus)
+- [Josh Junon](https://github.com/qix-)
+- [Benjamin Coe](https://github.com/bcoe)
+
+
 ## License
 
-MIT © [Sindre Sorhus](https://sindresorhus.com)
+MIT
diff --git a/test.js b/test.js
index da07db3..28b71f9 100755
--- a/test.js
+++ b/test.js
@@ -2,39 +2,41 @@ import test from 'ava';
 import chalk from 'chalk';
 import hasAnsi from 'has-ansi';
 import stripAnsi from 'strip-ansi';
-import fn from './';
+import m from '.';
 
-// when "hard" is false
+chalk.enabled = true;
+
+// When "hard" is false
 
 const fixture = 'The quick brown ' + chalk.red('fox jumped over ') + 'the lazy ' + chalk.green('dog and then ran away with the unicorn.');
 const fixture2 = '12345678\n901234567890';
 const fixture3 = '12345678\n901234567890 12345';
+const fixture4 = '12345678\n';
+const fixture5 = '12345678\n ';
 
 test('wraps string at 20 characters', t => {
-	const res20 = fn(fixture, 20);
+	const res20 = m(fixture, 20);
 
-	t.is(res20, 'The quick brown \u001b[31mfox\u001b[39m\n\u001b[31mjumped over \u001b[39mthe lazy\n\u001b[32mdog and then ran\u001b[39m\n\u001b[32maway with the\u001b[39m\n\u001b[32municorn.\u001b[39m');
+	t.is(res20, 'The quick brown \u001B[31mfox\u001B[39m\n\u001B[31mjumped over \u001B[39mthe lazy\n\u001B[32mdog and then ran\u001B[39m\n\u001B[32maway with the\u001B[39m\n\u001B[32municorn.\u001B[39m');
 	t.true(stripAnsi(res20).split('\n').every(x => x.length <= 20));
 });
 
 test('wraps string at 30 characters', t => {
-	const res30 = fn(fixture, 30);
+	const res30 = m(fixture, 30);
 
-	t.is(res30, 'The quick brown \u001b[31mfox jumped\u001b[39m\n\u001b[31mover \u001b[39mthe lazy \u001b[32mdog and then ran\u001b[39m\n\u001b[32maway with the unicorn.\u001b[39m');
-	t.true(stripAnsi(res30).split('\n').every(function (x) {
-		return x.length <= 30;
-	}));
+	t.is(res30, 'The quick brown \u001B[31mfox jumped\u001B[39m\n\u001B[31mover \u001B[39mthe lazy \u001B[32mdog and then ran\u001B[39m\n\u001B[32maway with the unicorn.\u001B[39m');
+	t.true(stripAnsi(res30).split('\n').every(x => x.length <= 30));
 });
 
 test('does not break strings longer than "cols" characters', t => {
-	const res5 = fn(fixture, 5, {hard: false});
+	const res5 = m(fixture, 5, {hard: false});
 
-	t.is(res5, 'The\nquick\nbrown\n\u001b[31mfox\u001b[39m\n\u001b[31mjumped\u001b[39m\n\u001b[31mover\u001b[39m\n\u001b[31m\u001b[39mthe\nlazy\n\u001b[32mdog\u001b[39m\n\u001b[32mand\u001b[39m\n\u001b[32mthen\u001b[39m\n\u001b[32mran\u001b[39m\n\u001b[32maway\u001b[39m\n\u001b[32mwith\u001b[39m\n\u001b[32mthe\u001b[39m\n\u001b[32municorn.\u001b[39m');
+	t.is(res5, 'The\nquick\nbrown\n\u001B[31mfox\u001B[39m\n\u001B[31mjumped\u001B[39m\n\u001B[31mover\u001B[39m\n\u001B[31m\u001B[39mthe\nlazy\n\u001B[32mdog\u001B[39m\n\u001B[32mand\u001B[39m\n\u001B[32mthen\u001B[39m\n\u001B[32mran\u001B[39m\n\u001B[32maway\u001B[39m\n\u001B[32mwith\u001B[39m\n\u001B[32mthe\u001B[39m\n\u001B[32municorn.\u001B[39m');
 	t.true(stripAnsi(res5).split('\n').filter(x => x.length > 5).length > 0);
 });
 
 test('handles colored string that wraps on to multiple lines', t => {
-	const res = fn(chalk.green('hello world') + ' hey!', 5, {hard: false});
+	const res = m(chalk.green('hello world') + ' hey!', 5, {hard: false});
 	const lines = res.split('\n');
 	t.true(hasAnsi(lines[0]));
 	t.true(hasAnsi(lines[1]));
@@ -42,53 +44,72 @@ test('handles colored string that wraps on to multiple lines', t => {
 });
 
 test('does not prepend newline if first string is greater than "cols"', t => {
-	const res = fn(chalk.green('hello') + '-world', 5, {hard: false});
+	const res = m(chalk.green('hello') + '-world', 5, {hard: false});
 	t.is(res.split('\n').length, 1);
 });
 
-// when "hard" is true
+// When "hard" is true
 
 test('breaks strings longer than "cols" characters', t => {
-	const res5 = fn(fixture, 5, {hard: true});
+	const res5 = m(fixture, 5, {hard: true});
 
-	t.is(res5, 'The\nquick\nbrown\n\u001b[31mfox\u001b[39m\n\u001b[31mjumpe\u001b[39m\n\u001b[31md\u001b[39m\n\u001b[31mover\u001b[39m\n\u001b[31m\u001b[39mthe\nlazy\n\u001b[32mdog\u001b[39m\n\u001b[32mand\u001b[39m\n\u001b[32mthen\u001b[39m\n\u001b[32mran\u001b[39m\n\u001b[32maway\u001b[39m\n\u001b[32mwith\u001b[39m\n\u001b[32mthe\u001b[39m\n\u001b[32munico\u001b[39m\n\u001b[32mrn.\u001b[39m');
+	t.is(res5, 'The\nquick\nbrown\n\u001B[31mfox\u001B[39m\n\u001B[31mjumpe\u001B[39m\n\u001B[31md\u001B[39m\n\u001B[31mover\u001B[39m\n\u001B[31m\u001B[39mthe\nlazy\n\u001B[32mdog\u001B[39m\n\u001B[32mand\u001B[39m\n\u001B[32mthen\u001B[39m\n\u001B[32mran\u001B[39m\n\u001B[32maway\u001B[39m\n\u001B[32mwith\u001B[39m\n\u001B[32mthe\u001B[39m\n\u001B[32munico\u001B[39m\n\u001B[32mrn.\u001B[39m');
 	t.true(stripAnsi(res5).split('\n').every(x => x.length <= 5));
 });
 
 test('removes last row if it contained only ansi escape codes', t => {
-	const res = fn(chalk.green('helloworld'), 2, {hard: true});
+	const res = m(chalk.green('helloworld'), 2, {hard: true});
 	t.true(stripAnsi(res).split('\n').every(x => x.length === 2));
 });
 
 test('does not prepend newline if first word is split', t => {
-	const res = fn(chalk.green('hello') + 'world', 5, {hard: true});
+	const res = m(chalk.green('hello') + 'world', 5, {hard: true});
 	t.is(res.split('\n').length, 2);
 });
 
 test('takes into account line returns inside input', t => {
-	const res20 = fn(fixture2, 10, {hard: true});
+	const res20 = m(fixture2, 10, {hard: true});
 	t.is(res20, '12345678\n9012345678\n90');
 });
 
 test('word wrapping', t => {
-	const res = fn(fixture3, 15);
+	const res = m(fixture3, 15);
 	t.is(res, '12345678\n901234567890\n12345');
 });
 
 test('no word-wrapping', t => {
-	const res = fn(fixture3, 15, {wordWrap: false});
+	const res = m(fixture3, 15, {wordWrap: false});
 	t.is(res, '12345678\n901234567890 12\n345');
 
-	const res2 = fn(fixture, 5, {wordWrap: false});
-	t.is(res2, 'The q\nuick\nbrown\nfox j\numped\nover\nthe l\nazy d\nog an\nd the\nn ran\naway\nwith\nthe u\nnicor\nn.');
+	const res2 = m(fixture3, 5, {wordWrap: false});
+	t.is(res2, '12345\n678\n90123\n45678\n90 12\n345');
+
+	const res3 = m(fixture5, 5, {wordWrap: false});
+	t.is(res3, '12345\n678\n');
+
+	const res4 = m(fixture, 5, {wordWrap: false});
+	t.is(res4, 'The q\nuick\nbrown\n\u001B[31mfox j\u001B[39m\n\u001B[31mumped\u001B[39m\n\u001B[31mover\u001B[39m\n\u001B[31m\u001B[39mthe l\nazy \u001B[32md\u001B[39m\n\u001B[32mog an\u001B[39m\n\u001B[32md the\u001B[39m\n\u001B[32mn ran\u001B[39m\n\u001B[32maway\u001B[39m\n\u001B[32mwith\u001B[39m\n\u001B[32mthe u\u001B[39m\n\u001B[32mnicor\u001B[39m\n\u001B[32mn.\u001B[39m');
+});
+
+test('no word-wrapping and no trimming', t => {
+	const res = m(fixture3, 13, {wordWrap: false, trim: false});
+	t.is(res, '12345678\n901234567890 \n12345');
+
+	const res2 = m(fixture4, 5, {wordWrap: false, trim: false});
+	t.is(res2, '12345\n678\n');
+
+	const res3 = m(fixture5, 5, {wordWrap: false, trim: false});
+	t.is(res3, '12345\n678\n ');
+
+	const res4 = m(fixture, 5, {wordWrap: false, trim: false});
+	t.is(res4, 'The q\nuick \nbrown\n \u001B[31mfox \u001B[39m\njumpe\nd ove\nr \u001B[39mthe\n lazy\n \u001B[32mdog \u001B[39m\nand t\nhen r\nan aw\nay wi\nth th\ne uni\ncorn.\u001B[39m');
 });
 
-// https://github.com/chalk/wrap-ansi/issues/10
-test.failing('supports fullwidth characters', t => {
-	t.is(fn('안녕하세', 4, {hard: true}), '안녕\n하세');
+test('supports fullwidth characters', t => {
+	t.is(m('안녕하세', 4, {hard: true}), '안녕\n하세');
 });
 
-// https://github.com/chalk/wrap-ansi/issues/11
-test.failing('supports unicode surrogate pairs', t => {
-	t.is(fn('a\ud83c\ude00bc', 2, {hard: true}), 'a\n\ud83c\ude00\nbc');
+test('supports unicode surrogate pairs', t => {
+	t.is(m('a\uD83C\uDE00bc', 2, {hard: true}), 'a\n\uD83C\uDE00\nbc');
+	t.is(m('a\uD83C\uDE00bc\uD83C\uDE00d\uD83C\uDE00', 2, {hard: true}), 'a\n\uD83C\uDE00\nbc\n\uD83C\uDE00\nd\n\uD83C\uDE00');
 });

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-wrap-ansi.git



More information about the Pkg-javascript-commits mailing list