aboutsummaryrefslogtreecommitdiff
path: root/node_modules/slice-ansi
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-05-28 00:38:50 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-05-28 00:40:43 +0200
commit7fff4499fd915bcea3fa93b1aa8b35f4fe7a6027 (patch)
tree6de9a1aebd150a23b7f8c273ec657a5d0a18fe3e /node_modules/slice-ansi
parent963b7a41feb29cc4be090a2446bdfe0c1f1bcd81 (diff)
add linting (and some initial fixes)
Diffstat (limited to 'node_modules/slice-ansi')
-rwxr-xr-xnode_modules/slice-ansi/index.js80
-rwxr-xr-xnode_modules/slice-ansi/license22
-rw-r--r--node_modules/slice-ansi/package.json56
-rwxr-xr-xnode_modules/slice-ansi/readme.md56
4 files changed, 214 insertions, 0 deletions
diff --git a/node_modules/slice-ansi/index.js b/node_modules/slice-ansi/index.js
new file mode 100755
index 000000000..c65de4d4a
--- /dev/null
+++ b/node_modules/slice-ansi/index.js
@@ -0,0 +1,80 @@
+'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;
+};
+
diff --git a/node_modules/slice-ansi/license b/node_modules/slice-ansi/license
new file mode 100755
index 000000000..3ecaf413e
--- /dev/null
+++ b/node_modules/slice-ansi/license
@@ -0,0 +1,22 @@
+(The MIT License)
+
+Copyright (c) 2015 DC <threedeecee@gmail.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:
+
+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. \ No newline at end of file
diff --git a/node_modules/slice-ansi/package.json b/node_modules/slice-ansi/package.json
new file mode 100644
index 000000000..70bc93162
--- /dev/null
+++ b/node_modules/slice-ansi/package.json
@@ -0,0 +1,56 @@
+{
+ "name": "slice-ansi",
+ "version": "0.0.4",
+ "description": "Slice a string with ANSI escape codes",
+ "license": "MIT",
+ "repository": "chalk/slice-ansi",
+ "author": {
+ "name": "David Caccavella",
+ "email": "threedeecee@gmail.com"
+ },
+ "maintainers": [
+ "David Caccavella <threedeecee@gmail.com> (github.com/dthree)",
+ "Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)",
+ "Joshua Appelman <jappelman@xebia.com> (jbnicolai.com)",
+ "JD Ballard <i.am.qix@gmail.com> (github.com/qix-)"
+ ],
+ "engines": {
+ "node": ">=0.10.0"
+ },
+ "scripts": {
+ "test": "node test.js && xo"
+ },
+ "files": [
+ "index.js"
+ ],
+ "keywords": [
+ "slice",
+ "string",
+ "ansi",
+ "styles",
+ "color",
+ "colour",
+ "colors",
+ "terminal",
+ "console",
+ "cli",
+ "tty",
+ "escape",
+ "formatting",
+ "rgb",
+ "256",
+ "shell",
+ "xterm",
+ "log",
+ "logging",
+ "command-line",
+ "text"
+ ],
+ "dependencies": {},
+ "devDependencies": {
+ "ava": "^0.2.0",
+ "chalk": "^1.1.1",
+ "strip-ansi": "^3.0.0",
+ "xo": "*"
+ }
+}
diff --git a/node_modules/slice-ansi/readme.md b/node_modules/slice-ansi/readme.md
new file mode 100755
index 000000000..31be6124d
--- /dev/null
+++ b/node_modules/slice-ansi/readme.md
@@ -0,0 +1,56 @@
+# slice-ansi
+
+[![Build Status](https://travis-ci.org/vorpaljs/slice-ansi.svg?branch=master)](https://travis-ci.org/vorpaljs/slice-ansi)
+[![XO: Linted](https://img.shields.io/badge/xo-linted-blue.svg)](https://github.com/sindresorhus/xo)
+
+> Slice a string with [ANSI escape codes](http://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles)
+
+## Install
+
+```
+$ npm install --save slice-ansi
+```
+
+## Usage
+
+```js
+var chalk = require('chalk');
+var sliceAnsi = require('slice-ansi');
+
+var input = 'The quick brown ' + chalk.red('fox jumped over ') +
+ 'the lazy ' + chalk.green('dog and then ran away with the unicorn.');
+
+console.log(sliceAnsi(input, 20, 30));
+```
+
+## API
+
+### sliceAnsi(input, beginSlice[, endSlice])
+
+#### input
+
+Type: `string`
+
+String with ANSI escape codes. Like one styled by [`chalk`](https://github.com/chalk/chalk).
+
+#### beginSlice
+
+Type: `number`
+
+The zero-based index at which to begin the slice.
+
+#### endSlice
+
+Type: `number`
+
+Optional. The zero-based index at which to end the slice.
+
+
+## Related
+
+- [chalk](https://github.com/chalk/chalk) - Terminal string styling done right
+
+
+## License
+
+MIT © [David Caccavella](https://githbu.com/dthree)