SassString

Hierarchy

Constructors

constructor

  • newSassString(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.

    • Optionaloptions:{
          quotes?:boolean;
      }
      • Optionalquotes?:boolean

        Whether the string is quoted. Defaults totrue.

    ReturnsSassString

    OverridesValue.constructor

constructor

Accessors

asList

hasBrackets

hasQuotes

isTruthy

realNull

sassLength

  • 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

separator

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 asurl\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

Methods

assertBoolean

assertCalculation

assertColor

assertFunction

assertMap

assertMixin

assertNumber

assertString

equals

get

  • get(index:number):undefined |Value
  • Returns the value at indexindex in this value as a list, orundefinedifindex 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 forthis.asList.get(index), although it may be moreefficient in some cases.

    ⚠️ Heads up!

    This method uses the same indexing conventions as theimmutable 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

    Inherited fromValue.get

hashCode

sassIndexToListIndex

  • sassIndexToListIndex(sassIndex:Value,name?:string):number
  • ConvertssassIndex 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.

    • Optionalname:string

      The name of the function argumentsassIndex came from(without the$) if it came from an argument. Used for error reporting.

    Returnsnumber

    Inherited fromValue.sassIndexToListIndex

sassIndexToStringIndex

  • sassIndexToStringIndex(sassIndex:Value,name?:string):number
  • ConvertssassIndex 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 oftext.

    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
    • Optionalname:string

    Returnsnumber

tryMap