/**
 *
 * @param {string} string
 * @param {string} trailing_sequence
 * @returns {string}
 */
export function string_strip_trailing(string, trailing_sequence) {
    const trailing_sequence_length = trailing_sequence.length;

    if (trailing_sequence_length <= 0) {
        // special case to avoid infinite looping
        return string;
    }

    let end_index = string.length;

    while (string.substring(end_index - trailing_sequence_length, end_index) === trailing_sequence) {
        end_index -= trailing_sequence_length;
    }

    return string.substring(0, end_index);
}