UNPKG

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