mirror of
https://github.com/nodejs/node.git
synced 2026-12-03 18:03:02 -05:00
Update ESLint to 2.1.0. ESLint has a number of potentially-useful new features but this change attempts to be minimal in its changes. However, some things could not be avoided reasonably. ESLint 2.1.0 found a few lint issues that ESLing 1.x missed with template strings that did not take advantage of any features of template strings, and `let` declarations where `const` sufficed. Additionally, ESLint 2.1.0 removes some granularity around enabling ES6 features. Some features (e.g., spread operator) that had been turned off in our configuration for ESLint 1.x are now permitted. PR-URL: https://github.com/nodejs/node/pull/5214 Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: jbergstroem - Johan Bergström <bugs@bergstroem.nu> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Myles Borins <myles.borins@gmail.com>
80 lines
1.3 KiB
JavaScript
Executable File
80 lines
1.3 KiB
JavaScript
Executable File
'use strict';
|
|
|
|
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';
|
|
}
|
|
|
|
module.exports = function (str, begin, end) {
|
|
end = end || str.length;
|
|
var insideEscape = false;
|
|
var escapeCode;
|
|
var visible = 0;
|
|
var output = '';
|
|
|
|
for (var i = 0; i < str.length; i++) {
|
|
var leftEscape = false;
|
|
var x = str[i];
|
|
|
|
if (ESCAPES.indexOf(x) !== -1) {
|
|
insideEscape = true;
|
|
var code = /[0-9][^m]*/.exec(str.slice(i, i + 4));
|
|
escapeCode = code === END_CODE ? null : code;
|
|
} else if (insideEscape && x === 'm') {
|
|
insideEscape = false;
|
|
leftEscape = true;
|
|
}
|
|
|
|
if (!insideEscape && !leftEscape) {
|
|
++visible;
|
|
}
|
|
|
|
if (visible > begin && visible <= end) {
|
|
output += x;
|
|
} else if (visible === begin && escapeCode !== undefined && escapeCode !== END_CODE) {
|
|
output += wrapAnsi(escapeCode);
|
|
} else if (visible >= end) {
|
|
if (escapeCode !== undefined) {
|
|
output += wrapAnsi(ESCAPE_CODES[escapeCode] || END_CODE);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
return output;
|
|
};
|