index.js 343 B

12345678910111213141516171819
  1. 'use strict';
  2. const stripAnsi = require('strip-ansi');
  3. const charRegex = require('char-regex');
  4. const stringLength = string => {
  5. if (string === '') {
  6. return 0;
  7. }
  8. const strippedString = stripAnsi(string);
  9. if (strippedString === '') {
  10. return 0;
  11. }
  12. return strippedString.match(charRegex()).length;
  13. };
  14. module.exports = stringLength;