Skip to content

Commit

Permalink
Improve performance by performing an early exit (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Feb 26, 2021
1 parent 5ad02fe commit a9fc011
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion index.js
Expand Up @@ -4,9 +4,13 @@ const isFullwidthCodePoint = require('is-fullwidth-code-point');
const emojiRegex = require('emoji-regex');

const stringWidth = string => {
if (typeof string !== 'string' || string.length === 0) {
return 0;
}

string = string.replace(emojiRegex(), ' ');

if (typeof string !== 'string' || string.length === 0) {
if (string.length === 0) {
return 0;
}

Expand Down

0 comments on commit a9fc011

Please sign in to comment.