index.d.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. export type WidthType = 'fullwidth' | 'halfwidth' | 'wide' | 'narrow' | 'neutral' | 'ambiguous';
  2. export type Options = {
  3. /**
  4. Whether to treat an `'ambiguous'` character as wide.
  5. @default true
  6. @example
  7. ```
  8. import {eastAsianWidth} from 'get-east-asian-width';
  9. const codePoint = '⛣'.codePointAt(0);
  10. console.log(eastAsianWidth(codePoint));
  11. //=> 1
  12. console.log(eastAsianWidth(codePoint, {ambiguousAsWide: true}));
  13. //=> 2
  14. ```
  15. > Ambiguous characters behave like wide or narrow characters depending on the context (language tag, script identification, associated font, source of data, or explicit markup; all can provide the context). __If the context cannot be established reliably, they should be treated as narrow characters by default.__
  16. > - http://www.unicode.org/reports/tr11/
  17. */
  18. readonly ambiguousAsWide?: boolean;
  19. };
  20. /**
  21. Returns the width as a number for the given code point.
  22. @param codePoint - A Unicode code point.
  23. @example
  24. ```
  25. import {eastAsianWidth} from 'get-east-asian-width';
  26. const codePoint = '字'.codePointAt(0);
  27. console.log(eastAsianWidth(codePoint));
  28. //=> 2
  29. ```
  30. */
  31. export function eastAsianWidth(codePoint: number, options?: Options): 1 | 2;
  32. /**
  33. Returns the type of “East Asian Width” for the given code point.
  34. @param codePoint - A Unicode code point.
  35. @example
  36. ```
  37. import {eastAsianWidthType} from 'get-east-asian-width';
  38. const codePoint = '字'.codePointAt(0);
  39. console.log(eastAsianWidthType(codePoint));
  40. //=> 'wide'
  41. ```
  42. */
  43. export function eastAsianWidthType(codePoint: number): WidthType;