@charset "UTF-8";

// @description
// * trim-end function.
// * This function removes all right whitespace from a given string.

// @access public

// @version 1.0.0

// @author roydukkey
// @link https://github.com/roydukkey/sass-fairy/blob/master/packages/string/src/_trim-end.sass

// @license MIT

// @repository: https://github.com/Black-Axis/sass-pire

// @namespace global

// @module global/trim-end

// @dependencies:
// * - meta.type-of (SASS function).
// * - string.index (SASS function).
// * - string.slice (SASS function).
// * - Error.throw (function).

// @update We updated the core of trim-end function and converted it
// * to SCSS language.

// @param {String} $str-value
// * The value which will be used to trim whitespace from the right.

// @throw {Exception}
// * Throws an exception if the parameter is not a string.

// @example
// * .example {
// *   content: trim-end("   Just an example   ");
// * }

// @output
// * .example {
// *   content: "   Just an example";
// * }

// @return {String} - A value after trim whitespace from start.

@use "sass:meta";
@use "sass:list";
@use "sass:string";
@use "../../development-utils/toggle-error-message" as Error;

@function trim-end($str-value) {
    @if meta.type-of($str-value) != "string" {
        @return Error.throw("The parameter of trim-end function must be in a string type.");
    }

    $whitespace: " ", "\000C", "\000A", "\000D", "\0009", "\000B", "\00A0", "\1680", "\2000", "\2001", "\2002", "\2003",
        "\2004", "\2005", "\2006", "\2007", "\2008", "\2009", "\200A", "\2028", "\2029", "\202F", "\205F", "\3000",
        "\FEFF";

    @while list.index($whitespace, string.slice($str-value, string.length($str-value), -1)) {
        $str-value: string.slice($str-value, 1, -2);
    }

    @return $str-value;
}
