From 14c663d512c1225e25d5907c4ef1d9bd7267a2fd Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Thu, 22 Sep 2016 13:54:10 +0700 Subject: [PATCH] ES2015ify and require Node.js 4 --- .gitattributes | 1 + .travis.yml | 2 -- index.js | 14 ++++++-------- package.json | 8 +++++--- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/.gitattributes b/.gitattributes index 176a458..391f0a4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ * text=auto +*.js text eol=lf diff --git a/.travis.yml b/.travis.yml index e526ffa..97519af 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,5 +2,3 @@ language: node_js node_js: - '6' - '4' - - '0.12' - - '0.10' diff --git a/index.js b/index.js index b9bec62..25a8943 100644 --- a/index.js +++ b/index.js @@ -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)) { diff --git a/package.json b/package.json index 5ba4361..6b4b2f4 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "url": "sindresorhus.com" }, "engines": { - "node": ">=0.10.0" + "node": ">=4" }, "scripts": { "test": "xo && ava" @@ -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 } }