aboutsummaryrefslogtreecommitdiff
path: root/node_modules/string-length/index.js
blob: c2589a2946dd3471d6b6ecea7fe94d4580753689 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
'use strict';
const stripAnsi = require('strip-ansi');
const charRegex = require('char-regex');

const stringLength = string => {
	if (string === '') {
		return 0;
	}

	const strippedString = stripAnsi(string);

	if (strippedString === '') {
		return 0;
	}

	return strippedString.match(charRegex()).length;
};

module.exports = stringLength;