[Pkg-javascript-commits] [node-string-width] 03/09: New upstream version 2.1.1

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 365e9b0bd2d244c2287b8e412ae6f28a38f91593
Author: Paolo Greppi <paolo.greppi at libpf.com>
Date:   Tue Sep 19 08:46:07 2017 +0200

    New upstream version 2.1.1
---
 .editorconfig |   2 +-
 .gitignore    |   1 +
 .npmrc        |   1 +
 .travis.yml   |   1 +
 index.js      |  23 +++++++------
 license       |  20 +++--------
 package.json  | 109 ++++++++++++++++++++++++++++------------------------------
 readme.md     |   4 +--
 test.js       |  12 ++++---
 9 files changed, 83 insertions(+), 90 deletions(-)

diff --git a/.editorconfig b/.editorconfig
index 98a761d..1c6314a 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -7,6 +7,6 @@ charset = utf-8
 trim_trailing_whitespace = true
 insert_final_newline = true
 
-[{package.json,*.yml}]
+[*.yml]
 indent_style = space
 indent_size = 2
diff --git a/.gitignore b/.gitignore
index 3c3629e..239ecff 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
 node_modules
+yarn.lock
diff --git a/.npmrc b/.npmrc
new file mode 100644
index 0000000..43c97e7
--- /dev/null
+++ b/.npmrc
@@ -0,0 +1 @@
+package-lock=false
diff --git a/.travis.yml b/.travis.yml
index 97519af..7d69d74 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,4 +1,5 @@
 language: node_js
 node_js:
+  - '8'
   - '6'
   - '4'
diff --git a/index.js b/index.js
index 25a8943..bbc49d2 100644
--- a/index.js
+++ b/index.js
@@ -7,28 +7,29 @@ module.exports = str => {
 		return 0;
 	}
 
-	let width = 0;
-
 	str = stripAnsi(str);
 
+	let width = 0;
+
 	for (let i = 0; i < str.length; i++) {
 		const code = str.codePointAt(i);
 
-		// ignore control characters
-		if (code <= 0x1f || (code >= 0x7f && code <= 0x9f)) {
+		// Ignore control characters
+		if (code <= 0x1F || (code >= 0x7F && code <= 0x9F)) {
 			continue;
 		}
 
-		// surrogates
-		if (code >= 0x10000) {
-			i++;
+		// Ignore combining characters
+		if (code >= 0x300 && code <= 0x36F) {
+			continue;
 		}
 
-		if (isFullwidthCodePoint(code)) {
-			width += 2;
-		} else {
-			width++;
+		// Surrogates
+		if (code > 0xFFFF) {
+			i++;
 		}
+
+		width += isFullwidthCodePoint(code) ? 2 : 1;
 	}
 
 	return width;
diff --git a/license b/license
index 654d0bf..e7af2f7 100644
--- a/license
+++ b/license
@@ -1,21 +1,9 @@
-The MIT License (MIT)
+MIT License
 
 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:
+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 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.
+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
index a590d2e..89f0b6a 100644
--- a/package.json
+++ b/package.json
@@ -1,58 +1,55 @@
 {
-  "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
-  }
+	"name": "string-width",
+	"version": "2.1.1",
+	"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": "^4.0.0"
+	},
+	"devDependencies": {
+		"ava": "*",
+		"xo": "*"
+	}
 }
diff --git a/readme.md b/readme.md
index 1ab42c9..df5b719 100644
--- a/readme.md
+++ b/readme.md
@@ -2,7 +2,7 @@
 
 > 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.
+Some Unicode characters are [fullwidth](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms) and use double the normal width. [ANSI escape codes](https://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.
 
@@ -10,7 +10,7 @@ Useful to be able to measure the actual width of command-line output.
 ## Install
 
 ```
-$ npm install --save string-width
+$ npm install string-width
 ```
 
 
diff --git a/test.js b/test.js
index 41081d8..a5e894b 100644
--- a/test.js
+++ b/test.js
@@ -1,5 +1,5 @@
 import test from 'ava';
-import m from './';
+import m from '.';
 
 test('main', t => {
 	t.is(m('abcde'), 5);
@@ -8,8 +8,8 @@ test('main', t => {
 	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);
+	t.is(m('A\uD83C\uDE00BC'), 5, 'surrogate');
+	t.is(m('\u001B[31m\u001B[39m'), 0);
 });
 
 test('ignores control characters', t => {
@@ -18,5 +18,9 @@ test('ignores control characters', t => {
 	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);
+	t.is(m('\u001B'), 0);
+});
+
+test('handles combining characters', t => {
+	t.is(m('x\u0300'), 1);
 });

-- 
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