sassdart-sass

In Sass, how can I check if a list of arguments is empty?


In Sass we can use argument list but how can we check if this argList is empty or not?

Here a basic sample with some debugs :

@mixin mymixin($myargs...) {
    @debug $myargs;
    @debug type-of($transitions);
    @debug not $myargs;
    @debug $myargs == ();
    @debug $myargs == list;
    @debug $myargs == arglist;
    @debug $myargs == "";
    @debug $myargs == false;
    @debug $myargs == null;
    @debug $myargs == (null);
    @debug $myargs == [];
    @debug $myargs == array;
}
html {
    @include mymixin();
}

returns :

Debug: ()
Debug: arglist
Debug: false
Debug: false
Debug: false
Debug: false
Debug: false
Debug: false
Debug: false
Debug: false
Debug: false
Debug: false

Solution

  • Length of lists can be achieved by using the length method of SASS. if length($myargs) is zero, it means the list is empty. More information about length: https://sass-lang.com/documentation/modules/list#length

    @mixin mymixin($myargs...) {
        @debug length($myargs) == 0;
    }
    html {
        @include mymixin();
    }