[Pkg-javascript-commits] [node-ansi-regex] 01/03: New upstream version 3.0.0

Paolo Greppi paolog-guest at moszumanska.debian.org
Tue Sep 19 07:44:37 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-ansi-regex.

commit ab655e7a2984750f83bc76e8fb921bd062615a8e
Author: Paolo Greppi <paolo.greppi at libpf.com>
Date:   Tue Sep 19 09:29:42 2017 +0200

    New upstream version 3.0.0
---
 .editorconfig                               |   5 +-
 .gitattributes                              |   1 +
 .jshintrc                                   |  12 --
 .travis.yml                                 |   7 +-
 fixtures/ansi-codes.js                      | 231 ++++++++++++++++++++++++++++
 test/viewCodes.js => fixtures/view-codes.js |  37 ++---
 index.js                                    |  10 +-
 license                                     |  20 +--
 package.json                                |  17 +-
 readme.md                                   |  31 +++-
 test.js                                     |  75 +++++++++
 test/ansiCodes.js                           | 211 -------------------------
 test/test.js                                |  80 ----------
 13 files changed, 372 insertions(+), 365 deletions(-)

diff --git a/.editorconfig b/.editorconfig
index 8f9d77e..1c6314a 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -7,9 +7,6 @@ charset = utf-8
 trim_trailing_whitespace = true
 insert_final_newline = true
 
-[{package.json,*.yml}]
+[*.yml]
 indent_style = space
 indent_size = 2
-
-[*.md]
-trim_trailing_whitespace = false
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/.jshintrc b/.jshintrc
deleted file mode 100644
index 9fe1be2..0000000
--- a/.jshintrc
+++ /dev/null
@@ -1,12 +0,0 @@
-{
-	"node": true,
-	"esnext": true,
-	"bitwise": true,
-	"curly": true,
-	"immed": true,
-	"newcap": true,
-	"noarg": true,
-	"undef": true,
-	"unused": "vars",
-	"strict": true
-}
diff --git a/.travis.yml b/.travis.yml
index dedfc07..7d69d74 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,6 +1,5 @@
-sudo: false
 language: node_js
 node_js:
