SassString
Sass'sstring type.
Hierarchy
- Value
- SassString
- Defined injs-api-doc/value/string.d.ts:8
Constructors
constructor
- new
Sass String(text:string,options?:{
quotes?:boolean;
}):SassString Creates a new string.
Parameters
text:string
The contents of the string. For quoted strings, this is thesemantic content—any escape sequences that were been written in the sourcetext are resolved to their Unicode values. For unquoted strings, though,escape sequences are preserved as literal backslashes.
Optional
options:{
quotes?:boolean;
}Optional
quotes?:booleanWhether the string is quoted. Defaults to
true
.
ReturnsSassString
OverridesValue.constructor
- Defined injs-api-doc/value/string.d.ts:19
constructor
- new
Sass String(options?:{
quotes?:boolean;
}):SassString Creates an empty string.
Parameters
Optional
options:{
quotes?:boolean;
}Optional
quotes?:booleanWhether the string is quoted. Defaults to
true
.
ReturnsSassString
Overrides Value.constructor
- Defined injs-api-doc/value/string.d.ts:31
Accessors
as List
- get asList():List<Value>
This value as a list.
All SassScript values can be used as lists. Maps count as lists of pairs,and all other values count as single-value lists.
ReturnsList<Value>
An immutable List from the
immutable
package.Inherited from Value.asList
- Defined injs-api-doc/value/index.d.ts:77
has Brackets
- get hasBrackets():boolean
Whether this value as a list has brackets.
All SassScript values can be used as lists. Maps count as lists of pairs,and all other values count as single-value lists.
Returnsboolean
Inherited from Value.hasBrackets
- Defined injs-api-doc/value/index.d.ts:85
has Quotes
- get hasQuotes():boolean
Whether this string has quotes.
Returnsboolean
- Defined injs-api-doc/value/string.d.ts:50
is Truthy
- get isTruthy():boolean
Whether the value counts as
true
in an@if
statement and other contexts.Returnsboolean
Inherited from Value.isTruthy
- Defined injs-api-doc/value/index.d.ts:91
real Null
- get realNull():null |Value
Returns JavaScript's
null
value if this issassNull, and returnsthis
otherwise.Returnsnull |Value
Inherited from Value.realNull
- Defined injs-api-doc/value/index.d.ts:97
sass Length
- get sassLength():number
Sass's notion of this string's length.
Sass treats strings as a series of Unicode code points while JavaScripttreats them as a series ofUTF-16 code units. For example, the characterU+1F60ASMILINGFACEWITHSMILINGEYES is a single Unicode code point butis represented inUTF-16 as two code units (
0xD83D
and0xDE0A
). So inJavaScript,"n😊b".length
returns4
, whereas in Sassstring.length("n😊b")
returns3
.Returnsnumber
- Defined injs-api-doc/value/string.d.ts:62
separator
- get separator():ListSeparator
The separator for this value as a list.
All SassScript values can be used as lists. Maps count as lists of pairs,and all other values count as single-value lists.
ReturnsListSeparator
Inherited from Value.separator
- Defined injs-api-doc/value/index.d.ts:105
text
- get text():string
The contents of the string.
For quoted strings, this is the semantic content—any escape sequences thatwere been written in the source text are resolved to their Unicode values.For unquoted strings, though, escape sequences are preserved as literal backslashes.
This difference allows us to distinguish between identifiers with escapes,such as
url\u28 http://example.com\u29
, and unquoted strings that containcharacters that aren't valid in identifiers, such asurl(http://example.com)
. Unfortunately, it also means that we don'tconsiderfoo
andf\6F\6F
the same string.Returnsstring
- Defined injs-api-doc/value/string.d.ts:47
Methods
assert Boolean
- assert
Boolean(name?:string):SassBoolean Throws if
this
isn't aSassBoolean.⚠️ Heads up!
Functions should generally useisTruthy rather thanrequiring a literal boolean.
Parameters
Optional
name:stringThe name of the function argument
this
came from (withoutthe$
) if it came from an argument. Used for error reporting.
ReturnsSassBoolean
Inherited fromValue.assertBoolean
- Defined injs-api-doc/value/index.d.ts:147
assert Calculation
- assert
Calculation(name?:string):SassCalculation Throws if
this
isn't aSassCalculation.Parameters
Optional
name:stringThe name of the function argument
this
came from (withoutthe$
) if it came from an argument. Used for error reporting.
ReturnsSassCalculation
Inherited fromValue.assertCalculation
- Defined injs-api-doc/value/index.d.ts:155
assert Color
- assert
Color(name?:string):SassColor Throws if
this
isn't aSassColor.Parameters
Optional
name:stringThe name of the function argument
this
came from (withoutthe$
) if it came from an argument. Used for error reporting.
ReturnsSassColor
Inherited fromValue.assertColor
- Defined injs-api-doc/value/index.d.ts:163
assert Function
- assert
Function(name?:string):SassFunction Throws if
this
isn't aSassFunction.Parameters
Optional
name:stringThe name of the function argument
this
came from (withoutthe$
) if it came from an argument. Used for error reporting.
ReturnsSassFunction
Inherited fromValue.assertFunction
- Defined injs-api-doc/value/index.d.ts:171
assert Map
- assert
Map(name?:string):SassMap Throws if
this
isn't aSassMap.Parameters
Optional
name:stringThe name of the function argument
this
came from (withoutthe$
) if it came from an argument. Used for error reporting.
ReturnsSassMap
- Defined injs-api-doc/value/index.d.ts:179
assert Mixin
- assert
Mixin(name?:string):SassMixin Throws if
this
isn't aSassMixin.Parameters
Optional
name:stringThe name of the function argument
this
came from (withoutthe$
) if it came from an argument. Used for error reporting.
ReturnsSassMixin
Inherited fromValue.assertMixin
- Defined injs-api-doc/value/index.d.ts:187
assert Number
- assert
Number(name?:string):SassNumber Throws if
this
isn't aSassNumber.Parameters
Optional
name:stringThe name of the function argument
this
came from (withoutthe$
) if it came from an argument. Used for error reporting.
ReturnsSassNumber
Inherited fromValue.assertNumber
- Defined injs-api-doc/value/index.d.ts:195
assert String
- assert
String(name?:string):SassString Throws if
this
isn't aSassString.Parameters
Optional
name:stringThe name of the function argument
this
came from (withoutthe$
) if it came from an argument. Used for error reporting.
ReturnsSassString
Inherited fromValue.assertString
- Defined injs-api-doc/value/index.d.ts:203
equals
- equals(other:Value):boolean
Returns whether
this
represents the same value asother
.Parameters
other:Value
Returnsboolean
- Defined injs-api-doc/value/index.d.ts:212
get
- get(index:number):undefined |Value
Returns the value at index
index
in this value as a list, orundefined
ifindex
isn't valid for this list.All SassScript values can be used as lists. Maps count as lists of pairs,and all other values count as single-value lists.
This is a shorthand for
this.asList.get(index)
, although it may be moreefficient in some cases.⚠️ Heads up!
This method uses the same indexing conventions as the
immutable
package: unlike Sass the index of the first element is 0, butlike Sass negative numbers index from the end of the list.Parameters
index:number
Returnsundefined |Value
- Defined injs-api-doc/value/index.d.ts:136
hash Code
- hash
Code():number Returns a hash code that can be used to store
this
in a hash map.Returnsnumber
- Defined injs-api-doc/value/index.d.ts:215
sass Index To List Index
- sass
Index To List Index(sassIndex:Value,name?:string):number Converts
sassIndex
into a JavaScript-style index into the list returnedbyasList.Sass indexes are one-based, while JavaScript indexes are zero-based. Sassindexes may also be negative in order to index from the end of the list.
Throws
Error
IfsassIndex
isn't a number, if that number isn't aninteger, or if that integer isn't a valid index forasList.Parameters
sassIndex:Value
The Sass-style index into this as a list.
Optional
name:stringThe name of the function argument
sassIndex
came from(without the$
) if it came from an argument. Used for error reporting.
Returnsnumber
Inherited fromValue.sassIndexToListIndex
- Defined injs-api-doc/value/index.d.ts:120
sass Index To String Index
- sass
Index To String Index(sassIndex:Value,name?:string):number Converts
sassIndex
to a JavaScript index intotext.Sass indices are one-based, while JavaScript indices are zero-based. Sassindices may also be negative in order to index from the end of the string.
In addition, Sass indices refer to Unicode code points while JavaScriptstring indices refer toUTF-16 code units. For example, the characterU+1F60ASMILINGFACEWITHSMILINGEYES is a single Unicode code point butis represented inUTF-16 as two code units (
0xD83D
and0xDE0A
). So inJavaScript,"n😊b".charCodeAt(1)
returns0xD83D
, whereas in Sassstring.slice("n😊b", 1, 1)
returns"😊"
.This function converts Sass's code point indices to JavaScript's code unitindices. This means it's O(n) in the length of
text
.Throws
Error
- IfsassIndex
isn't a number, if that number isn't aninteger, or if that integer isn't a valid index for this string.Parameters
sassIndex:Value
Optional
name:string
Returnsnumber
- Defined injs-api-doc/value/string.d.ts:83
try Map
- try
Map():null |SassMap Returns
this
as a map if it counts as one (empty lists count as emptymaps) ornull
if it doesn't.Returnsnull |SassMap
- Defined injs-api-doc/value/index.d.ts:209