aboutsummaryrefslogtreecommitdiff
path: root/node_modules/cli-truncate
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/cli-truncate
parent963b7a41feb29cc4be090a2446bdfe0c1f1bcd81 (diff)
add linting (and some initial fixes)
Diffstat (limited to 'node_modules/cli-truncate')
-rw-r--r--node_modules/cli-truncate/index.js45
-rw-r--r--node_modules/cli-truncate/license21
-rw-r--r--node_modules/cli-truncate/node_modules/is-fullwidth-code-point/index.js46
-rw-r--r--node_modules/cli-truncate/node_modules/is-fullwidth-code-point/license21
-rw-r--r--node_modules/cli-truncate/node_modules/is-fullwidth-code-point/package.json45
-rw-r--r--node_modules/cli-truncate/node_modules/is-fullwidth-code-point/readme.md39
-rw-r--r--node_modules/cli-truncate/node_modules/string-width/index.js35
-rw-r--r--node_modules/cli-truncate/node_modules/string-width/license21
-rw-r--r--node_modules/cli-truncate/node_modules/string-width/package.json58
-rw-r--r--node_modules/cli-truncate/node_modules/string-width/readme.md42
-rw-r--r--node_modules/cli-truncate/package.json42
-rw-r--r--node_modules/cli-truncate/readme.md77
12 files changed, 492 insertions, 0 deletions
diff --git a/node_modules/cli-truncate/index.js b/node_modules/cli-truncate/index.js
new file mode 100644
index 000000000..5f8b831c9
--- /dev/null
+++ b/node_modules/cli-truncate/index.js
@@ -0,0 +1,45 @@
+'use strict';
+const sliceAnsi = require('slice-ansi');
+const stringWidth = require('string-width');
+
+module.exports = (input, columns, opts) => {
+ opts = Object.assign({
+ position: 'end'
+ }, opts);
+
+ const position = opts.position;
+ const ellipsis = '…';
+
+ if (typeof input !== 'string') {
+ throw new TypeError(`Expected \`input\` to be a string, got ${typeof input}`);
+ }
+
+ if (typeof columns !== 'number') {
+ throw new TypeError(`Expected \`columns\` to be a number, got ${typeof columns}`);
+ }
+
+ if (columns < 1) {
+ return '';
+ }
+
+ if (columns === 1) {
+ return ellipsis;
+ }
+
+ const length = stringWidth(input);
+
+ if (length <= columns) {
+ return input;
+ }
+
+ if (position === 'start') {
+ return ellipsis + sliceAnsi(input, length - columns + 1, length);
+ } else if (position === 'middle') {
+ const half = Math.floor(columns / 2);
+ return sliceAnsi(input, 0, half) + ellipsis + sliceAnsi(input, length - (columns - half) + 1, length);
+ } else if (position === 'end') {
+ return sliceAnsi(input, 0, columns - 1) + ellipsis;
+ }
+
+ throw new Error(`Expected \`options.position\` to be either \`start\`, \`middle\` or \`end\`, got ${position}`);
+};
diff --git a/node_modules/cli-truncate/license b/node_modules/cli-truncate/license
new file mode 100644
index 000000000..654d0bfe9
--- /dev/null
+++ b/node_modules/cli-truncate/license
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) Sindre Sorhus <sindresorhus@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:
+
+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/cli-truncate/node_modules/is-fullwidth-code-point/index.js b/node_modules/cli-truncate/node_modules/is-fullwidth-code-point/index.js
new file mode 100644
index 000000000..d506327c3
--- /dev/null
+++ b/node_modules/cli-truncate/node_modules/is-fullwidth-code-point/index.js
@@ -0,0 +1,46 @@
+'use strict';
+/* eslint-disable yoda */
+module.exports = x => {
+ if (Number.isNaN(x)) {
+ return false;
+ }
+
+ // code points are derived from:
+ // http://www.unix.org/Public/UNIDATA/EastAsianWidth.txt
+ if (
+ x >= 0x1100 && (
+ x <= 0x115f || // Hangul Jamo
+ x === 0x2329 || // LEFT-POINTING ANGLE BRACKET
+ x === 0x232a || // RIGHT-POINTING ANGLE BRACKET
+ // CJK Radicals Supplement .. Enclosed CJK Letters and Months
+ (0x2e80 <= x && x <= 0x3247 && x !== 0x303f) ||
+ // Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A
+ (0x3250 <= x && x <= 0x4dbf) ||
+ // CJK Unified Ideographs .. Yi Radicals
+ (0x4e00 <= x && x <= 0xa4c6) ||
+ // Hangul Jamo Extended-A
+ (0xa960 <= x && x <= 0xa97c) ||
+ // Hangul Syllables
+ (0xac00 <= x && x <= 0xd7a3) ||
+ // CJK Compatibility Ideographs
+ (0xf900 <= x && x <= 0xfaff) ||
+ // Vertical Forms
+ (0xfe10 <= x && x <= 0xfe19) ||
+ // CJK Compatibility Forms .. Small Form Variants
+ (0xfe30 <= x && x <= 0xfe6b) ||
+ // Halfwidth and Fullwidth Forms
+ (0xff01 <= x && x <= 0xff60) ||
+ (0xffe0 <= x && x <= 0xffe6) ||
+ // Kana Supplement
+ (0x1b000 <= x && x <= 0x1b001) ||
+ // Enclosed Ideographic Supplement
+ (0x1f200 <= x && x <= 0x1f251) ||
+ // CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane
+ (0x20000 <= x && x <= 0x3fffd)
+ )
+ ) {
+ return true;
+ }
+
+ return false;
+};
diff --git a/node_modules/cli-truncate/node_modules/is-fullwidth-code-point/license b/node_modules/cli-truncate/node_modules/is-fullwidth-code-point/license
new file mode 100644
index 000000000..654d0bfe9
--- /dev/null
+++ b/node_modules/cli-truncate/node_modules/is-fullwidth-code-point/license
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) Sindre Sorhus <sindresorhus@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:
+
+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/cli-truncate/node_modules/is-fullwidth-code-point/package.json b/node_modules/cli-truncate/node_modules/is-fullwidth-code-point/package.json
new file mode 100644
index 000000000..3049d9e03
--- /dev/null
+++ b/node_modules/cli-truncate/node_modules/is-fullwidth-code-point/package.json
@@ -0,0 +1,45 @@
+{
+ "name": "is-fullwidth-code-point",
+ "version": "2.0.0",
+ "description": "Check if the character represented by a given Unicode code point is fullwidth",
+ "license": "MIT",
+ "repository": "sindresorhus/is-fullwidth-code-point",
+ "author": {
+ "name": "Sindre Sorhus",
+ "email": "sindresorhus@gmail.com",
+ "url": "sindresorhus.com"
+ },
+ "engines": {
+ "node": ">=4"
+ },
+ "scripts": {
+ "test": "xo && ava"
+ },
+ "files": [
+ "index.js"
+ ],
+ "keywords": [
+ "fullwidth",
+ "full-width",
+ "full",
+ "width",
+ "unicode",
+ "character",
+ "char",
+ "string",
+ "str",
+ "codepoint",
+ "code",
+ "point",
+ "is",
+ "detect",
+ "check"
+ ],
+ "devDependencies": {
+ "ava": "*",
+ "xo": "*"
+ },
+ "xo": {
+ "esnext": true
+ }
+}
diff --git a/node_modules/cli-truncate/node_modules/is-fullwidth-code-point/readme.md b/node_modules/cli-truncate/node_modules/is-fullwidth-code-point/readme.md
new file mode 100644
index 000000000..093b0281b
--- /dev/null
+++ b/node_modules/cli-truncate/node_modules/is-fullwidth-code-point/readme.md
@@ -0,0 +1,39 @@
+# is-fullwidth-code-point [![Build Status](https://travis-ci.org/sindresorhus/is-fullwidth-code-point.svg?branch=master)](https://travis-ci.org/sindresorhus/is-fullwidth-code-point)
+
+> Check if the character represented by a given [Unicode code point](https://en.wikipedia.org/wiki/Code_point) is [fullwidth](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms)
+
+
+## Install
+
+```
+$ npm install --save is-fullwidth-code-point
+```
+
+
+## Usage
+
+```js
+const isFullwidthCodePoint = require('is-fullwidth-code-point');
+
+isFullwidthCodePoint('谢'.codePointAt());
+//=> true
+
+isFullwidthCodePoint('a'.codePointAt());
+//=> false
+```
+
+
+## API
+
+### isFullwidthCodePoint(input)
+
+#### input
+
+Type: `number`
+
+[Code point](https://en.wikipedia.org/wiki/Code_point) of a character.
+
+
+## License
+
+MIT © [Sindre Sorhus](https://sindresorhus.com)
diff --git a/node_modules/cli-truncate/node_modules/string-width/index.js b/node_modules/cli-truncate/node_modules/string-width/index.js
new file mode 100644
index 000000000..25a8943c1
--- /dev/null
+++ b/node_modules/cli-truncate/node_modules/string-width/index.js
@@ -0,0 +1,35 @@
+'use strict';
+const stripAnsi = require('strip-ansi');
+const isFullwidthCodePoint = require('is-fullwidth-code-point');
+
+module.exports = str => {
+ if (typeof str !== 'string' || str.length === 0) {
+ return 0;
+ }
+
+ let width = 0;
+
+ str = stripAnsi(str);
+
+ for (let i = 0; i < str.length; i++) {
+ const code = str.codePointAt(i);
+
+ // ignore control characters
+ if (code <= 0x1f || (code >= 0x7f && code <= 0x9f)) {
+ continue;
+ }
+
+ // surrogates
+ if (code >= 0x10000) {
+ i++;
+ }
+
+ if (isFullwidthCodePoint(code)) {
+ width += 2;
+ } else {
+ width++;
+ }
+ }
+
+ return width;
+};
diff --git a/node_modules/cli-truncate/node_modules/string-width/license b/node_modules/cli-truncate/node_modules/string-width/license
new file mode 100644
index 000000000..654d0bfe9
--- /dev/null
+++ b/node_modules/cli-truncate/node_modules/string-width/license
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) Sindre Sorhus <sindresorhus@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:
+
+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/cli-truncate/node_modules/string-width/package.json b/node_modules/cli-truncate/node_modules/string-width/package.json
new file mode 100644
index 000000000..a590d2e0b
--- /dev/null
+++ b/node_modules/cli-truncate/node_modules/string-width/package.json
@@ -0,0 +1,58 @@
+{
+ "name": "string-width",
+ "version": "2.0.0",
+ "description": "Get the visual width of a string - the number of columns required to display it",
+ "license": "MIT",
+ "repository": "sindresorhus/string-width",
+ "author": {
+ "name": "Sindre Sorhus",
+ "email": "sindresorhus@gmail.com",
+ "url": "sindresorhus.com"
+ },
+ "engines": {
+ "node": ">=4"
+ },
+ "scripts": {
+ "test": "xo && ava"
+ },
+ "files": [
+ "index.js"
+ ],
+ "keywords": [
+ "string",
+ "str",
+ "character",
+ "char",
+ "unicode",
+ "width",
+ "visual",
+ "column",
+ "columns",
+ "fullwidth",
+ "full-width",
+ "full",
+ "ansi",
+ "escape",
+ "codes",
+ "cli",
+ "command-line",
+ "terminal",
+ "console",
+ "cjk",
+ "chinese",
+ "japanese",
+ "korean",
+ "fixed-width"
+ ],
+ "dependencies": {
+ "is-fullwidth-code-point": "^2.0.0",
+ "strip-ansi": "^3.0.0"
+ },
+ "devDependencies": {
+ "ava": "*",
+ "xo": "*"
+ },
+ "xo": {
+ "esnext": true
+ }
+}
diff --git a/node_modules/cli-truncate/node_modules/string-width/readme.md b/node_modules/cli-truncate/node_modules/string-width/readme.md
new file mode 100644
index 000000000..1ab42c935
--- /dev/null
+++ b/node_modules/cli-truncate/node_modules/string-width/readme.md
@@ -0,0 +1,42 @@
+# string-width [![Build Status](https://travis-ci.org/sindresorhus/string-width.svg?branch=master)](https://travis-ci.org/sindresorhus/string-width)
+
+> Get the visual width of a string - the number of columns required to display it
+
+Some Unicode characters are [fullwidth](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms) and use double the normal width. [ANSI escape codes](http://en.wikipedia.org/wiki/ANSI_escape_code) are stripped and doesn't affect the width.
+
+Useful to be able to measure the actual width of command-line output.
+
+
+## Install
+
+```
+$ npm install --save string-width
+```
+
+
+## Usage
+
+```js
+const stringWidth = require('string-width');
+
+stringWidth('古');
+//=> 2
+
+stringWidth('\u001b[1m古\u001b[22m');
+//=> 2
+
+stringWidth('a');
+//=> 1
+```
+
+
+## Related
+
+- [string-width-cli](https://github.com/sindresorhus/string-width-cli) - CLI for this module
+- [string-length](https://github.com/sindresorhus/string-length) - Get the real length of a string
+- [widest-line](https://github.com/sindresorhus/widest-line) - Get the visual width of the widest line in a string
+
+
+## License
+
+MIT © [Sindre Sorhus](https://sindresorhus.com)
diff --git a/node_modules/cli-truncate/package.json b/node_modules/cli-truncate/package.json
new file mode 100644
index 000000000..2db1f989a
--- /dev/null
+++ b/node_modules/cli-truncate/package.json
@@ -0,0 +1,42 @@
+{
+ "name": "cli-truncate",
+ "version": "1.0.0",
+ "description": "Truncate a string to a specific width in the terminal",
+ "license": "MIT",
+ "repository": "sindresorhus/cli-truncate",
+ "author": {
+ "name": "Sindre Sorhus",
+ "email": "sindresorhus@gmail.com",
+ "url": "sindresorhus.com"
+ },
+ "engines": {
+ "node": ">=4"
+ },
+ "scripts": {
+ "test": "xo && ava"
+ },
+ "files": [
+ "index.js"
+ ],
+ "keywords": [
+ "truncate",
+ "ellipsis",
+ "text",
+ "limit",
+ "slice",
+ "cli",
+ "terminal",
+ "term",
+ "shell",
+ "width",
+ "ansi"
+ ],
+ "dependencies": {
+ "slice-ansi": "0.0.4",
+ "string-width": "^2.0.0"
+ },
+ "devDependencies": {
+ "ava": "*",
+ "xo": "*"
+ }
+}
diff --git a/node_modules/cli-truncate/readme.md b/node_modules/cli-truncate/readme.md
new file mode 100644
index 000000000..72ae44a35
--- /dev/null
+++ b/node_modules/cli-truncate/readme.md
@@ -0,0 +1,77 @@
+# cli-truncate [![Build Status](https://travis-ci.org/sindresorhus/cli-truncate.svg?branch=master)](https://travis-ci.org/sindresorhus/cli-truncate)
+
+> Truncate a string to a specific width in the terminal
+
+Gracefully handles [ANSI escapes](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles). Like a string styled with [`chalk`](https://github.com/chalk/chalk).
+
+
+## Install
+
+```
+$ npm install --save cli-truncate
+```
+
+
+## Usage
+
+```js
+const cliTruncate = require('cli-truncate');
+
+cliTruncate('unicorn', 4);
+//=> 'uni…'
+
+// Truncate at different positions
+cliTruncate('unicorn', 4, {position: 'start'});
+//=> '…orn'
+
+cliTruncate('unicorn', 4, {position: 'middle'});
+//=> 'un…n'
+
+cliTruncate('\u001b[31municorn\u001b[39m', 4);
+//=> '\u001b[31muni\u001b[39m…'
+
+// Truncate the paragraph to the terminal width
+const paragraph = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa.';
+cliTruncate(paragraph, process.stdout.columns));
+//=> 'Lorem ipsum dolor sit amet, consectetuer adipiscing…'
+```
+
+
+## API
+
+### cliTruncate(input, columns, [options])
+
+#### input
+
+Type: `string`
+
+Text to truncate.
+
+#### columns
+
+Type: `number`
+
+Columns to occupy in the terminal.
+
+#### options
+
+Type: `Object`
+
+##### position
+
+Type: `string`<br>
+Default: `'end'`<br>
+Values: `'start'`, `'middle'`, `'end'`
+
+Position to truncate the string.
+
+
+## Related
+
+- [wrap-ansi](https://github.com/chalk/wrap-ansi) - Wordwrap a string with ANSI escape codes
+- [slice-ansi](https://github.com/chalk/slice-ansi) - Slice a string with ANSI escape codes
+
+
+## License
+
+MIT © [Sindre Sorhus](https://sindresorhus.com)