Sha256: 7d88178fb35726264fa3a8500abeae44d5b585491edf3cd5b0ecf4dec1bbb299

Contents?: true

Size: 741 Bytes

Versions: 126

Compression:

Stored size: 741 Bytes

Contents

'use strict';
var stripAnsi = require('strip-ansi');
var codePointAt = require('code-point-at');
var isFullwidthCodePoint = require('is-fullwidth-code-point');

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

	var width = 0;

	str = stripAnsi(str);

	for (var i = 0; i < str.length; i++) {
		var code = codePointAt(str, 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;
};

Version data entries

126 entries across 90 versions & 18 rubygems

Version Path
cortex-0.1.3 spec/dummy/node_modules/string-width/index.js
dragonfly_puppeteer-0.1.0 node_modules/wrap-ansi/node_modules/string-width/index.js
dragonfly_puppeteer-0.1.0 node_modules/wide-align/node_modules/string-width/index.js
dragonfly_puppeteer-0.1.0 node_modules/fsevents/node_modules/string-width/index.js
dragonfly_puppeteer-0.1.0 node_modules/cli-truncate/node_modules/string-width/index.js
dragonfly_puppeteer-0.1.0 node_modules/gauge/node_modules/string-width/index.js
affiliator-0.2.1 node_modules/fsevents/node_modules/string-width/index.js
guard-sass-lint-0.1.2 node_modules/string-width/index.js
guard-sass-lint-0.1.1 node_modules/string-width/index.js
lanes-0.8.0 node_modules/string-width/index.js
lanes-0.8.0 node_modules/fsevents/node_modules/string-width/index.js
node-compiler-0.9.1 vendor/node/deps/npm/node_modules/npm-registry-client/node_modules/npmlog/node_modules/gauge/node_modules/string-width/index.js
node-compiler-0.9.1 vendor/node/deps/npm/node_modules/npmlog/node_modules/gauge/node_modules/string-width/index.js
node-compiler-0.9.1 vendor/node/deps/npm/node_modules/node-gyp/node_modules/npmlog/node_modules/gauge/node_modules/string-width/index.js
node-compiler-0.9.0 vendor/node-v7.2.1/deps/npm/node_modules/npm-registry-client/node_modules/npmlog/node_modules/gauge/node_modules/string-width/index.js
node-compiler-0.9.0 vendor/node-v7.2.1/deps/npm/node_modules/node-gyp/node_modules/npmlog/node_modules/gauge/node_modules/string-width/index.js
node-compiler-0.9.0 vendor/node-v7.2.1/deps/npm/node_modules/npmlog/node_modules/gauge/node_modules/string-width/index.js
node-compiler-0.8.0 vendor/node-v7.2.0/deps/npm/node_modules/npm-registry-client/node_modules/npmlog/node_modules/gauge/node_modules/string-width/index.js
node-compiler-0.8.0 vendor/node-v7.2.0/deps/npm/node_modules/node-gyp/node_modules/npmlog/node_modules/gauge/node_modules/string-width/index.js
node-compiler-0.8.0 vendor/node-v7.2.0/deps/npm/node_modules/npmlog/node_modules/gauge/node_modules/string-width/index.js