/**
 *
 * @param {string} source
 * @param {string} insert_term
 * @param {string} replace_term
 * @param {string} value
 * @returns {string}
 */
export function insert_after_or_replace(source, insert_term, replace_term, value) {
    const insert_term_index = source.indexOf(insert_term);

    if (insert_term_index !== -1) {
        const end = insert_term_index + insert_term.length;
        return source.slice(0, end) + value + source.slice(end);
    }

    const replace_term_index = source.indexOf(replace_term);

    if (replace_term_index === -1) {
        // not found
        console.warn(`Neither insert term '${insert_term}', nor replacement term '${replace_term}' were found in the source`, source, value);
        return source;
    }


    return source.slice(0, replace_term_index) + value + source.slice(replace_term_index + replace_term.length);
}
