Skip to main content

validate-index ()

Signatures

validate-index ( $context, $name, $value, $list )

Returns a valid index for a list of a given length; otherwise, an error message stating the reason the index is invalid.

Details

Parameters

$context
The name of the function or mixin issuing the error.
Type
String
$name
The name of the index parameter which is being validated.
Type
String
$value
The value of the index parameter which is being validated. A valid negative value will be transformed to the respective positive index value.
Type
Number
$list
The list value for which the index is validated against.
Type
List

Return Value

Number | String
A string when the index is not a number, is zero, or is invalid for the amount of elements in the list; otherwise, a number.
validate-index ( $context, $name, $value, $string )

Returns a valid index for a string of a given length; otherwise, an error message stating the reason the index is invalid.

Details

Parameters

$context
The name of the function or mixin issuing the error.
Type
String
$name
The name of the index parameter which is being validated.
Type
String
$value
The value of the index parameter which is being validated. A valid negative value will be transformed to the respective positive index value.
Type
Number
$string
The string value for which the index is validated against.
Type
String

Return Value

Number | String
A string when the index is not a number; otherwise, a number.

Example

@sass-fairy/list/src/_set-nth.sass
// Copyright (c) roydukkey. All rights reserved.
// Licensed under the MIT. See LICENSE file in the project root for full license information.

@use 'sass:list'
@use 'sass:meta'
@use '@sass-fairy/exception'


@function set-nth($list, $index, $value, $separator: auto)
$index: exception.validate-index('set-nth', 'index', $index, $list)

@if meta.type-of($index) != 'number'
@error $index

@if exception.is-separator-invalid($separator)
@error exception.separator('set-nth')

@return list.join(list.set-nth($list, $index, $value), (), $separator)