Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SASS : Check if a variable is a map

Tags:

sass

sass-maps

Is there something like is-map($some_variable) in SASS?

I have tried looking into the documentation but there is none there.

like image 450
qtgye Avatar asked Aug 20 '16 10:08

qtgye


People also ask

What is SCSS map?

Maps in Sass hold pairs of keys and values, and make it easy to look up a value by its corresponding key. They're written (<expression>: <expression>, <expression>: <expression>) . The expression before the : is the key, and the expression after is the value associated with that key.

What is the correct way to define a variable in Sass?

The basic syntax for defining a variable is simple: Just use a $ before the variable name and treat its definition like a CSS rule: Sass Variable Syntax: $<variable name>:<value>; The following declares a variable named large-font.

Which map function returns all keys in a map in Sass?

map-keys($map) function: This function returns the list of the keys in the given map.

What Is syntax in Sass?

SASS supports two syntaxes namely SCSS and Indented syntax. The SCSS (Sassy CSS) is an extension of CSS syntax. This means every valid CSS is a valid SCSS as well. SCSS makes much easier to maintain large stylesheets and can recognize vendor specific syntax, Many CSS and SCSS files use the extension .


1 Answers

You can implement it with the type-of function, like this one:

@function is-map($var){
  @return type-of($var) == 'map';
}
like image 163
Amit Avihud Avatar answered Sep 29 '22 14:09

Amit Avihud