Accoutrement 2.2.0

Function Registration

Because Sass 3.5+ requires first-class functions, we provide tools for capturing functions and making them available to the Accoutrement map parser. This also provides the ability to alias functions as you like.

$functions (map)

$functions: () !default;

We provide a single map to store & manage functions that you would like to use inside Accoutrement maps.

$functions: (
  'times': get-function('times'),
  'divide': get-function('divide'),

Functions can be registered multiple times, under any aliases, using our standard hashtag reference syntax:

$functions: (
  'times': get-function('times'),
  '*': '#times',

Since 0.1.0:

  • NEW: Supports the core map-refernece syntax, for creating function aliases

Map Properties

<alias>: (function)

Each alias key in the map should refer to a captured function

Used By

@function _a_get-function() [private]

@mixin register-function()

In addition to managing the $functions map directly, you can also register new functions on the fly:

  // the first value is the function name,
  // any additional values provide alias names for the same function
  @include register-function('rgba', 'alpha');

Functions only need to be registered if they will be used inside accoutrement maps. That includes core Sass functions.

Note: When using the Sass “module” syntax, the $function argument must be a first-class function (since we cannot capture functions in your module), and you must provide at least one $name (since we cannot extract the name of captured functions):

  @use 'sass:meta';
  @use 'sass:color';
  @use '<path-to>/accoutrement/tools';
  // capture the function from local context
  $rgba: meta.get-function('rgba', $module: 'color');
  // pass the captured function for registration
  @include tools.register-function($rgba, ('rgba', 'alpha'));

Since 2.1.3:

  • BUGFIX: proper support for Sass modules system

Parameters & Output

$function: (string | function)

The function-name to be registered or a first-class function previously captured

$names...: (strings)

One or more alias names (strings) to use for map-access to the function

{CSS output} (code block)

{map} $functions - Functions are captured and added to the $functions map under any number of aliases


@include register-function('darken', 'shade');

/*! Registered Functions… */
@each $name, $value in $functions {
  /*! - #{$name}: #{$value} */
css compiled
@charset "UTF-8";
/*! Registered Functions… */
/*! - darken: get-function("darken") */
/*! - shade: #darken */


@function _a_registration() [private]

$functions (map)