Skip to content

Commit

Permalink
ES2015ify and require Node.js 4
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Sep 22, 2016
1 parent 282cf3d commit 14c663d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* text=auto
*.js text eol=lf
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ language: node_js
node_js:
- '6'
- '4'
- '0.12'
- '0.10'
14 changes: 6 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
'use strict';
var stripAnsi = require('strip-ansi');
var codePointAt = require('code-point-at');
var isFullwidthCodePoint = require('is-fullwidth-code-point');
const stripAnsi = require('strip-ansi');
const isFullwidthCodePoint = require('is-fullwidth-code-point');

// https://github.com/nodejs/io.js/blob/cff7300a578be1b10001f2d967aaedc88aee6402/lib/readline.js#L1345
module.exports = function (str) {
module.exports = str => {
if (typeof str !== 'string' || str.length === 0) {
return 0;
}

var width = 0;
let width = 0;

str = stripAnsi(str);

for (var i = 0; i < str.length; i++) {
var code = codePointAt(str, i);
for (let i = 0; i < str.length; i++) {
const code = str.codePointAt(i);

// ignore control characters
if (code <= 0x1f || (code >= 0x7f && code <= 0x9f)) {
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"url": "sindresorhus.com"
},
"engines": {
"node": ">=0.10.0"
"node": ">=4"
},
"scripts": {
"test": "xo && ava"
Expand Down Expand Up @@ -45,12 +45,14 @@
"fixed-width"
],
"dependencies": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
"is-fullwidth-code-point": "^2.0.0",
"strip-ansi": "^3.0.0"
},
"devDependencies": {
"ava": "*",
"xo": "*"
},
"xo": {
"esnext": true
}
}

0 comments on commit 14c663d

Please sign in to comment.