index.d.ts 792 B

1234567891011121314151617181920212223242526272829
  1. declare const stringWidth: {
  2. /**
  3. Get the visual width of a string - the number of columns required to display it.
  4. Some Unicode characters are [fullwidth](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms) and use double the normal width. [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) are stripped and doesn't affect the width.
  5. @example
  6. ```
  7. import stringWidth = require('string-width');
  8. stringWidth('a');
  9. //=> 1
  10. stringWidth('古');
  11. //=> 2
  12. stringWidth('\u001B[1m古\u001B[22m');
  13. //=> 2
  14. ```
  15. */
  16. (string: string): number;
  17. // TODO: remove this in the next major version, refactor the whole definition to:
  18. // declare function stringWidth(string: string): number;
  19. // export = stringWidth;
  20. default: typeof stringWidth;
  21. }
  22. export = stringWidth;