SassValue
public class SassValue: Hashable, Sequence, CustomStringConvertible, Sendable
Common behavior between values passed to or returned from Sass functions.
All Sass values can be treated as lists: singleton values like strings behave like
1-element lists and maps behave like lists of two-element (key, value) lists. Use the
SequenceSequence conformance to access the list contents.
SassValue is abstract, you cannot create instances. Instead create instances of subtypes
like SassColor.
All the SassValue types have value semantics and are almost all entirely immutable: the
only mutability is to do with caching of derived properties.
Topics
Sass properties
var isNull: Bool
var isNull: Bool
var isTruthy: Bool
var isTruthy: Bool
Downcasts
func asString() -> SassString
func asString() -> SassString
Reinterpret the value as a string.
Declaration
public func asString() throws -> SassString
Throws
SassFunctionError.wrongType(...) if it isn’t a string.
func asNumber() -> SassNumber
func asNumber() -> SassNumber
Reinterpret the value as a number.
Declaration
public func asNumber() throws -> SassNumber
Throws
SassFunctionError.wrongType(...) if it isn’t a number.
func asColor() -> SassColor
func asColor() -> SassColor
Reinterpret the value as a color.
Declaration
public func asColor() throws -> SassColor
Throws
SassFunctionError.wrongType(...) if it isn’t a color.
func asBool() -> SassBool
func asBool() -> SassBool
Reinterpret the value as a boolean. But see isTruthy: you almost always don’t
want to be using this.
Declaration
public func asBool() throws -> SassBool
Throws
SassFunctionError.wrongType(...) if it isn’t a boolean.
func asMap() -> SassMap
func asMap() -> SassMap
Reinterpret the value as a map. Empty lists are reinterpreted as the empty map.
Declaration
public func asMap() throws -> SassMap
Throws
SassFunctionError.wrongType(...) if it isn’t a map or empty list.
func asArgumentList() -> SassArgumentList
func asArgumentList() -> SassArgumentList
Reinterpret the value as an argument list.
Declaration
public func asArgumentList() throws -> SassArgumentList
Throws
SassFunctionError.wrongType(...) if it isn’t an argument list.
func asCompilerFunction() -> SassCompilerFunction
func asCompilerFunction() -> SassCompilerFunction
Reinterpret the value as a compiler function.
Declaration
public func asCompilerFunction() throws -> SassCompilerFunction
Throws
SassFunctionError.wrongType(...) if it isn’t a compiler function.
func asDynamicFunction() -> SassDynamicFunction
func asDynamicFunction() -> SassDynamicFunction
Reinterpret the value as a dynamic function.
Declaration
public func asDynamicFunction() throws -> SassDynamicFunction
Throws
SassFunctionError.wrongType(...) if it isn’t a compiler function.
func asCalculation() -> SassCalculation
func asCalculation() -> SassCalculation
Reinterpret the value as a calculation.
Declaration
public func asCalculation() throws -> SassCalculation
Throws
SassFunctionError.wrongType(...) if it isn’t a calculation.
Sass listiness
var listCount: Int
var listCount: Int
The number of values in this value viewed as a list.
Declaration
public var listCount: Int { get }
func arrayIndexFrom(sassIndex: SassValue) -> Int
func arrayIndexFrom(sassIndex: SassValue) -> Int
Convert a Sass list index.
Declaration
Parameters
index |
A Sass value intended to be used as an index into this value viewed as a list. This must be an integer between 1 and the number of elements inclusive, or negative in the same range to index from the end. |
Throws
SassFunctionError if sassIndex is not an integer or out of range.
Return Value
An integer suitable for subscripting the array created from this value, guaranteed to be a valid subscript in the range [0..<count]
func valueAt(sassIndex: SassValue) -> SassValue
func valueAt(sassIndex: SassValue) -> SassValue
Subscript the value using a Sass list index.
(Swift can’t throw exceptions from subscript).
Declaration
Parameters
sassIndex |
A Sass value intended to be used as an index into this value viewed as a list. This must be an integer between 1 and the number of elements inclusive, or a negative number with similar magnitude to index back from the end. |
Throws
SassFunctionError if sassIndex is not an integer or out of range.
Return Value
The value at the Sass index.
var hasBrackets: Bool
var hasBrackets: Bool
Is this value, viewed as a list, surrounded by brackets?
Declaration
public var hasBrackets: Bool { get }
var separator: SassList.Separator
var separator: SassList.Separator
The list separator used by this value when viewed as a list.
Declaration
public var separator: SassList.Separator { get }
Misc
static func ==(lhs: SassValue, rhs: SassValue) -> Bool
static func ==(lhs: SassValue, rhs: SassValue) -> Bool
func accept<V, R>(visitor: V) -> R
func accept<V, R>(visitor: V) -> R
Call the corresponding method of visitor against this object.
Declaration
public func accept<V, R>(visitor: V) throws -> R
where V: SassValueVisitor, R == V.ReturnType
func hash(into: inout Hasher)
func hash(into: inout Hasher)
func makeIterator() -> AnyIterator<SassValue>
func makeIterator() -> AnyIterator<SassValue>
Declaration
public func makeIterator() -> AnyIterator<SassValue>
var description: String
var description: String
Other Definitions
func asMixin() -> SassMixin
func asMixin() -> SassMixin
Reinterpret the value as a mixin.
Declaration
public func asMixin() throws -> SassMixin
Throws
SassFunctionError.wrongType(...) if it isn’t a mixin.