[Pkg-javascript-commits] [node-string-width] 01/09: Import Upstream version 2.0.0

Paolo Greppi paolog-guest at moszumanska.debian.org
Mon Oct 30 09:48:28 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-string-width.

commit c9354caf8f967a81ce9d2ce78c2d3f47d358774a
Author: Paolo Greppi <paolo.greppi at libpf.com>
Date:   Tue Sep 19 08:41:54 2017 +0200

    Import Upstream version 2.0.0
---
 .editorconfig  | 12 ++++++++++++
 .gitattributes |  2 ++
 .gitignore     |  1 +
 .travis.yml    |  4 ++++
 index.js       | 35 +++++++++++++++++++++++++++++++++++
 license        | 21 +++++++++++++++++++++
 package.json   | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 readme.md      | 42 ++++++++++++++++++++++++++++++++++++++++++
 test.js        | 22 ++++++++++++++++++++++
 9 files changed, 197 insertions(+)

diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..98a761d
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,12 @@
+root = true
+
+[*]
+indent_style = tab
+end_of_line = lf
+charset = utf-8
+trim_trailing_whitespace = true
+insert_final_newline = true
+
+[{package.json,*.yml}]
+indent_style = space
+indent_size = 2
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..391f0a4
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,2 @@
+* text=auto
+*.js text eol=lf
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3c3629e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+node_modules
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..97519af
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,4 @@
+language: node_js
+node_js:
+  - '6'
+  - '4'
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..25a8943
--- /dev/null
+++ b/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/license b/license
new file mode 100644
index 0000000..654d0bf
--- /dev/null
+++ b/license
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+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:
+
+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/package.json b/package.json
new file mode 100644
index 0000000..a590d2e
--- /dev/null
+++ b/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 at 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/readme.md b/readme.md
new file mode 100644
index 0000000..1ab42c9
--- /dev/null
+++ b/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/test.js b/test.js
new file mode 100644
index 0000000..41081d8
--- /dev/null
+++ b/test.js
@@ -0,0 +1,22 @@
+import test from 'ava';
+import m from './';
+
+test('main', t => {
+	t.is(m('abcde'), 5);
+	t.is(m('古池や'), 6);
+	t.is(m('あいうabc'), 9);
+	t.is(m('ノード.js'), 9);
+	t.is(m('你好'), 4);
+	t.is(m('안녕하세요'), 10);
+	t.is(m('A\ud83c\ude00BC'), 5, 'surrogate');
+	t.is(m('\u001b[31m\u001b[39m'), 0);
+});
+
+test('ignores control characters', t => {
+	t.is(m(String.fromCharCode(0)), 0);
+	t.is(m(String.fromCharCode(31)), 0);
+	t.is(m(String.fromCharCode(127)), 0);
+	t.is(m(String.fromCharCode(134)), 0);
+	t.is(m(String.fromCharCode(159)), 0);
+	t.is(m('\u001b'), 0);
+});

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



More information about the Pkg-javascript-commits mailing list