aboutsummaryrefslogtreecommitdiff
path: root/node_modules/slice-ansi
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2017-08-14 05:01:11 +0200
committerFlorian Dold <florian.dold@gmail.com>2017-08-14 05:02:09 +0200
commit363723fc84f7b8477592e0105aeb331ec9a017af (patch)
tree29f92724f34131bac64d6a318dd7e30612e631c7 /node_modules/slice-ansi
parent5634e77ad96bfe1818f6b6ee70b7379652e5487f (diff)
downloadwallet-core-363723fc84f7b8477592e0105aeb331ec9a017af.tar.xz
node_modules
Diffstat (limited to 'node_modules/slice-ansi')
-rwxr-xr-xnode_modules/slice-ansi/index.js102
-rw-r--r--[-rwxr-xr-x]node_modules/slice-ansi/license31
-rw-r--r--node_modules/slice-ansi/package.json23
-rwxr-xr-xnode_modules/slice-ansi/readme.md32
4 files changed, 94 insertions, 94 deletions
diff --git a/node_modules/slice-ansi/index.js b/node_modules/slice-ansi/index.js
index c65de4d4a..634ee9c7b 100755
--- a/node_modules/slice-ansi/index.js
+++ b/node_modules/slice-ansi/index.js
@@ -1,58 +1,63 @@
'use strict';
+const isFullwidthCodePoint = require('is-fullwidth-code-point');
-var ESCAPES = [
- '\u001b',
- '\u009b'
+const ESCAPES = [
+ '\u001B',
+ '\u009B'
];
-var END_CODE = 39;
+const END_CODE = 39;
+const ASTRAL_REGEX = /[\uD800-\uDBFF][\uDC00-\uDFFF]/;
-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
-};
+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[0]}[${code}m`;
+
+module.exports = (str, begin, end) => {
+ const arr = Array.from(str.normalize());
+
+ end = typeof end === 'number' ? end : arr.length;
-function wrapAnsi(code) {
- return ESCAPES[0] + '[' + code + 'm';
-}
+ let insideEscape = false;
+ let escapeCode;
+ let visible = 0;
+ let output = '';
-module.exports = function (str, begin, end) {
- end = end || str.length;
- var insideEscape = false;
- var escapeCode;
- var visible = 0;
- var output = '';
+ for (const item of arr.entries()) {
+ const i = item[0];
+ const x = item[1];
- for (var i = 0; i < str.length; i++) {
- var leftEscape = false;
- var x = str[i];
+ let leftEscape = false;
if (ESCAPES.indexOf(x) !== -1) {
insideEscape = true;
- var code = /[0-9][^m]*/.exec(str.slice(i, i + 4));
+ const code = /\d[^m]*/.exec(str.slice(i, i + 4));
escapeCode = code === END_CODE ? null : code;
} else if (insideEscape && x === 'm') {
insideEscape = false;
@@ -63,13 +68,17 @@ module.exports = function (str, begin, end) {
++visible;
}
+ if (!ASTRAL_REGEX.test(x) && isFullwidthCodePoint(x.codePointAt())) {
+ ++visible;
+ }
+
if (visible > begin && visible <= end) {
output += x;
- } else if (visible === begin && escapeCode !== undefined && escapeCode !== END_CODE) {
+ } else if (visible === begin && !insideEscape && escapeCode !== undefined && escapeCode !== END_CODE) {
output += wrapAnsi(escapeCode);
} else if (visible >= end) {
if (escapeCode !== undefined) {
- output += wrapAnsi(ESCAPE_CODES[escapeCode] || END_CODE);
+ output += wrapAnsi(ESCAPE_CODES.get(parseInt(escapeCode, 10)) || END_CODE);
}
break;
}
@@ -77,4 +86,3 @@ module.exports = function (str, begin, end) {
return output;
};
-
diff --git a/node_modules/slice-ansi/license b/node_modules/slice-ansi/license
index 3ecaf413e..4d726339c 100755..100644
--- a/node_modules/slice-ansi/license
+++ b/node_modules/slice-ansi/license
@@ -1,22 +1,9 @@
-(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
+MIT License
+
+Copyright (c) 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.
diff --git a/node_modules/slice-ansi/package.json b/node_modules/slice-ansi/package.json
index 70bc93162..cc60b3bb3 100644
--- a/node_modules/slice-ansi/package.json
+++ b/node_modules/slice-ansi/package.json
@@ -1,6 +1,6 @@
{
"name": "slice-ansi",
- "version": "0.0.4",
+ "version": "1.0.0",
"description": "Slice a string with ANSI escape codes",
"license": "MIT",
"repository": "chalk/slice-ansi",
@@ -8,17 +8,11 @@
"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"
+ "node": ">=4"
},
"scripts": {
- "test": "node test.js && xo"
+ "test": "xo && ava"
},
"files": [
"index.js"
@@ -46,11 +40,14 @@
"command-line",
"text"
],
- "dependencies": {},
+ "dependencies": {
+ "is-fullwidth-code-point": "^2.0.0"
+ },
"devDependencies": {
- "ava": "^0.2.0",
- "chalk": "^1.1.1",
- "strip-ansi": "^3.0.0",
+ "ava": "*",
+ "chalk": "^2.0.1",
+ "random-item": "^1.0.0",
+ "strip-ansi": "^4.0.0",
"xo": "*"
}
}
diff --git a/node_modules/slice-ansi/readme.md b/node_modules/slice-ansi/readme.md
index 31be6124d..628eed2e5 100755
--- a/node_modules/slice-ansi/readme.md
+++ b/node_modules/slice-ansi/readme.md
@@ -1,31 +1,31 @@
-# slice-ansi
+# slice-ansi [![Build Status](https://travis-ci.org/chalk/slice-ansi.svg?branch=master)](https://travis-ci.org/chalk/slice-ansi) [![XO: Linted](https://img.shields.io/badge/xo-linted-blue.svg)](https://github.com/sindresorhus/xo)
-[![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](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles)
-> Slice a string with [ANSI escape codes](http://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles)
## Install
```
-$ npm install --save slice-ansi
+$ npm install slice-ansi
```
+
## Usage
```js
-var chalk = require('chalk');
-var sliceAnsi = require('slice-ansi');
+const chalk = require('chalk');
+const sliceAnsi = require('slice-ansi');
-var input = 'The quick brown ' + chalk.red('fox jumped over ') +
+const 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])
+### sliceAnsi(input, beginSlice, [endSlice])
#### input
@@ -37,20 +37,28 @@ String with ANSI escape codes. Like one styled by [`chalk`](https://github.com/c
Type: `number`
-The zero-based index at which to begin the slice.
+Zero-based index at which to begin the slice.
#### endSlice
Type: `number`
-Optional. The zero-based index at which to end the slice.
+Zero-based index at which to end the slice.
## Related
+- [wrap-ansi](https://github.com/chalk/wrap-ansi) - Wordwrap a string with ANSI escape codes
+- [cli-truncate](https://github.com/sindresorhus/cli-truncate) - Truncate a string to a specific width in the terminal
- [chalk](https://github.com/chalk/chalk) - Terminal string styling done right
+## Maintainers
+
+- [Sindre Sorhus](https://github.com/sindresorhus)
+- [Josh Junon](https://github.com/qix-)
+
+
## License
-MIT © [David Caccavella](https://githbu.com/dthree)
+MIT