d9c4f6f50e236bbf424ea6372814a6d66388c38983edfc78041b241ea9ca4704cf2de19ec454f66e12eb60da965a58a600ee90610f95af1bd15a36700610fa 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import {Value} from './index';
  2. /**
  3. * Sass's [string type](https://sass-lang.com/documentation/values/strings).
  4. *
  5. * @category Custom Function
  6. */
  7. export class SassString extends Value {
  8. /**
  9. * Creates a new string.
  10. *
  11. * @param text - The contents of the string. For quoted strings, this is the
  12. * semantic content—any escape sequences that were been written in the source
  13. * text are resolved to their Unicode values. For unquoted strings, though,
  14. * escape sequences are preserved as literal backslashes.
  15. *
  16. * @param options.quotes - Whether the string is quoted. Defaults to `true`.
  17. */
  18. constructor(
  19. text: string,
  20. options?: {
  21. quotes?: boolean;
  22. }
  23. );
  24. /**
  25. * Creates an empty string.
  26. *
  27. * @param options.quotes - Whether the string is quoted. Defaults to `true`.
  28. */
  29. constructor(options?: {quotes?: boolean});
  30. /**
  31. * The contents of the string.
  32. *
  33. * For quoted strings, this is the semantic content—any escape sequences that
  34. * were been written in the source text are resolved to their Unicode values.
  35. * For unquoted strings, though, escape sequences are preserved as literal
  36. * backslashes.
  37. *
  38. * This difference allows us to distinguish between identifiers with escapes,
  39. * such as `url\u28 http://example.com\u29`, and unquoted strings that contain
  40. * characters that aren't valid in identifiers, such as
  41. * `url(http://example.com)`. Unfortunately, it also means that we don't
  42. * consider `foo` and `f\6F\6F` the same string.
  43. */
  44. get text(): string;
  45. /** Whether this string has quotes. */
  46. get hasQuotes(): boolean;
  47. /**
  48. * Sass's notion of this string's length.
  49. *
  50. * Sass treats strings as a series of Unicode code points while JavaScript
  51. * treats them as a series of UTF-16 code units. For example, the character
  52. * U+1F60A SMILING FACE WITH SMILING EYES is a single Unicode code point but
  53. * is represented in UTF-16 as two code units (`0xD83D` and `0xDE0A`). So in
  54. * JavaScript, `"n😊b".length` returns `4`, whereas in Sass
  55. * `string.length("n😊b")` returns `3`.
  56. */
  57. get sassLength(): number;
  58. /**
  59. * Converts `sassIndex` to a JavaScript index into {@link text}.
  60. *
  61. * Sass indices are one-based, while JavaScript indices are zero-based. Sass
  62. * indices may also be negative in order to index from the end of the string.
  63. *
  64. * In addition, Sass indices refer to Unicode code points while JavaScript
  65. * string indices refer to UTF-16 code units. For example, the character
  66. * U+1F60A SMILING FACE WITH SMILING EYES is a single Unicode code point but
  67. * is represented in UTF-16 as two code units (`0xD83D` and `0xDE0A`). So in
  68. * JavaScript, `"n😊b".charCodeAt(1)` returns `0xD83D`, whereas in Sass
  69. * `string.slice("n😊b", 1, 1)` returns `"😊"`.
  70. *
  71. * This function converts Sass's code point indices to JavaScript's code unit
  72. * indices. This means it's O(n) in the length of `text`.
  73. *
  74. * @throws `Error` - If `sassIndex` isn't a number, if that number isn't an
  75. * integer, or if that integer isn't a valid index for this string.
  76. */
  77. sassIndexToStringIndex(sassIndex: Value, name?: string): number;
  78. }