Home > front end >  Why was the CSS function clamp written into an Sass unquote function?
Why was the CSS function clamp written into an Sass unquote function?

Time:03-08

In a project I took over, the style was written with SCSS. At one point I wonder why the CSS clamp() function was written with an unquote. If I remove unquote there is no difference.

div {
  font-size:unquote("clamp(30px, 10px   2%, 30px)");
}

And without unquote

div {
  font-size:clamp(30px, 10px   2%, 30px);
}

Question:

Why did you put the clamp function into an unquote function again? If it works without!

CodePudding user response:

This is what the documentation says:

You can convert a quoted string to an unquoted string using the string.unquote() function, and you can convert an unquoted string to a quoted string using the string.quote() function.

So this means that the unquote function is basically useless, because the only thing it does is unquoting "clamp(30px, 10px 2%, 30px)" which will result in clamp(30px, 10px 2%, 30px) which is the exact same.

A reason someone can do this, is for bug reasons, if there is a bug in sass itself (the clamp function only works with unquote), so maybe that is the reason why the programmer has added this.

The probability of this specific bug is offcourse very low, but it is just a theory...

CodePudding user response:

The unquote function was probably used because the text in the function came from a string from an other program or service, so to make sure it will work as CSS they added that during the transfer to CSS.

  • Related