-  - 'iojs'
-  - '0.12'
-  - '0.10'
+  - '8'
+  - '6'
+  - '4'
diff --git a/fixtures/ansi-codes.js b/fixtures/ansi-codes.js
new file mode 100644
index 0000000..36bc04d
--- /dev/null
+++ b/fixtures/ansi-codes.js
@@ -0,0 +1,231 @@
+'use strict';
+
+// From http://www.umich.edu/~archive/apple2/misc/programmers/vt100.codes.txt
+exports.vt52Codes = new Map([
+	['A', ['Cursor up']],
+	['B', ['Cursor down']],
+	['C', ['Cursor right']],
+	['D', ['Cursor left']],
+	['H', ['Cursor to home']],
+	['I', ['Reverse line feed']],
+	['J', ['Erase to end of screen']],
+	['K', ['Erase to end of line']],
+	['Z', ['Identify']],
+	['=', ['Enter alternate keypad mode']],
+	['>', ['Exit alternate keypad mode']],
+	['1', ['Graphics processor on']],
+	['2', ['Graphics processor off']],
+	['<', ['Enter ANSI mode']]
+]);
+
+// From http://www.umich.edu/~archive/apple2/misc/programmers/vt100.codes.txt
+exports.ansiCompatible = new Map([
+	['[176A', ['Cursor up Pn lines']],
+	['[176B', ['Cursor down Pn lines']],
+	['[176C', ['Cursor forward Pn characters (right)']],
+	['[176D', ['Cursor backward Pn characters (left)']],
+	['[176;176H', ['Direct cursor addressing, where Pl is line#, Pc is column#']],
+	['[176;176f', ['Direct cursor addressing, where Pl is line#, Pc is column#']],
+
+	['7', ['Save cursor and attributes']],
+	['8', ['Restore cursor and attributes']],
+
+	['#3', ['Change this line to double-height top half']],
+	['#4', ['Change this line to double-height bottom half']],
+	['#5', ['Change this line to single-width single-height']],
+	['#6', ['Change this line to double-width single-height']],
+
+	['[176;176;176;176;176;176;176m', ['Text Styles']],
+	['[176;176;176;176;176;176;176q', ['Programmable LEDs']],
+
+	['[K', ['Erase from cursor to end of line']],
+	['[0K', ['Same']],
+	['[1K', ['Erase from beginning of line to cursor']],
+	['[2K', ['Erase line containing cursor']],
+	['[J', ['Erase from cursor to end of screen']],
+	['[0J', ['Same']],
+	['[2J', ['Erase entire screen']],
+	['[P', ['Delete character']],
+	['[0P', ['Delete character (0P)']],
+	['[2P', ['Delete 2 characters']],
+
+	['(A', ['United Kingdom (UK) (Character Set G0)']],
+	[')A', ['United Kingdom (UK) (Character Set G1)']],
+	['(B', ['United States (USASCII) (Character Set G0)']],
+	[')B', ['United States (USASCII) (Character Set G1)']],
+	['(0', ['Special graphics/line drawing set (Character Set G0)']],
+	[')0', ['Special graphics/line drawing set (Character Set G1)']],
+	['(1', ['Alternative character ROM (Character Set G0)']],
+	[')1', ['Alternative character ROM (Character Set G1)']],
+	['(2', ['Alternative graphic ROM (Character Set G0)']],
+	[')2', ['Alternative graphic ROM (Character Set G1)']],
+
+	['H', ['Set tab at current column']],
+	['[g', ['Clear tab at current column']],
+	['[0g', ['Same']],
+	['[3g', ['Clear all tabs']],
+
+	['[6n', ['Cursor position report']],
+	['[176;176R', ['(response; Pl=line#; Pc=column#)']],
+	['[5n', ['Status report']],
+	['[c', ['(response; terminal Ok)']],
+	['[0c', ['(response; teminal not Ok)']],
+	['[?1;176c', ['response; where Ps is option present:']],
+
+	['c', ['Causes power-up reset routine to be executed']],
+	['#8', ['Fill screen with "E"']],
+	['[2;176y', ['Invoke Test(s), where Ps is a decimal computed by adding the numbers of the desired tests to be executed']]
+]);
+
+// From http://ascii-table.com/ansi-escape-sequences-vt-100.php
+exports.commonCodes = new Map([
+	['[176A', ['Move cursor up n lines', 'CUU']],
+	['[176B', ['Move cursor down n lines', 'CUD']],
+	['[176C', ['Move cursor right n lines', 'CUF']],
+	['[176D', ['Move cursor left n lines', 'CUB']],
+	['[176;176H', ['Move cursor to screen location v,h', 'CUP']],
+	['[176;176f', ['Move cursor to screen location v,h', 'CUP']],
+	['[176;176r', ['Set top and bottom lines of a window', 'DECSTBM']],
+	['[176;176R', ['Response: cursor is at v,h', 'CPR']],
+
+	['[?1;1760c', ['Response: terminal type code n', 'DA']],
+
+	['[20h', ['Set new line mode', 'LMN']],
+	['[?1h', ['Set cursor key to application', 'DECCKM']],
+	['[?3h', ['Set number of columns to 132', 'DECCOLM']],
+	['[?4h', ['Set smooth scrolling', 'DECSCLM']],
+	['[?5h', ['Set reverse video on screen', 'DECSCNM']],
+	['[?6h', ['Set origin to relative', 'DECOM']],
+	['[?7h', ['Set auto-wrap mode', 'DECAWM']],
+	['[?8h', ['Set auto-repeat mode', 'DECARM']],
+	['[?9h', ['Set interlacing mode', 'DECINLM']],
+	['[20l', ['Set line feed mode', 'LMN']],
+	['[?1l', ['Set cursor key to cursor', 'DECCKM']],
+	['[?2l', ['Set VT52 (versus ANSI)', 'DECANM']],
+	['[?3l', ['Set number of columns to 80', 'DECCOLM']],
+	['[?4l', ['Set jump scrolling', 'DECSCLM']],
+	['[?5l', ['Set normal video on screen', 'DECSCNM']],
+	['[?6l', ['Set origin to absolute', 'DECOM']],
+	['[?7l', ['Reset auto-wrap mode', 'DECAWM']],
+	['[?8l', ['Reset auto-repeat mode', 'DECARM']],
+	['[?9l', ['Reset interlacing mode', 'DECINLM']],
+
+	['N', ['Set single shift 2', 'SS2']],
+	['O', ['Set single shift 3', 'SS3']],
+
+	['[m', ['Turn off character attributes', 'SGR0']],
+	['[0m', ['Turn off character attributes', 'SGR0']],
+	['[1m', ['Turn bold mode on', 'SGR1']],
+	['[2m', ['Turn low intensity mode on', 'SGR2']],
+	['[4m', ['Turn underline mode on', 'SGR4']],
+	['[5m', ['Turn blinking mode on', 'SGR5']],
+	['[7m', ['Turn reverse video on', 'SGR7']],
+	['[8m', ['Turn invisible text mode on', 'SGR8']],
+
+	['[9m', ['strikethrough on', '--']],
+	['[22m', ['bold off (see below)', '--']],
+	['[23m', ['italics off', '--']],
+	['[24m', ['underline off', '--']],
+	['[27m', ['inverse off', '--']],
+	['[29m', ['strikethrough off', '--']],
+	['[30m', ['set foreground color to black', '--']],
+	['[31m', ['set foreground color to red', '--']],
+	['[32m', ['set foreground color to green', '--']],
+	['[33m', ['set foreground color to yellow', '--']],
+	['[34m', ['set foreground color to blue', '--']],
+	['[35m', ['set foreground color to magenta (purple)', '--']],
+	['[36m', ['set foreground color to cyan', '--']],
+	['[37m', ['set foreground color to white', '--']],
+	['[39m', ['set foreground color to default (white)', '--']],
+	['[40m', ['set background color to black', '--']],
+	['[41m', ['set background color to red', '--']],
+	['[42m', ['set background color to green', '--']],
+	['[43m', ['set background color to yellow', '--']],
+	['[44m', ['set background color to blue', '--']],
+	['[45m', ['set background color to magenta (purple)', '--']],
+	['[46m', ['set background color to cyan', '--']],
+	['[47m', ['set background color to white', '--']],
+	['[49m', ['set background color to default (black)', '--']],
+
+	['[H', ['Move cursor to upper left corner', 'cursorhome']],
+	['[;H', ['Move cursor to upper left corner', 'cursorhome']],
+	['[f', ['Move cursor to upper left corner', 'hvhome']],
+	['[;f', ['Move cursor to upper left corner', 'hvhome']],
+	['M', ['Move/scroll window down one line', 'RI']],
+	['E', ['Move to next line', 'NEL']],
+
+	['H', ['Set a tab at the current column', 'HTS']],
+	['[g', ['Clear a tab at the current column', 'TBC']],
+	['[0g', ['Clear a tab at the current column', 'TBC']],
+	['[3g', ['Clear all tabs', 'TBC']],
+
+	['[K', ['Clear line from cursor right', 'EL0']],
+	['[0K', ['Clear line from cursor right', 'EL0']],
+	['[1K', ['Clear line from cursor left', 'EL1']],
+	['[2K', ['Clear entire line', 'EL2']],
+	['[J', ['Clear screen from cursor down', 'ED0']],
+	['[0J', ['Clear screen from cursor down', 'ED0']],
+	['[1J', ['Clear screen from cursor up', 'ED1']],
+	['[2J', ['Clear entire screen', 'ED2']],
+
+	['[c', ['Identify what terminal type', 'DA']],
+	['[0c', ['Identify what terminal type (another)', 'DA']],
+	['c', ['Reset terminal to initial state', 'RIS']],
+	['[2;1y', ['Confidence power up test', 'DECTST']],
+	['[2;2y', ['Confidence loopback test', 'DECTST']],
+	['[2;9y', ['Repeat power up test', 'DECTST']],
+	['[2;10y', ['Repeat loopback test', 'DECTST']],
+	['[0q', ['Turn off all four leds', 'DECLL0']],
+	['[1q', ['Turn on LED #1', 'DECLL1']],
+	['[2q', ['Turn on LED #2', 'DECLL2']],
+	['[3q', ['Turn on LED #3', 'DECLL3']],
+	['[4q', ['Turn on LED #4', 'DECLL4']]
+]);
+
+// From http://ascii-table.com/ansi-escape-sequences-vt-100.php
+exports.otherCode = new Map([
+	['7', ['Save cursor position and attributes', 'DECSC']],
+	['8', ['Restore cursor position and attributes', 'DECSC']],
+
+	['=', ['Set alternate keypad mode', 'DECKPAM']],
+	['>', ['Set numeric keypad mode', 'DECKPNM']],
+
+	['(A', ['Set United Kingdom G0 character set', 'setukg0']],
+	[')A', ['Set United Kingdom G1 character set', 'setukg1']],
+	['(B', ['Set United States G0 character set', 'setusg0']],
+	[')B', ['Set United States G1 character set', 'setusg1']],
+	['(0', ['Set G0 special chars. & line set', 'setspecg0']],
+	[')0', ['Set G1 special chars. & line set', 'setspecg1']],
+	['(1', ['Set G0 alternate character ROM', 'setaltg0']],
+	[')1', ['Set G1 alternate character ROM', 'setaltg1']],
+	['(2', ['Set G0 alt char ROM and spec. graphics', 'setaltspecg0']],
+	[')2', ['Set G1 alt char ROM and spec. graphics', 'setaltspecg1']],
+
+	['#3', ['Double-height letters, top half', 'DECDHL']],
+	['#4', ['Double-height letters, bottom half', 'DECDHL']],
+	['#5', ['Single width, single height letters', 'DECSWL']],
+	['#6', ['Double width, single height letters', 'DECDWL']],
+	['#8', ['Screen alignment display', 'DECALN']],
+
+	['5n', ['Device status report', 'DSR']],
+	['0n', ['Response: terminal is OK', 'DSR']],
+	['3n', ['Response: terminal is not OK', 'DSR']],
+	['6n', ['Get cursor position', 'DSR']]
+]);
+
+// urxvt escapes
+exports.urxvt = new Map([
+	['[5~', ['URxvt.keysym.Prior']],
+	['[6~', ['URxvt.keysym.Next']],
+	['[7~', ['URxvt.keysym.Home']],
+	['[8~', ['URxvt.keysym.End']],
+	['[A', ['URxvt.keysym.Up']],
+	['[B', ['URxvt.keysym.Down']],
+	['[C', ['URxvt.keysym.Right']],
+	['[D', ['URxvt.keysym.Left']],
+	['[3;5;5t', ['URxvt.keysym.C-M-q']],
+	['[3;5;606t', ['URxvt.keysym.C-M-y']],
+	['[3;1605;5t', ['URxvt.keysym.C-M-e']],
+	['[3;1605;606t', ['URxvt.keysym.C-M-c']],
+	[']710;9x15bold\u0007', ['URxvt.keysym.font']]
+]);
diff --git a/test/viewCodes.js b/fixtures/view-codes.js
similarity index 52%
rename from test/viewCodes.js
rename to fixtures/view-codes.js
index 25125dc..a13105a 100644
--- a/test/viewCodes.js
+++ b/fixtures/view-codes.js
@@ -1,27 +1,28 @@
 'use strict';
