string-width
Advanced tools
+8
-5
| 'use strict'; | ||
| const stripAnsi = require('strip-ansi'); | ||
| const isFullwidthCodePoint = require('is-fullwidth-code-point'); | ||
| const emojiRegex = require('emoji-regex')(); | ||
| module.exports = str => { | ||
| if (typeof str !== 'string' || str.length === 0) { | ||
| module.exports = input => { | ||
| input = input.replace(emojiRegex, ' '); | ||
| if (typeof input !== 'string' || input.length === 0) { | ||
| return 0; | ||
| } | ||
| str = stripAnsi(str); | ||
| input = stripAnsi(input); | ||
| let width = 0; | ||
| for (let i = 0; i < str.length; i++) { | ||
| const code = str.codePointAt(i); | ||
| for (let i = 0; i < input.length; i++) { | ||
| const code = input.codePointAt(i); | ||
@@ -17,0 +20,0 @@ // Ignore control characters |
+6
-5
| { | ||
| "name": "string-width", | ||
| "version": "2.1.1", | ||
| "version": "3.0.0", | ||
| "description": "Get the visual width of a string - the number of columns required to display it", | ||
@@ -13,3 +13,3 @@ "license": "MIT", | ||
| "engines": { | ||
| "node": ">=4" | ||
| "node": ">=6" | ||
| }, | ||
@@ -49,9 +49,10 @@ "scripts": { | ||
| "dependencies": { | ||
| "emoji-regex": "^7.0.1", | ||
| "is-fullwidth-code-point": "^2.0.0", | ||
| "strip-ansi": "^4.0.0" | ||
| "strip-ansi": "^5.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "ava": "*", | ||
| "xo": "*" | ||
| "ava": "^1.0.1", | ||
| "xo": "^0.23.0" | ||
| } | ||
| } |
3928
3.7%29
7.41%3
50%+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
Updated