UNPKG

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