-var ansiRegex = require('../');
-var ansiCodes = require('./ansiCodes');
-var allCodes = {};
-var supported = [];
-var unsupported = [];
+const ansiRegex = require('..');
+const ansiCodes = require('./ansi-codes');
+
+const allCodes = {};
+const supported = [];
+const unsupported = [];
 
 function addCodesToTest(codes) {
-	for (var code in codes) {
+	for (const code in codes) {
 		allCodes[code] = codes[code];
 	}
 }
 
 function identifySupportedCodes() {
-	var codeSupport = {};
+	let codeSupport = {};
 
-	for (var code in allCodes) {
+	for (const code in allCodes) {
 		codeSupport = {
-			code: code,
-			matches: ('\u001b' + code).match(ansiRegex()),
+			code,
+			matches: `\u001B${code}`.match(ansiRegex()),
 			description: allCodes[code][0]
 		};
 
-		if (codeSupport.matches !== null && codeSupport.matches[0] === '\u001b' + code) {
+		if (codeSupport.matches !== null && codeSupport.matches[0] === `\u001B${code}`) {
 			supported.push(codeSupport);
 		} else {
 			unsupported.push(codeSupport);
@@ -30,21 +31,21 @@ function identifySupportedCodes() {
 }
 
 function displaySupport() {
-	process.stdout.write('\u001b[32m');
+	process.stdout.write('\u001B[32m');
 
 	console.log('SUPPORTED');
-	for (var i = 0; i < supported.length; i++) {
-		console.log(supported[i]);
+	for (const el of supported) {
+		console.log(el);
 	}
 
-	process.stdout.write('\u001b[31m');
+	process.stdout.write('\u001B[31m');
 	console.log('UNSUPPORTED');
 
-	for (var j = 0; j < unsupported.length; j++) {
-		console.log(unsupported[j]);
+	for (const el of unsupported) {
+		console.log(el);
 	}
 
-	process.stdout.write('\u001b[0m');
+	process.stdout.write('\u001B[0m');
 }
 
 addCodesToTest(ansiCodes.vt52Codes);
diff --git a/index.js b/index.js
index 4906755..c4aaecf 100644
--- a/index.js
+++ b/index.js
@@ -1,4 +1,10 @@
 'use strict';
-module.exports = function () {
-	return /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
+
+module.exports = () => {
+	const pattern = [
+		'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\\u0007)',
+		'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))'
+	].join('|');
+
+	return new RegExp(pattern, 'g');
 };
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 bca8b6d..e94852f 100644
--- a/package.json
+++ b/package.json
@@ -1,24 +1,20 @@
 {
   "name": "ansi-regex",
-  "version": "2.0.0",
+  "version": "3.0.0",
   "description": "Regular expression for matching ANSI escape codes",
   "license": "MIT",
-  "repository": "sindresorhus/ansi-regex",
+  "repository": "chalk/ansi-regex",
   "author": {
     "name": "Sindre Sorhus",
     "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)"
-  ],
   "engines": {
-    "node": ">=0.10.0"
+    "node": ">=4"
   },
   "scripts": {
-    "test": "mocha test/test.js",
-    "view-supported": "node test/viewCodes.js"
+    "test": "xo && ava",
+    "view-supported": "node fixtures/view-codes.js"
   },
   "files": [
     "index.js"
@@ -51,6 +47,7 @@
     "pattern"
   ],
   "devDependencies": {
-    "mocha": "*"
+    "ava": "*",
+    "xo": "*"
   }
 }
diff --git a/readme.md b/readme.md
index 1a4894e..22db1c3 100644
--- a/readme.md
+++ b/readme.md
@@ -1,31 +1,46 @@
-# ansi-regex [![Build Status](https://travis-ci.org/sindresorhus/ansi-regex.svg?branch=master)](https://travis-ci.org/sindresorhus/ansi-regex)
+# ansi-regex [![Build Status](https://travis-ci.org/chalk/ansi-regex.svg?branch=master)](https://travis-ci.org/chalk/ansi-regex)
 
-> Regular expression for matching [ANSI escape codes](http://en.wikipedia.org/wiki/ANSI_escape_code)
+> Regular expression for matching [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code)
 
 
 ## Install
 
 ```
-$ npm install --save ansi-regex
+$ npm install ansi-regex
 ```
 
 
 ## Usage
 
 ```js
-var ansiRegex = require('ansi-regex');
+const ansiRegex = require('ansi-regex');
 
-ansiRegex().test('\u001b[4mcake\u001b[0m');
+ansiRegex().test('\u001B[4mcake\u001B[0m');
 //=> true
 
 ansiRegex().test('cake');
 //=> false
 
-'\u001b[4mcake\u001b[0m'.match(ansiRegex());
-//=> ['\u001b[4m', '\u001b[0m']
+'\u001B[4mcake\u001B[0m'.match(ansiRegex());
+//=> ['\u001B[4m', '\u001B[0m']
 ```
 
 
+## FAQ
+
+### Why do you test for codes not in the ECMA 48 standard?
+
+Some of the codes we run as a test are codes that we acquired finding various lists of non-standard or manufacturer specific codes. We test for both standard and non-standard codes, as most of them follow the same or similar format and can be safely matched in strings without the risk of removing actual string content. There are a few non-standard control codes that do not follow the traditional format (i.e. they end in numbers) thus forcing us to exclude them from the test because we ca [...]
+
+On the historical side, those ECMA standards were established in the early 90's whereas the VT100, for example, was designed in the mid/late 70's. At that point in time, control codes were still pretty ungoverned and engineers used them for a multitude of things, namely to activate hardware ports that may have been proprietary. Somewhere else you see a similar 'anarchy' of codes is in the x86 architecture for processors; there are a ton of "interrupts" that can mean different things on c [...]
+
+
+## Maintainers
+
+- [Sindre Sorhus](https://github.com/sindresorhus)
+- [Josh Junon](https://github.com/qix-)
+
+
 ## License
 
-MIT © [Sindre Sorhus](http://sindresorhus.com)
+MIT
diff --git a/test.js b/test.js
new file mode 100644
index 0000000..05a448b
--- /dev/null
+++ b/test.js
@@ -0,0 +1,75 @@
+import test from 'ava';
+import ansiCodes from './fixtures/ansi-codes';
+import m from '.';
+
+const consumptionChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+1234567890-=[]{};\':"./>?,<\\|';
+
+// Testing against codes found at: http://ascii-table.com/ansi-escape-sequences-vt-100.php
+test('match ansi code in a string', t => {
+	t.regex('foo\u001B[4mcake\u001B[0m', m());
+	t.regex('\u001B[4mcake\u001B[0m', m());
+	t.regex('foo\u001B[4mcake\u001B[0m', m());
+	t.regex('\u001B[0m\u001B[4m\u001B[42m\u001B[31mfoo\u001B[39m\u001B[49m\u001B[24mfoo\u001B[0m', m());
+	t.regex('foo\u001B[mfoo', m());
+});
+
+test('match ansi code from ls command', t => {
+	t.regex('\u001B[00;38;5;244m\u001B[m\u001B[00;38;5;33mfoo\u001B[0m', m());
+});
+
+test('match reset;setfg;setbg;italics;strike;underline sequence in a string', t => {
+	t.regex('\u001B[0;33;49;3;9;4mbar\u001B[0m', m());
+	t.is('foo\u001B[0;33;49;3;9;4mbar'.match(m())[0], '\u001B[0;33;49;3;9;4m');
+});
+
+test('match clear tabs sequence in a string', t => {
+	t.regex('foo\u001B[0gbar', m());
+	t.is('foo\u001B[0gbar'.match(m())[0], '\u001B[0g');
+});
+
+test('match clear line from cursor right in a string', t => {
+	t.regex('foo\u001B[Kbar', m());
+	t.is('foo\u001B[Kbar'.match(m())[0], '\u001B[K');
+});
+
+test('match clear screen in a string', t => {
+	t.regex('foo\u001B[2Jbar', m());
+	t.is('foo\u001B[2Jbar'.match(m())[0], '\u001B[2J');
+});
+
+// Testing against extended codes (excluding codes ending in 0-9)
+for (const codeSet of Object.keys(ansiCodes)) {
+	for (const el of ansiCodes[codeSet]) {
+		const code = el[0];
+		const codeInfo = el[1];
+		const skip = /\d$/.test(code);
+		const skipText = skip ? '[SKIP] ' : '';
+		const ecode = `\u001B${code}`;
+
+		test(`${skipText}${code} → ${codeInfo[0]}`, t => {
+			if (skip) {
+				t.pass();
+				return;
+			}
+
+			const string = `hel${ecode}lo`;
+			t.regex(string, m());
+			t.is(string.match(m())[0], ecode);
+			t.is(string.replace(m(), ''), 'hello');
+		});
+
+		test(`${skipText}${code} should not overconsume`, t => {
+			if (skip) {
+				t.pass();
+				return;
+			}
+
+			for (const c of consumptionChars) {
+				const string = ecode + c;
+				t.regex(string, m());
+				t.is(string.match(m())[0], ecode);
+				t.is(string.replace(m(), ''), c);
+			}
+		});
+	}
+}
diff --git a/test/ansiCodes.js b/test/ansiCodes.js
deleted file mode 100644
index 4c3c0fb..0000000
--- a/test/ansiCodes.js
+++ /dev/null
@@ -1,211 +0,0 @@
-'use strict';
-
-// from http://www.umich.edu/~archive/apple2/misc/programmers/vt100.codes.txt
-exports.vt52Codes = {
-	'A': ['Cursor up'],
-	'B': ['Cursor down'],
-	'C': ['Cursor right'],
-	'D': ['Cursor left'],
-	'H': ['Cursor to home'],
-	'I': ['Reverse line feed'],
-	'J': ['Erase to end of screen'],
-	'K': ['Erase to end of line'],
-	'Z': ['Identify'],
-	'=': ['Enter alternate keypad mode'],
-	'>': ['Exit alternate keypad mode'],
-	'1': ['Graphics processor on'],
-	'2': ['Graphics processor off'],
-	'<': ['Enter ANSI mode']
-};
-
-// from http://www.umich.edu/~archive/apple2/misc/programmers/vt100.codes.txt
-exports.ansiCompatible = {
-	'[176A': ['Cursor up Pn lines'],
-	'[176B': ['Cursor down Pn lines'],
-	'[176C': ['Cursor forward Pn characters (right)'],
-	'[176D': ['Cursor backward Pn characters (left)'],
-	'[176;176H': ['Direct cursor addressing, where Pl is line#, Pc is column#'],
-	'[176;176f': ['Direct cursor addressing, where Pl is line#, Pc is column#'],
-
-	'7': ['Save cursor and attributes'],
-	'8': ['Restore cursor and attributes'],
-
-	'#3': ['Change this line to double-height top half'],
-	'#4': ['Change this line to double-height bottom half'],
-	'#5': ['Change this line to single-width single-height'],
-	'#6': ['Change this line to double-width single-height'],
-
-	'[176;176;176;176;176;176;176m': ['Text Styles'],
-	'[176;176;176;176;176;176;176q': ['Programmable LEDs'],
-
-	'[K': ['Erase from cursor to end of line'],
-	'[0K': ['Same'],
-	'[1K': ['Erase from beginning of line to cursor'],
-	'[2K': ['Erase line containing cursor'],
-	'[J': ['Erase from cursor to end of screen'],
-	'[0J': ['Same'],
-	'[2J': ['Erase entire screen'],
-
-	'(A': ['United Kingdom (UK) (Character Set G0)'],
-	')A': ['United Kingdom (UK) (Character Set G1)'],
-	'(B': ['United States (USASCII) (Character Set G0)'],
-	')B': ['United States (USASCII) (Character Set G1)'],
-	'(0': ['Special graphics/line drawing set (Character Set G0)'],
-	')0': ['Special graphics/line drawing set (Character Set G1)'],
-	'(1': ['Alternative character ROM (Character Set G0)'],
-	')1': ['Alternative character ROM (Character Set G1)'],
-	'(2': ['Alternative graphic ROM (Character Set G0)'],
-	')2': ['Alternative graphic ROM (Character Set G1)'],
-
-	'H': ['Set tab at current column'],
-	'[g': ['Clear tab at current column'],
-	'[0g': ['Same'],
-	'[3g': ['Clear all tabs'],
-
-	'[6n': ['Cursor position report'],
-	'[176;176R': ['(response; Pl=line#; Pc=column#)'],
-	'[5n': ['Status report'],
-	'[c': ['(response; terminal Ok)'],
-	'[0c': ['(response; teminal not Ok)'],
-	'[?1;176c': ['response; where Ps is option present:'],
-
-	'c': ['Causes power-up reset routine to be executed'],
-	'#8': ['Fill screen with "E"'],
-	'[2;176y': ['Invoke Test(s), where Ps is a decimal computed by adding the numbers of the desired tests to be executed']
-};
-
-// from http://ascii-table.com/ansi-escape-sequences-vt-100.php
-exports.commonCodes = {
-	'[176A': ['Move cursor up n lines', 'CUU'],
-	'[176B': ['Move cursor down n lines', 'CUD'],
-	'[176C': ['Move cursor right n lines', 'CUF'],
-	'[176D': ['Move cursor left n lines', 'CUB'],
-	'[176;176H': ['Move cursor to screen location v,h', 'CUP'],
-	'[176;176f': ['Move cursor to screen location v,h', 'CUP'],
-	'[176;176r': ['Set top and bottom lines of a window', 'DECSTBM'],
-	'[176;176R': ['Response: cursor is at v,h', 'CPR'],
-
-	'[?1;1760c': ['Response: terminal type code n', 'DA'],
-
-	'[20h': ['Set new line mode', 'LMN'],
-	'[?1h': ['Set cursor key to application', 'DECCKM'],
-	'[?3h': ['Set number of columns to 132', 'DECCOLM'],
-	'[?4h': ['Set smooth scrolling', 'DECSCLM'],
-	'[?5h': ['Set reverse video on screen', 'DECSCNM'],
-	'[?6h': ['Set origin to relative', 'DECOM'],
-	'[?7h': ['Set auto-wrap mode', 'DECAWM'],
-	'[?8h': ['Set auto-repeat mode', 'DECARM'],
-	'[?9h': ['Set interlacing mode', 'DECINLM'],
-	'[20l': ['Set line feed mode', 'LMN'],
-	'[?1l': ['Set cursor key to cursor', 'DECCKM'],
-	'[?2l': ['Set VT52 (versus ANSI)', 'DECANM'],
-	'[?3l': ['Set number of columns to 80', 'DECCOLM'],
-	'[?4l': ['Set jump scrolling', 'DECSCLM'],
-	'[?5l': ['Set normal video on screen', 'DECSCNM'],
-	'[?6l': ['Set origin to absolute', 'DECOM'],
-	'[?7l': ['Reset auto-wrap mode', 'DECAWM'],
-	'[?8l': ['Reset auto-repeat mode', 'DECARM'],
-	'[?9l': ['Reset interlacing mode', 'DECINLM'],
-
-	'N': ['Set single shift 2', 'SS2'],
-	'O': ['Set single shift 3', 'SS3'],
-
-	'[m': ['Turn off character attributes', 'SGR0'],
-	'[0m': ['Turn off character attributes', 'SGR0'],
-	'[1m': ['Turn bold mode on', 'SGR1'],
-	'[2m': ['Turn low intensity mode on', 'SGR2'],
-	'[4m': ['Turn underline mode on', 'SGR4'],
-	'[5m': ['Turn blinking mode on', 'SGR5'],
-	'[7m': ['Turn reverse video on', 'SGR7'],
-	'[8m': ['Turn invisible text mode on', 'SGR8'],
-
-	'[9m': ['strikethrough on', '--'],
-	'[22m': ['bold off (see below)', '--'],
-	'[23m': ['italics off', '--'],
-	'[24m': ['underline off', '--'],
-	'[27m': ['inverse off', '--'],
-	'[29m': ['strikethrough off', '--'],
-	'[30m': ['set foreground color to black', '--'],
-	'[31m': ['set foreground color to red', '--'],
-	'[32m': ['set foreground color to green', '--'],
-	'[33m': ['set foreground color to yellow', '--'],
-	'[34m': ['set foreground color to blue', '--'],
-	'[35m': ['set foreground color to magenta (purple)', '--'],
-	'[36m': ['set foreground color to cyan', '--'],
-	'[37m': ['set foreground color to white', '--'],
-	'[39m': ['set foreground color to default (white)', '--'],
-	'[40m': ['set background color to black', '--'],
-	'[41m': ['set background color to red', '--'],
-	'[42m': ['set background color to green', '--'],
-	'[43m': ['set background color to yellow', '--'],
-	'[44m': ['set background color to blue', '--'],
-	'[45m': ['set background color to magenta (purple)', '--'],
-	'[46m': ['set background color to cyan', '--'],
-	'[47m': ['set background color to white', '--'],
-	'[49m': ['set background color to default (black)', '--'],
-
-	'[H': ['Move cursor to upper left corner', 'cursorhome'],
-	'[;H': ['Move cursor to upper left corner', 'cursorhome'],
-	'[f': ['Move cursor to upper left corner', 'hvhome'],
-	'[;f': ['Move cursor to upper left corner', 'hvhome'],
-	'M': ['Move/scroll window down one line', 'RI'],
-	'E': ['Move to next line', 'NEL'],
-
-	'H': ['Set a tab at the current column', 'HTS'],
-	'[g': ['Clear a tab at the current column', 'TBC'],
-	'[0g': ['Clear a tab at the current column', 'TBC'],
-	'[3g': ['Clear all tabs', 'TBC'],
-
-	'[K': ['Clear line from cursor right', 'EL0'],
-	'[0K': ['Clear line from cursor right', 'EL0'],
-	'[1K': ['Clear line from cursor left', 'EL1'],
-	'[2K': ['Clear entire line', 'EL2'],
-	'[J': ['Clear screen from cursor down', 'ED0'],
-	'[0J': ['Clear screen from cursor down', 'ED0'],
-	'[1J': ['Clear screen from cursor up', 'ED1'],
-	'[2J': ['Clear entire screen', 'ED2'],
-
-	'[c': ['Identify what terminal type', 'DA'],
-	'[0c': ['Identify what terminal type (another)', 'DA'],
-	'c': ['Reset terminal to initial state', 'RIS'],
-	'[2;1y': ['Confidence power up test', 'DECTST'],
-	'[2;2y': ['Confidence loopback test', 'DECTST'],
-	'[2;9y': ['Repeat power up test', 'DECTST'],
-	'[2;10y': ['Repeat loopback test', 'DECTST'],
-	'[0q': ['Turn off all four leds', 'DECLL0'],
-	'[1q': ['Turn on LED #1', 'DECLL1'],
-	'[2q': ['Turn on LED #2', 'DECLL2'],
-	'[3q': ['Turn on LED #3', 'DECLL3'],
-	'[4q': ['Turn on LED #4', 'DECLL4']
-};
-
-// from http://ascii-table.com/ansi-escape-sequences-vt-100.php
-exports.otherCode = {
-	'7': ['Save cursor position and attributes', 'DECSC'],
-	'8': ['Restore cursor position and attributes', 'DECSC'],
-
-	'=': ['Set alternate keypad mode', 'DECKPAM'],
-	'>': ['Set numeric keypad mode', 'DECKPNM'],
-
-	'(A': ['Set United Kingdom G0 character set', 'setukg0'],
-	')A': ['Set United Kingdom G1 character set', 'setukg1'],
-	'(B': ['Set United States G0 character set', 'setusg0'],
-	')B': ['Set United States G1 character set', 'setusg1'],
-	'(0': ['Set G0 special chars. & line set', 'setspecg0'],
-	')0': ['Set G1 special chars. & line set', 'setspecg1'],
-	'(1': ['Set G0 alternate character ROM', 'setaltg0'],
-	')1': ['Set G1 alternate character ROM', 'setaltg1'],
-	'(2': ['Set G0 alt char ROM and spec. graphics', 'setaltspecg0'],
-	')2': ['Set G1 alt char ROM and spec. graphics', 'setaltspecg1'],
-
-	'#3': ['Double-height letters, top half', 'DECDHL'],
-	'#4': ['Double-height letters, bottom half', 'DECDHL'],
-	'#5': ['Single width, single height letters', 'DECSWL'],
-	'#6': ['Double width, single height letters', 'DECDWL'],
-	'#8': ['Screen alignment display', 'DECALN'],
-
-	'5n': ['Device status report', 'DSR'],
-	'0n': ['Response: terminal is OK', 'DSR'],
-	'3n': ['Response: terminal is not OK', 'DSR'],
-	'6n': ['Get cursor position', 'DSR']
-};
diff --git a/test/test.js b/test/test.js
deleted file mode 100644
index 35ffa98..0000000
--- a/test/test.js
+++ /dev/null
@@ -1,80 +0,0 @@
-'use strict';
-var assert = require('assert');
-var ansiRegex = require('../');
-var ansiCodes = require('./ansiCodes.js');
-
-var consumptionChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()_+1234567890-=[]{};\':"./>?,<\\|';
-
-// testing against codes found at: http://ascii-table.com/ansi-escape-sequences-vt-100.php
-describe('practical tests', function () {
-	it('should match ansi code in a string', function () {
-		assert.equal(ansiRegex().test('foo\u001b[4mcake\u001b[0m'), true);
-		assert.equal(ansiRegex().test('\u001b[4mcake\u001b[0m'), true);
-		assert.equal(ansiRegex().test('foo\u001b[4mcake\u001b[0m'), true);
-		assert.equal(ansiRegex().test('\u001b[0m\u001b[4m\u001b[42m\u001b[31mfoo\u001b[39m\u001b[49m\u001b[24mfoo\u001b[0m'), true);
-		assert.equal(ansiRegex().test('foo\u001b[mfoo'), true);
-	});
-
-	it('should match ansi code from ls command', function () {
-		assert.equal(ansiRegex().test('\u001b[00;38;5;244m\u001b[m\u001b[00;38;5;33mfoo\u001b[0m'), true);
-	});
-
-	it('should match reset;setfg;setbg;italics;strike;underline sequence in a string', function () {
-		assert.equal(ansiRegex().test('\u001b[0;33;49;3;9;4mbar\u001b[0m'), true);
-		assert.equal('foo\u001b[0;33;49;3;9;4mbar'.match(ansiRegex())[0], '\u001b[0;33;49;3;9;4m');
-	});
-
-	it('should match clear tabs sequence in a string', function () {
-		assert.equal(ansiRegex().test('foo\u001b[0gbar'), true);
-		assert.equal('foo\u001b[0gbar'.match(ansiRegex())[0], '\u001b[0g');
-	});
-
-	it('should match clear line from cursor right in a string', function () {
-		assert.equal(ansiRegex().test('foo\u001b[Kbar'), true);
-		assert.equal('foo\u001b[Kbar'.match(ansiRegex())[0], '\u001b[K');
-	});
-
-	it('should match clear screen in a string', function () {
-		assert.equal(ansiRegex().test('foo\u001b[2Jbar'), true);
-		assert.equal('foo\u001b[2Jbar'.match(ansiRegex())[0], '\u001b[2J');
-	});
-});
-
-// testing against extended codes (excluding codes ending in 0-9)
-describe('extended tests', function () {
-	for (var codeSet in ansiCodes) {
-		describe(codeSet, function () {
-			for (var code in ansiCodes[codeSet]) {
-				var codeInfo = ansiCodes[codeSet][code];
-				var skip = !!code.match(/[0-9]$/);
-				var skipText = skip ? '[SKIP] ' : '';
-				var ecode = '\u001b' + code;
-
-				it(skipText + code + ' -> ' + codeInfo[0], function (ecode, skip) {
-					if (skip) {
-						return;
-					}
-
-					var string = 'hel' + ecode + 'lo';
-					assert.equal(ansiRegex().test(string), true);
-					assert.equal(string.match(ansiRegex())[0], ecode);
-					assert.equal(string.replace(ansiRegex(), ''), 'hello');
-				}.bind(null, ecode, skip));
-
-				it(skipText + code + ' should not overconsume', function (ecode, skip) {
-					if (skip) {
-						return;
-					}
-
-					for (var i = 0; i < consumptionChars.length; i++) {
-						var c = consumptionChars[i];
-						var string = ecode + c;
-						assert.equal(ansiRegex().test(string), true);
-						assert.equal(string.match(ansiRegex())[0], ecode);
-						assert.equal(string.replace(ansiRegex(), ''), c);
-					}
-				}.bind(null, ecode, skip));
-			}
-		});
-	}
-});

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



More information about the Pkg-javascript-commits mailing list