Module Sass::Script::Functions
In: lib/sass/script/functions.rb

Methods in this module are accessible from the SassScript context. For example, you can write

    $color: hsl(120deg, 100%, 50%)

and it will call {Sass::Script::Functions#hsl}.

The following functions are provided:

*Note: These functions are described in more detail below.*

## RGB Functions

\{rgb rgb($red, $green, $blue)} : Creates a {Color} from red, green, and blue values.

\{rgba rgba($red, $green, $blue, $alpha)} : Creates a {Color} from red, green, blue, and alpha values.

\{red red($color)} : Gets the red component of a color.

\{green green($color)} : Gets the green component of a color.

\{blue blue($color)} : Gets the blue component of a color.

\{mix mix($color-1, $color-2, \[$weight\])} : Mixes two colors together.

## HSL Functions

\{hsl hsl($hue, $saturation, $lightness)} : Creates a {Color} from hue, saturation, and lightness values.

\{hsla hsla($hue, $saturation, $lightness, $alpha)} : Creates a {Color} from hue, saturation, lightness, and alpha

  values.

\{hue hue($color)} : Gets the hue component of a color.

\{saturation saturation($color)} : Gets the saturation component of a color.

\{lightness lightness($color)} : Gets the lightness component of a color.

\{adjust_hue adjust-hue($color, $degrees)} : Changes the hue of a color.

\{lighten lighten($color, $amount)} : Makes a color lighter.

\{darken darken($color, $amount)} : Makes a color darker.

\{saturate saturate($color, $amount)} : Makes a color more saturated.

\{desaturate desaturate($color, $amount)} : Makes a color less saturated.

\{grayscale grayscale($color)} : Converts a color to grayscale.

\{complement complement($color)} : Returns the complement of a color.

\{invert invert($color)} : Returns the inverse of a color.

## Opacity Functions

\{alpha alpha($color)} / \{opacity opacity($color)} : Gets the alpha component (opacity) of a color.

\{rgba rgba($color, $alpha)} : Changes the alpha component for a color.

\{opacify opacify($color, $amount)} / \{fade_in fade-in($color, $amount)} : Makes a color more opaque.

\{transparentize transparentize($color, $amount)} / \{fade_out fade-out($color, $amount)} : Makes a color more transparent.

## Other Color Functions

\{adjust_color adjust-color($color, \[$red\], \[$green\], \[$blue\], \[$hue\], \[$saturation\], \[$lightness\], \[$alpha\])} : Increases or decreases one or more components of a color.

\{scale_color scale-color($color, \[$red\], \[$green\], \[$blue\], \[$saturation\], \[$lightness\], \[$alpha\])} : Fluidly scales one or more properties of a color.

\{change_color change-color($color, \[$red\], \[$green\], \[$blue\], \[$hue\], \[$saturation\], \[$lightness\], \[$alpha\])} : Changes one or more properties of a color.

\{ie_hex_str ie-hex-str($color)} : Converts a color into the format understood by IE filters.

## String Functions

\{unquote unquote($string)} : Removes quotes from a string.

\{quote quote($string)} : Adds quotes to a string.

## Number Functions

\{percentage percentage($value)} : Converts a unitless number to a percentage.

\{round round($value)} : Rounds a number to the nearest whole number.

\{ceil ceil($value)} : Rounds a number up to the next whole number.

\{floor floor($value)} : Rounds a number down to the previous whole number.

\{abs abs($value)} : Returns the absolute value of a number.

\{min min($numbers…)\} : Finds the minimum of several numbers.

\{max max($numbers…)\} : Finds the maximum of several numbers.

## List Functions {list-functions}

\{length length($list)} : Returns the length of a list.

\{nth nth($list, $n)} : Returns a specific item in a list.

\{join join($list1, $list2, \[$separator\])} : Joins together two lists into one.

\{append append($list1, $val, \[$separator\])} : Appends a single value onto the end of a list.

\{zip zip($lists…)} : Combines several lists into a single multidimensional list.

\{index index($list, $value)} : Returns the position of a value within a list.

## Introspection Functions

\{type_of type-of($value)} : Returns the type of a value.

\{unit unit($number)} : Returns the unit(s) associated with a number.

\{unitless unitless($number)} : Returns whether a number has units.

\{comparable comparable($number-1, $number-2)} : Returns whether two numbers can be added, subtracted, or compared.

## Miscellaneous Functions

\{if if($condition, $if-true, $if-false)} : Returns one of two values, depending on whether or not `$condition` is

  true.

## Adding Custom Functions

New Sass functions can be added by adding Ruby methods to this module. For example:

    module Sass::Script::Functions
      def reverse(string)
        assert_type string, :String
        Sass::Script::String.new(string.value.reverse)
      end
      declare :reverse, :args => [:string]
    end

Calling {declare} tells Sass the argument names for your function. If omitted, the function will still work, but will not be able to accept keyword arguments. {declare} can also allow your function to take arbitrary keyword arguments.

There are a few things to keep in mind when modifying this module. First of all, the arguments passed are {Sass::Script::Literal} objects. Literal objects are also expected to be returned. This means that Ruby values must be unwrapped and wrapped.

Most Literal objects support the {Sass::Script::Literal#value value} accessor for getting their Ruby values. Color objects, though, must be accessed using {Sass::Script::Color#rgb rgb}, {Sass::Script::Color#red red}, {Sass::Script::Color#blue green}, or {Sass::Script::Color#blue blue}.

Second, making Ruby functions accessible from Sass introduces the temptation to do things like database access within stylesheets. This is generally a bad idea; since Sass files are by default only compiled once, dynamic code is not a great fit.

If you really, really need to compile Sass on each request, first make sure you have adequate caching set up. Then you can use {Sass::Engine} to render the code, using the {file:SASS_REFERENCE.md#custom-option `options` parameter} to pass in data that {EvaluationContext#options can be accessed} from your Sass functions.

Within one of the functions in this module, methods of {EvaluationContext} can be used.

### Caveats

When creating new {Literal} objects within functions, be aware that it‘s not safe to call {Literal#to_s to_s} (or other methods that use the string representation) on those objects without first setting {Node#options= the options attribute}.

Methods

abs   adjust_color   adjust_hue   alpha   append   blue   ceil   change_color   comparable   complement   counter   counters   darken   declare   desaturate   fade_in   fade_out   floor   grayscale   green   hsl   hsla   hue   ie_hex_str   if   index   invert   join   length   lighten   lightness   max   min   mix   nth   opacify   opacity   percentage   quote   red   rgb   rgba   round   saturate   saturation   scale_color   signature   transparentize   type_of   unit   unitless   unquote   zip  

Classes and Modules

Class Sass::Script::Functions::EvaluationContext

Constants

Signature = Struct.new(:args, :var_args, :var_kwargs)   A class representing a Sass function signature.

@attr args [Array<Symbol>] The names of the arguments to the function. @attr var_args [Boolean] Whether the function takes a variable number of arguments. @attr var_kwargs [Boolean] Whether the function takes an arbitrary set of keyword arguments.

External Aliases

public_method_defined? -> callable?
  Returns whether user function with a given name exists.

@param function_name [String] @return [Boolean]

Public Class methods

Declare a Sass signature for a Ruby-defined function. This includes the names of the arguments, whether the function takes a variable number of arguments, and whether the function takes an arbitrary set of keyword arguments.

It‘s not necessary to declare a signature for a function. However, without a signature it won‘t support keyword arguments.

A single function can have multiple signatures declared as long as each one takes a different number of arguments. It‘s also possible to declare multiple signatures that all take the same number of arguments, but none of them but the first will be used unless the user uses keyword arguments.

@example

  declare :rgba, [:hex, :alpha]
  declare :rgba, [:red, :green, :blue, :alpha]
  declare :accepts_anything, [], :var_args => true, :var_kwargs => true
  declare :some_func, [:foo, :bar, :baz], :var_kwargs => true

@param method_name [Symbol] The name of the method

  whose signature is being declared.

@param args [Array<Symbol>] The names of the arguments for the function signature. @option options :var_args [Boolean] (false)

  Whether the function accepts a variable number of (unnamed) arguments
  in addition to the named arguments.

@option options :var_kwargs [Boolean] (false)

  Whether the function accepts other keyword arguments
  in addition to those in `:args`.
  If this is true, the Ruby function will be passed a hash from strings
  to {Sass::Script::Literal}s as the last argument.
  In addition, if this is true and `:var_args` is not,
  Sass will ensure that the last argument passed is a hash.

Determine the correct signature for the number of arguments passed in for a given function. If no signatures match, the first signature is returned for error messaging.

@param method_name [Symbol] The name of the Ruby function to be called. @param arg_arity [Number] The number of unnamed arguments the function was passed. @param kwarg_arity [Number] The number of keyword arguments the function was passed.

@return [{Symbol => Object}, nil]

  The signature options for the matching signature,
  or nil if no signatures are declared for this function. See {declare}.

Public Instance methods

Returns the absolute value of a number.

@example

  abs(10px) => 10px
  abs(-10px) => 10px

@overload abs($value) @param $value [Number] @return [Number] @raise [ArgumentError] if `$value` isn‘t a number

Increases or decreases one or more properties of a color. This can change the red, green, blue, hue, saturation, value, and alpha properties. The properties are specified as keyword arguments, and are added to or subtracted from the color‘s current value for that property.

All properties are optional. You can‘t specify both RGB properties (`$red`, `$green`, `$blue`) and HSL properties (`$hue`, `$saturation`, `$value`) at the same time.

@example

  adjust-color(#102030, $blue: 5) => #102035
  adjust-color(#102030, $red: -5, $blue: 5) => #0b2035
  adjust-color(hsl(25, 100%, 80%), $lightness: -30%, $alpha: -0.4) => hsla(25, 100%, 50%, 0.6)

@overload adjust_color($color, [$red], [$green], [$blue], [$hue], [$saturation], [$lightness], [$alpha]) @param $color [Color] @param $red [Number] The adjustment to make on the red component, between

  -255 and 255 inclusive

@param $green [Number] The adjustment to make on the green component,

  between -255 and 255 inclusive

@param $blue [Number] The adjustment to make on the blue component, between

  -255 and 255 inclusive

@param $hue [Number] The adjustment to make on the hue component, in

  degrees

@param $saturation [Number] The adjustment to make on the saturation

  component, between `-100%` and `100%` inclusive

@param $lightness [Number] The adjustment to make on the lightness

  component, between `-100%` and `100%` inclusive

@param $alpha [Number] The adjustment to make on the alpha component,

  between -1 and 1 inclusive

@return [Color] @raise [ArgumentError] if any parameter is the wrong type or out-of

  bounds, or if RGB properties and HSL properties are adjusted at the
  same time

Changes the hue of a color. Takes a color and a number of degrees (usually between `-360deg` and `360deg`), and returns a color with the hue rotated along the color wheel by that amount.

@example

  adjust-hue(hsl(120, 30%, 90%), 60deg) => hsl(180, 30%, 90%)
  adjust-hue(hsl(120, 30%, 90%), 060deg) => hsl(60, 30%, 90%)
  adjust-hue(#811, 45deg) => #886a11

@overload adjust_hue($color, $degrees) @param $color [Color] @param $degrees [Number] The number of degrees to rotate the hue @return [Color] @raise [ArgumentError] if either parameter is the wrong type

Returns the alpha component (opacity) of a color. This is 1 unless otherwise specified.

This function also supports the proprietary Microsoft `alpha(opacity=20)` syntax as a special case.

@overload alpha($color) @param $color [Color] @return [Number] The alpha component, between 0 and 1 @raise [ArgumentError] if `$color` isn‘t a color

Appends a single value onto the end of a list.

Unless the `$separator` argument is passed, if the list had only one item, the resulting list will be space-separated.

@example

  append(10px 20px, 30px) => 10px 20px 30px
  append((blue, red), green) => blue, red, green
  append(10px 20px, 30px 40px) => 10px 20px (30px 40px)
  append(10px, 20px, comma) => 10px, 20px
  append((blue, red), green, space) => blue red green

@overload append($list, $val, $separator: auto) @param $list [Literal] @param $val [Literal] @param $separator [String] The list separator to use. If this is `comma`

  or `space`, that separator will be used. If this is `auto` (the
  default), the separator is determined as explained above.

@return [List]

Gets the blue component of a color. Calculated from HSL where necessary via [this algorithm][hsl-to-rgb].

[hsl-to-rgb]: www.w3.org/TR/css3-color/#hsl-color

@overload blue($color) @param $color [Color] @return [Number] The blue component, between 0 and 255 inclusive @raise [ArgumentError] if `$color` isn‘t a color

Rounds a number up to the next whole number.

@example

  ceil(10.4px) => 11px
  ceil(10.6px) => 11px

@overload ceil($value) @param $value [Number] @return [Number] @raise [ArgumentError] if `$value` isn‘t a number

Changes one or more properties of a color. This can change the red, green, blue, hue, saturation, value, and alpha properties. The properties are specified as keyword arguments, and replace the color‘s current value for that property.

All properties are optional. You can‘t specify both RGB properties (`$red`, `$green`, `$blue`) and HSL properties (`$hue`, `$saturation`, `$value`) at the same time.

@example

  change-color(#102030, $blue: 5) => #102005
  change-color(#102030, $red: 120, $blue: 5) => #782005
  change-color(hsl(25, 100%, 80%), $lightness: 40%, $alpha: 0.8) => hsla(25, 100%, 40%, 0.8)

@overload change_color($color, [$red], [$green], [$blue], [$hue], [$saturation], [$lightness], [$alpha]) @param $color [Color] @param $red [Number] The new red component for the color, within 0 and 255

  inclusive

@param $green [Number] The new green component for the color, within 0 and

  255 inclusive

@param $blue [Number] The new blue component for the color, within 0 and

  255 inclusive

@param $hue [Number] The new hue component for the color, in degrees @param $saturation [Number] The new saturation component for the color,

  between `0%` and `100%` inclusive

@param $lightness [Number] The new lightness component for the color,

  within `0%` and `100%` inclusive

@param $alpha [Number] The new alpha component for the color, within 0 and

  1 inclusive

@return [Color] @raise [ArgumentError] if any parameter is the wrong type or out-of

  bounds, or if RGB properties and HSL properties are adjusted at the
  same time

Returns whether two numbers can added, subtracted, or compared.

@example

  comparable(2px, 1px) => true
  comparable(100px, 3em) => false
  comparable(10cm, 3mm) => true

@overload comparable($number-1, $number-2) @param $number-1 [Number] @param $number-2 [Number] @return [Bool] @raise [ArgumentError] if either parameter is the wrong type

Returns the complement of a color. This is identical to `adjust-hue(color, 180deg)`.

@see adjust_hue adjust-hue @overload complement($color) @param $color [Color] @return [Color] @raise [ArgumentError] if `$color` isn‘t a color

This function only exists as a workaround for IE7‘s [`content: counter` bug][bug]. It works identically to any other plain-CSS function, except it avoids adding spaces between the argument commas.

[bug]: jes.st/2013/ie7s-css-breaking-content-counter-bug/

@example

  counter(item, ".") => counter(item,".")

@overload counter($args…) @return [String]

This function only exists as a workaround for IE7‘s [`content: counters` bug][bug]. It works identically to any other plain-CSS function, except it avoids adding spaces between the argument commas.

[bug]: jes.st/2013/ie7s-css-breaking-content-counter-bug/

@example

  counters(item, ".") => counters(item,".")

@overload counters($args…) @return [String]

Makes a color darker. Takes a color and a number between 0% and 100%, and returns a color with the lightness decreased by that amount.

@see lighten @example

  darken(hsl(25, 100%, 80%), 30%) => hsl(25, 100%, 50%)
  darken(#800, 20%) => #200

@overload darken($color, $amount) @param $color [Color] @param $amount [Number] The amount to dencrease the lightness by, between

  `0%` and `100%`

@return [Color] @raise [ArgumentError] if `$amount` is out of bounds, or either parameter

  is the wrong type

Makes a color less saturated. Takes a color and a number between 0% and 100%, and returns a color with the saturation decreased by that value.

@see saturate @example

  desaturate(hsl(120, 30%, 90%), 20%) => hsl(120, 10%, 90%)
  desaturate(#855, 20%) => #726b6b

@overload desaturate($color, $amount) @param $color [Color] @param $amount [Number] The amount to decrease the saturation by, between

  `0%` and `100%`

@return [Color] @raise [ArgumentError] if `$amount` is out of bounds, or either parameter

  is the wrong type
fade_in(color, amount)

Alias for opacify

fade_out(color, amount)

Alias for transparentize

Rounds a number down to the previous whole number.

@example

  floor(10.4px) => 10px
  floor(10.6px) => 10px

@overload floor($value) @param $value [Number] @return [Number] @raise [ArgumentError] if `$value` isn‘t a number

Converts a color to grayscale. This is identical to `desaturate(color, 100%)`.

@see desaturate @overload grayscale($color) @param $color [Color] @return [Color] @raise [ArgumentError] if `$color` isn‘t a color

Gets the green component of a color. Calculated from HSL where necessary via [this algorithm][hsl-to-rgb].

[hsl-to-rgb]: www.w3.org/TR/css3-color/#hsl-color

@overload green($color) @param $color [Color] @return [Number] The green component, between 0 and 255 inclusive @raise [ArgumentError] if `$color` isn‘t a color

Creates a {Color} from hue, saturation, and lightness values. Uses the algorithm from the [CSS3 spec][].

[CSS3 spec]: www.w3.org/TR/css3-color/#hsl-color

@see hsla @overload hsl($hue, $saturation, $lightness) @param $hue [Number] The hue of the color. Should be between 0 and 360

  degrees, inclusive

@param $saturation [Number] The saturation of the color. Must be between

  `0%` and `100%`, inclusive

@param $lightness [Number] The lightness of the color. Must be between

  `0%` and `100%`, inclusive

@return [Color] @raise [ArgumentError] if `$saturation` or `$lightness` are out of bounds

  or any parameter is the wrong type

Creates a {Color} from hue, saturation, lightness, and alpha values. Uses the algorithm from the [CSS3 spec][].

[CSS3 spec]: www.w3.org/TR/css3-color/#hsl-color

@see hsl @overload hsla($hue, $saturation, $lightness, $alpha) @param $hue [Number] The hue of the color. Should be between 0 and 360

  degrees, inclusive

@param $saturation [Number] The saturation of the color. Must be between

  `0%` and `100%`, inclusive

@param $lightness [Number] The lightness of the color. Must be between

  `0%` and `100%`, inclusive

@param $alpha [Number] The opacity of the color. Must be between 0 and 1,

  inclusive

@return [Color] @raise [ArgumentError] if `$saturation`, `$lightness`, or `$alpha` are out

  of bounds or any parameter is the wrong type

Returns the hue component of a color. See [the CSS3 HSL specification][hsl]. Calculated from RGB where necessary via [this algorithm][rgb-to-hsl].

[hsl]: en.wikipedia.org/wiki/HSL_and_HSV#Conversion_from_RGB_to_HSL_or_HSV [rgb-to-hsl]: en.wikipedia.org/wiki/HSL_and_HSV#Conversion_from_RGB_to_HSL_or_HSV

@overload hue($color) @param $color [Color] @return [Number] The hue component, between 0deg and 360deg @raise [ArgumentError] if `$color` isn‘t a color

Converts a color into the format understood by IE filters.

@example

  ie-hex-str(#abc) => #FFAABBCC
  ie-hex-str(#3322BB) => #FF3322BB
  ie-hex-str(rgba(0, 255, 0, 0.5)) => #8000FF00

@overload ie_hex_str($color) @param $color [Color] @return [String] The IE-formatted string representation of the color @raise [ArgumentError] if `$color` isn‘t a color

Returns one of two values, depending on whether or not `$condition` is true. Just like in `@if`, all values other than `false` and `null` are considered to be true.

@example

  if(true, 1px, 2px) => 1px
  if(false, 1px, 2px) => 2px

@overload if($condition, $if-true, $if-false) @param $condition [Literal] Whether the `$if-true` or `$if-false` will be

  returned

@param $if-true [Literal] @param $if-false [Literal] @return [Literal] `$if-true` or `$if-false`

Returns the position of a value within a list. If the value isn‘t found, returns false instead.

Note that unlike some languages, the first item in a Sass list is number 1, the second number 2, and so forth.

@example

  index(1px solid red, solid) => 2
  index(1px solid red, dashed) => false

@overload index($list, $value) @param $list [Literal] @param $value [Literal] @return [Number, Bool] The 1-based index of `$value` in `$list`, or

  `false`

Returns the inverse (negative) of a color. The red, green, and blue values are inverted, while the opacity is left alone.

@overload invert($color) @param $color [Color] @return [Color] @raise [ArgumentError] if `$color` isn‘t a color

Joins together two lists into one.

Unless `$separator` is passed, if one list is comma-separated and one is space-separated, the first parameter‘s separator is used for the resulting list. If both lists have fewer than two items, spaces are used for the resulting list.

@example

  join(10px 20px, 30px 40px) => 10px 20px 30px 40px
  join((blue, red), (#abc, #def)) => blue, red, #abc, #def
  join(10px, 20px) => 10px 20px
  join(10px, 20px, comma) => 10px, 20px
  join((blue, red), (#abc, #def), space) => blue red #abc #def

@overload join($list1, $list2, $separator: auto) @param $list1 [Literal] @param $list2 [Literal] @param $separator [String] The list separator to use. If this is `comma`

  or `space`, that separator will be used. If this is `auto` (the
  default), the separator is determined as explained above.

@return [List]

Return the length of a list.

@example

  length(10px) => 1
  length(10px 20px 30px) => 3

@overload length($list) @param $list [Literal] @return [Number]

Makes a color lighter. Takes a color and a number between `0%` and `100%`, and returns a color with the lightness increased by that amount.

@see darken @example

  lighten(hsl(0, 0%, 0%), 30%) => hsl(0, 0, 30)
  lighten(#800, 20%) => #e00

@overload lighten($color, $amount) @param $color [Color] @param $amount [Number] The amount to increase the lightness by, between

  `0%` and `100%`

@return [Color] @raise [ArgumentError] if `$amount` is out of bounds, or either parameter

  is the wrong type

Returns the lightness component of a color. See [the CSS3 HSL specification][hsl]. Calculated from RGB where necessary via [this algorithm][rgb-to-hsl].

[hsl]: en.wikipedia.org/wiki/HSL_and_HSV#Conversion_from_RGB_to_HSL_or_HSV [rgb-to-hsl]: en.wikipedia.org/wiki/HSL_and_HSV#Conversion_from_RGB_to_HSL_or_HSV

@overload lightness($color) @param $color [Color] @return [Number] The lightness component, between 0% and 100% @raise [ArgumentError] if `$color` isn‘t a color

Finds the maximum of several numbers. This function takes any number of arguments.

@example

  max(1px, 4px) => 4px
  max(5em, 3em, 4em) => 5em

@overload max($numbers…) @param $numbers [[Number]] @return [Number] @raise [ArgumentError] if any argument isn‘t a number, or if not all of

  the arguments have comparable units

Finds the minimum of several numbers. This function takes any number of arguments.

@example

  min(1px, 4px) => 1px
  min(5em, 3em, 4em) => 3em

@overload min($numbers…) @param $numbers [[Number]] @return [Number] @raise [ArgumentError] if any argument isn‘t a number, or if not all of

  the arguments have comparable units

Mixes two colors together. Specifically, takes the average of each of the RGB components, optionally weighted by the given percentage. The opacity of the colors is also considered when weighting the components.

The weight specifies the amount of the first color that should be included in the returned color. The default, `50%`, means that half the first color and half the second color should be used. `25%` means that a quarter of the first color and three quarters of the second color should be used.

@example

  mix(#f00, #00f) => #7f007f
  mix(#f00, #00f, 25%) => #3f00bf
  mix(rgba(255, 0, 0, 0.5), #00f) => rgba(63, 0, 191, 0.75)

@overload mix($color-1, $color-2, $weight: 50%) @param $color-1 [Color] @param $color-2 [Color] @param $weight [Number] The relative weight of each color. Closer to `0%`

  gives more weight to `$color`, closer to `100%` gives more weight to
  `$color2`

@return [Color] @raise [ArgumentError] if `$weight` is out of bounds or any parameter is

  the wrong type

Gets the nth item in a list.

Note that unlike some languages, the first item in a Sass list is number 1, the second number 2, and so forth.

@example

  nth(10px 20px 30px, 1) => 10px
  nth((Helvetica, Arial, sans-serif), 3) => sans-serif

@overload nth($list, $n) @param $list [Literal] @param $n [Number] The index of the item to get @return [Literal] @raise [ArgumentError] if `$n` isn‘t an integer between 1 and the length

  of `$list`

Makes a color more opaque. Takes a color and a number between 0 and 1, and returns a color with the opacity increased by that amount.

@see transparentize @example

  opacify(rgba(0, 0, 0, 0.5), 0.1) => rgba(0, 0, 0, 0.6)
  opacify(rgba(0, 0, 17, 0.8), 0.2) => #001

@overload opacify($color, $amount) @param $color [Color] @param $amount [Number] The amount to increase the opacity by, between 0

  and 1

@return [Color] @raise [ArgumentError] if `$amount` is out of bounds, or either parameter

  is the wrong type

Returns the alpha component (opacity) of a color. This is 1 unless otherwise specified.

@overload opacity($color) @param $color [Color] @return [Number] The alpha component, between 0 and 1 @raise [ArgumentError] if `$color` isn‘t a color

Converts a unitless number to a percentage.

@example

  percentage(0.2) => 20%
  percentage(100px / 50px) => 200%

@overload percentage($value) @param $value [Number] @return [Number] @raise [ArgumentError] if `$value` isn‘t a unitless number

Add quotes to a string if the string isn‘t quoted, or returns the same string if it is.

@see unquote @example

  quote("foo") => "foo"
  quote(foo) => "foo"

@overload quote($string) @param $string [String] @return [String] @raise [ArgumentError] if `$string` isn‘t a string

Gets the red component of a color. Calculated from HSL where necessary via [this algorithm][hsl-to-rgb].

[hsl-to-rgb]: www.w3.org/TR/css3-color/#hsl-color

@overload red($color) @param $color [Color] @return [Number] The red component, between 0 and 255 inclusive @raise [ArgumentError] if `$color` isn‘t a color

Creates a {Color} object from red, green, and blue values.

@see rgba @overload rgb($red, $green, $blue) @param $red [Number] The amount of red in the color. Must be between 0 and

  255 inclusive, or between `0%` and `100%` inclusive

@param $green [Number] The amount of green in the color. Must be between 0

  and 255 inclusive, or between `0%` and `100%` inclusive

@param $blue [Number] The amount of blue in the color. Must be between 0

  and 255 inclusive, or between `0%` and `100%` inclusive

@return [Color] @raise [ArgumentError] if any parameter is the wrong type or out of bounds

Creates a {Color} from red, green, blue, and alpha values. @see rgb

@overload rgba($red, $green, $blue, $alpha)

  @param $red [Number] The amount of red in the color. Must be between 0
    and 255 inclusive
  @param $green [Number] The amount of green in the color. Must be between
    0 and 255 inclusive
  @param $blue [Number] The amount of blue in the color. Must be between 0
    and 255 inclusive
  @param $alpha [Number] The opacity of the color. Must be between 0 and 1
    inclusive
  @return [Color]
  @raise [ArgumentError] if any parameter is the wrong type or out of
    bounds

@overload rgba($color, $alpha)

  Sets the opacity of an existing color.

  @example
    rgba(#102030, 0.5) => rgba(16, 32, 48, 0.5)
    rgba(blue, 0.2)    => rgba(0, 0, 255, 0.2)

  @param $color [Color] The color whose opacity will be changed.
  @param $alpha [Number] The new opacity of the color. Must be between 0
    and 1 inclusive
  @return [Color]
  @raise [ArgumentError] if `$alpha` is out of bounds or either parameter
    is the wrong type

Rounds a number to the nearest whole number.

@example

  round(10.4px) => 10px
  round(10.6px) => 11px

@overload round($value) @param $value [Number] @return [Number] @raise [ArgumentError] if `$value` isn‘t a number

Makes a color more saturated. Takes a color and a number between 0% and 100%, and returns a color with the saturation increased by that amount.

@see desaturate @example

  saturate(hsl(120, 30%, 90%), 20%) => hsl(120, 50%, 90%)
  saturate(#855, 20%) => #9e3f3f

@overload saturate($color, $amount) @param $color [Color] @param $amount [Number] The amount to increase the saturation by, between

  `0%` and `100%`

@return [Color] @raise [ArgumentError] if `$amount` is out of bounds, or either parameter

  is the wrong type

Returns the saturation component of a color. See [the CSS3 HSL specification][hsl]. Calculated from RGB where necessary via [this algorithm][rgb-to-hsl].

[hsl]: en.wikipedia.org/wiki/HSL_and_HSV#Conversion_from_RGB_to_HSL_or_HSV [rgb-to-hsl]: en.wikipedia.org/wiki/HSL_and_HSV#Conversion_from_RGB_to_HSL_or_HSV

@overload saturation($color) @param $color [Color] @return [Number] The saturation component, between 0% and 100% @raise [ArgumentError] if `$color` isn‘t a color

Fluidly scales one or more properties of a color. Unlike \{adjust_color adjust-color}, which changes a color‘s properties by fixed amounts, \{scale_color scale-color} fluidly changes them based on how high or low they already are. That means that lightening an already-light color with \{scale_color scale-color} won‘t change the lightness much, but lightening a dark color by the same amount will change it more dramatically. This has the benefit of making `scale-color($color, …)` have a similar effect regardless of what `$color` is.

For example, the lightness of a color can be anywhere between `0%` and `100%`. If `scale-color($color, $lightness: 40%)` is called, the resulting color‘s lightness will be 40% of the way between its original lightness and 100. If `scale-color($color, $lightness: -40%)` is called instead, the lightness will be 40% of the way between the original and 0.

This can change the red, green, blue, saturation, value, and alpha properties. The properties are specified as keyword arguments. All arguments should be percentages between `0%` and `100%`.

All properties are optional. You can‘t specify both RGB properties (`$red`, `$green`, `$blue`) and HSL properties (`$saturation`, `$value`) at the same time.

@example

  scale-color(hsl(120, 70%, 80%), $lightness: 50%) => hsl(120, 70%, 90%)
  scale-color(rgb(200, 150%, 170%), $green: -40%, $blue: 70%) => rgb(200, 90, 229)
  scale-color(hsl(200, 70%, 80%), $saturation: -90%, $alpha: -30%) => hsla(200, 7%, 80%, 0.7)

@overload scale_color($color, [$red], [$green], [$blue], [$saturation], [$lightness], [$alpha]) @param $color [Color] @param $red [Number] @param $green [Number] @param $blue [Number] @param $saturation [Number] @param $lightness [Number] @param $alpha [Number] @return [Color] @raise [ArgumentError] if any parameter is the wrong type or out-of

  bounds, or if RGB properties and HSL properties are adjusted at the
  same time

Makes a color more transparent. Takes a color and a number between 0 and 1, and returns a color with the opacity decreased by that amount.

@see opacify @example

  transparentize(rgba(0, 0, 0, 0.5), 0.1) => rgba(0, 0, 0, 0.4)
  transparentize(rgba(0, 0, 0, 0.8), 0.2) => rgba(0, 0, 0, 0.6)

@overload transparentize($color, $amount) @param $color [Color] @param $amount [Number] The amount to decrease the opacity by, between 0

  and 1

@return [Color] @raise [ArgumentError] if `$amount` is out of bounds, or either parameter

  is the wrong type

Returns the type of a value.

@example

  type-of(100px)  => number
  type-of(asdf)   => string
  type-of("asdf") => string
  type-of(true)   => bool
  type-of(#fff)   => color
  type-of(blue)   => color

@overload type_of($value) @param $value [Literal] The value to inspect @return [String] The unquoted string name of the value‘s type

Returns the unit(s) associated with a number. Complex units are sorted in alphabetical order by numerator and denominator.

@example

  unit(100) => ""
  unit(100px) => "px"
  unit(3em) => "em"
  unit(10px * 5em) => "em*px"
  unit(10px * 5em / 30cm / 1rem) => "em*px/cm*rem"

@overload unit($number) @param $number [Number] @return [String] The unit(s) of the number, as a quoted string @raise [ArgumentError] if `$number` isn‘t a number

Returns whether a number has units.

@example

  unitless(100) => true
  unitless(100px) => false

@overload unitless($number) @param $number [Number] @return [Bool] @raise [ArgumentError] if `$number` isn‘t a number

Removes quotes from a string. If the string is already unquoted, this will return it unmodified.

@see quote @example

  unquote("foo") => foo
  unquote(foo) => foo

@overload unquote($string) @param $string [String] @return [String] @raise [ArgumentError] if `$string` isn‘t a string

Combines several lists into a single multidimensional list. The nth value of the resulting list is a space separated list of the source lists’ nth values.

The length of the resulting list is the length of the shortest list.

@example

  zip(1px 1px 3px, solid dashed solid, red green blue)
  => 1px solid red, 1px dashed green, 3px solid blue

@overload zip($lists…) @param $lists [[Literal]] @return [List]

[Validate]