Skip to content

Helper functions

Scarab provides a library of helper functions in addition to the tokens helpers mentioned above. These helpers provide additional syntactic sugar on top of the default Sass functions.

This section of the documentation is a WIP

This section of the docs is a work-in-progress. In the meantime, to view documentation for helper functions, you may clone the Github repository and generate the legacy Sassdoc documentation.

Type helpers

is-null

Checks if the specified value is null.

Example
is-null(null)
// => true

is-null(false)
// => false

is-null('')
// => false

is-null(0)
// => false

to-length

Converts a value to a length.

to-negative

Converts a number, list, or map of values to negative value(s).

to-number

Converts a value to a number.

to-string

Converts a value to a string.

type-check

Performs type checks on values.

Unit helpers

em

Converts px to em.

rem

Converts px to rem.

unit-convert

Converts units of a value.

unit-strip

Strips units from a value.

String helpers

str-append

Appends to a string.

str-compare

Compares two strings or numbers to determine which comes first.

str-contains

Escapes CSS special characters within a string.

str-escape

Escapes CSS special characters within a string.

str-prepend

Prepends to a string.

str-remove

Removes a substring within a string.

str-replace

Replaces a substring within a string.

List helpers

list-append

Adds values to the end of a list.

list-contains

Checks if a list contains the specified value.

list-each

Calls a function on each item in a list.

list-every

Checks if the result of calling a given function on every item in list is true.

list-prepend

Adds value(s) to the start of a list.

list-remove

Finds and removes value(s) from a list.

list-replace

Finds and replaces value(s) in a list.

list-reverse

Reverses the order of values in a list.

list-sort

Sorts items in a list.

list-unique

Removes duplicate values from a list.

Map helpers

map-append

Adds a single key-value pair onto the end of a map.

map-each-key

Calls a function on each key in a map.

map-each-value

Calls a function on each value in a map.

map-flatten

Flattens a map one-level deep.

map-get-key

Returns the key(s) in a map associated with a given value.

map-prepend

Adds a single key-value pair onto the start of a map.

map-stringify-keys-deep

Converts all keys in a map to strings, including keys of nested maps.

map-stringify-keys

Converts direct keys of a map to strings.

map-unique

Removes key-value pairs from a map which contain duplicate values.

CSS class helpers

class-escape

Escapes a string for use as a CSS class name.

class-sanitize

Removes selector-format placeholders from a string.

class-template

Returns the result of hydrating the selector-format with give values.

Utility helpers

get-function-safe

Safely calls native get-function. Intended for use with nativ call.

random-color

Returns a random color.

throw

Throws an error.