UNPKG

5.54 kBTypeScriptView Raw
1import {List, ValueObject} from 'immutable';
2
3import {SassBoolean} from './boolean';
4import {SassColor} from './color';
5import {SassFunction} from './function';
6import {ListSeparator} from './list';
7import {SassMap} from './map';
8import {SassNumber} from './number';
9import {SassString} from './string';
10
11export {SassArgumentList} from './argument_list';
12export {SassBoolean, sassTrue, sassFalse} from './boolean';
13export {SassColor} from './color';
14export {SassFunction} from './function';
15export {SassList, ListSeparator} from './list';
16export {SassMap} from './map';
17export {SassNumber} from './number';
18export {SassString} from './string';
19
20/**
21 * Sass's [`null` value](https://sass-lang.com/documentation/values/null).
22 *
23 * @category Custom Function
24 */
25export const sassNull: Value;
26
27/**
28 * The abstract base class of Sass's value types.
29 *
30 * This is passed to and returned by [[CustomFunction]]s, which are passed into
31 * the Sass implementation using [[Options.functions]].
32 *
33 * @category Custom Function
34 */
35export abstract class Value implements ValueObject {
36 protected constructor();
37
38 /**
39 * This value as a list.
40 *
41 * All SassScript values can be used as lists. Maps count as lists of pairs,
42 * and all other values count as single-value lists.
43 *
44 * @returns An immutable [[List]] from the [`immutable`
45 * package](https://immutable-js.com/).
46 */
47 get asList(): List<Value>;
48
49 /**
50 * Whether this value as a list has brackets.
51 *
52 * All SassScript values can be used as lists. Maps count as lists of pairs,
53 * and all other values count as single-value lists.
54 */
55 get hasBrackets(): boolean;
56
57 /**
58 * Whether the value counts as `true` in an `@if` statement and other
59 * contexts.
60 */
61 get isTruthy(): boolean;
62
63 /**
64 * Returns JavaScript's `null` value if this is [[sassNull]], and returns
65 * `this` otherwise.
66 */
67 get realNull(): null | Value;
68
69 /**
70 * The separator for this value as a list.
71 *
72 * All SassScript values can be used as lists. Maps count as lists of pairs,
73 * and all other values count as single-value lists.
74 */
75 get separator(): ListSeparator;
76
77 /**
78 * Converts `sassIndex` into a JavaScript-style index into the list returned
79 * by [[asList]].
80 *
81 * Sass indexes are one-based, while JavaScript indexes are zero-based. Sass
82 * indexes may also be negative in order to index from the end of the list.
83 *
84 * @param sassIndex - The Sass-style index into this as a list.
85 * @param name - The name of the function argument `sassIndex` came from
86 * (without the `$`) if it came from an argument. Used for error reporting.
87 * @throws `Error` If `sassIndex` isn't a number, if that number isn't an
88 * integer, or if that integer isn't a valid index for [[asList]].
89 */
90 sassIndexToListIndex(sassIndex: Value, name?: string): number;
91
92 /**
93 * Returns the value at index `index` in this value as a list, or `undefined`
94 * if `index` isn't valid for this list.
95 *
96 * All SassScript values can be used as lists. Maps count as lists of pairs,
97 * and all other values count as single-value lists.
98 *
99 * This is a shorthand for `this.asList.get(index)`, although it may be more
100 * efficient in some cases.
101 *
102 * **Heads up!** This method uses the same indexing conventions as the
103 * `immutable` package: unlike Sass the index of the first element is 0, but
104 * like Sass negative numbers index from the end of the list.
105 */
106 get(index: number): Value | undefined;
107
108 /**
109 * Throws if `this` isn't a [[SassBoolean]].
110 *
111 * **Heads up!** Functions should generally use [[isTruthy]] rather than
112 * requiring a literal boolean.
113 *
114 * @param name - The name of the function argument `this` came from (without
115 * the `$`) if it came from an argument. Used for error reporting.
116 */
117 assertBoolean(name?: string): SassBoolean;
118
119 /**
120 * Throws if `this` isn't a [[SassColor]].
121 *
122 * @param name - The name of the function argument `this` came from (without
123 * the `$`) if it came from an argument. Used for error reporting.
124 */
125 assertColor(name?: string): SassColor;
126
127 /**
128 * Throws if `this` isn't a [[SassFunction]].
129 *
130 * @param name - The name of the function argument `this` came from (without
131 * the `$`) if it came from an argument. Used for error reporting.
132 */
133 assertFunction(name?: string): SassFunction;
134
135 /**
136 * Throws if `this` isn't a [[SassMap]].
137 *
138 * @param name - The name of the function argument `this` came from (without
139 * the `$`) if it came from an argument. Used for error reporting.
140 */
141 assertMap(name?: string): SassMap;
142
143 /**
144 * Throws if `this` isn't a [[SassNumber]].
145 *
146 * @param name - The name of the function argument `this` came from (without
147 * the `$`) if it came from an argument. Used for error reporting.
148 */
149 assertNumber(name?: string): SassNumber;
150
151 /**
152 * Throws if `this` isn't a [[SassString]].
153 *
154 * @param name - The name of the function argument `this` came from (without
155 * the `$`) if it came from an argument. Used for error reporting.
156 */
157 assertString(name?: string): SassString;
158
159 /**
160 * Returns `this` as a map if it counts as one (empty lists count as empty
161 * maps) or `null` if it doesn't.
162 */
163 tryMap(): SassMap | null;
164
165 /** Returns whether `this` represents the same value as `other`. */
166 equals(other: Value): boolean;
167
168 /** Returns a hash code that can be used to store `this` in a hash map. */
169 hashCode(): number;
170
171 /** @hidden */
172 toString(): string;
173}
174
\No newline at end of file