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

Constructors

  • 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

    const list = new sass.types.List(3);
    list.setValue(0, new sass.types.Number(10, "px"));
    list.setValue(1, new sass.types.Number(15, "px"));
    list.setValue(2, new sass.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

  • 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

  • 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

  • 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

  • Sets whether the list is comma-separated.

    Parameters

    • isComma: boolean

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

    Returns void

  • Sets the element at index to value.

    Example

    // list is `10px, 15px, 32px`
    list.setValue(1, new sass.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