math

Functions group for work with numeric values.

get-numeric

Transforms a given pseudo-number string to a real number.

Arguments:

NameTypeDefaultDescription
$value *string | numberThe input value (number or pseudo-number string).

Returns:

?number - Numeric value, or null if value is not a valid number.

Example:

@use 'more-sass' as more;

@debug more.get-numeric('12px'); // number: 12px
@debug more.get-numeric('foo'); // null

get-unit

Retrieves a unit of a given number.

Arguments:

NameTypeDefaultDescription
$value *string | numberThe number or pseudo-number string to get its unit.

Returns:

?number - A number representing the base value of received unit (1px, 1em, etc.), or null if value is not a valid number.

Example:

@use 'more-sass' as more;

@debug more.get-unit(12px);  // number: 1px
@debug more.get-unit('12%'); // number: 1%

strip-unit

Strips the unit of a given value.

Arguments:

NameTypeDefaultDescription
$value *string | numberThe number or pseudo-number string to to remove unit from.

Returns:

?number - The unitless number or null if value is not a valid number.

Example:

@use 'more-sass' as more;

@debug more.strip-unit(12px);  // number: 12
@debug more.strip-unit('10%'); // number: 10

with-unit

Sets default unit for a given unitless number.

Arguments:

NameTypeDefaultDescription
$value *string | numberThe input value (number or pseudo-number string).
$unitstringpxDefault unit (one of valid CSS units).

Returns:

number - Original number transformed to a given unit.

Example:

@use 'more-sass' as more;
@debug more.with-unit(12);       // number: 12px
@debug more.with-unit(12, 'em'); // number: 12em
Edit this page on GitHub Updated at Mon, Jan 30, 2023