@charset "UTF-8";

// @description
// * cut-unit function.
// * This function cuts or strips the unit from a given number.

// @access private

// @version 1.3.1

// @author Kitty Giraudel
// @link https://css-tricks.com/snippets/sass/strip-unit-function/

// @license MIT

// @repository: https://github.com/Black-Axis/sass-pire

// @namespace global

// @module global/cut-unit

// @dependencies:
// * - meta.type-of (SASS function).
// * - math.is-unitless (SASS function).
// * - math.div (SASS function).
// * - Error.throw (function).

// @update We updated the usage of the math library of Sass and added
// * more validations.

// @param {Number} $num
// * The value from which the unit will be cut or stripped.

// @throw {Exception}
// * Throws an exception if the parameter is not a number.

// @example
// * .example {
// *   content: cut-unit(12cm);
// * }

// @output
// * .example {
// *   content: 12;
// * }

// @return {Number} - A number after cutting or stripping the unit.

@use "sass:meta";
@use "sass:math";
@use "../../development-utils/toggle-error-message" as Error;

@function cut-unit($num) {
    @if meta.type-of($num) != number {
        @return Error.throw("The parameter of cut-unit function must be in a number type.");
    }

    // stylelint-disable-next-line length-zero-no-unit
    @if math.unit($num) == "" and not math.is-unitless($num) {
        @return Error.throw("The parameter does not need a unit if it equals to zero.");
    }

    @if meta.type-of($num) == number and not math.is-unitless($num) {
        @return math.div($num, ($num * 0 + 1));
    }

    @return $num;
}
