W3cubDocs

/Sass

Class List

Sass's list type.

⚠️ Heads up!

This list type’s methods use 0-based indexing, even though within Sass lists use 1-based indexing. These methods also don’t support using negative numbers to index backwards from the end of the list.

Hierarchy

  • List

Index

Constructors

constructor

  • new List(length: number, commaSeparator?: boolean): List
  • Creates a new Sass list.

    ⚠️ Heads up!

    The initial values of the list elements are undefined. These elements must be set using setValue before accessing them or passing the list back to Sass.

    example
    constlist = newsass.types.List(3);
    list.setValue(0, newsass.types.Number(10, "px"));
    list.setValue(1, newsass.types.Number(15, "px"));
    list.setValue(2, newsass.types.Number(32, "px"));
    list; // 10px, 15px, 32px

    Parameters

    • length: number

      The number of (initially undefined) elements in the list.

    • Optional commaSeparator: boolean

      If true, the list is comma-separated; otherwise, it's space-separated. Defaults to true.

    Returns List

Methods

getLength

  • getLength(): number
  • Returns the number of elements in the list.

    example
    // list is `10px, 15px, 32px`
    list.getLength(); // 3

    // list is `1px solid`
    list.getLength(); // 2

    Returns number

getSeparator

  • getSeparator(): boolean
  • Returns true if this list is comma-separated and false otherwise.

    example
    // list is `10px, 15px, 32px`
    list.getSeparator(); // true

    // list is `1px solid`
    list.getSeparator(); // false

    Returns boolean

getValue

  • Returns the element at index, or undefined if that value hasn't yet been set.

    example
    // list is `10px, 15px, 32px`
    list.getValue(0); // 10px
    list.getValue(2); // 32px
    throws

    Error if index is less than 0 or greater than or equal to the number of elements in this list.

    Parameters

    • index: number

      A (0-based) index into this list.

    Returns undefined | LegacyValue

setSeparator

  • setSeparator(isComma: boolean): void
  • Sets whether the list is comma-separated.

    Parameters

    • isComma: boolean

      true to make the list comma-separated, false otherwise.

    Returns void

setValue

  • Sets the element at index to value.

    example
    // list is `10px, 15px, 32px`
    list.setValue(1, newsass.types.Number(18, "px"));
    list; // 10px, 18px, 32px
    throws

    Error if index is less than 0 or greater than or equal to the number of elements in this list.

    Parameters

    • index: number

      A (0-based) index into this list.

    • value: LegacyValue

    Returns void

© 2006–2022 the Sass team, and numerous contributors
Licensed under the MIT License.
https://sass-lang.com/documentation/js-api/classes/types.List