src/core/utils.js
function shiftLinesLeft(text) {
    // Determine type of linebreak
    let linebreak = determineLinebreaks(text);
    if (linebreak === "") return text;

    let lines = [];
    lines = text.split(linebreak);

    // Find amount to shift lines
    let commonPrefix = null;

    for (let i = 0; i < lines.length; i++) {
        if (!lines[i].length) continue;

        let whitespace = lines[i].match(/^\s*/);
        if (whitespace) whitespace = whitespace[0];
        else whitespace = "";

        if (commonPrefix === null || commonPrefix.startsWith(whitespace)) commonPrefix = whitespace;
    }

    // Shift lines and return result
    text = "";
    let shift = commonPrefix.length;

    for (let i = 0; i < lines.length; i++) {
        if (lines[i].length) {
            lines[i] = lines[i].slice(shift, lines[i].length);
        }

        text += lines[i] + linebreak;
    }

    return text;
}
function shiftLinesLeft(text) {
    // Determine type of linebreak
    let linebreak = determineLinebreaks(text);
    if (linebreak === "") return text;

    let lines = [];
    lines = text.split(linebreak);

    // Find amount to shift lines
    let commonPrefix = null;

    for (let i = 0; i < lines.length; i++) {
        if (!lines[i].length) continue;

        let whitespace = lines[i].match(/^\s*/);
        if (whitespace) whitespace = whitespace[0];
        else whitespace = "";

        if (commonPrefix === null || commonPrefix.startsWith(whitespace)) commonPrefix = whitespace;
    }

    // Shift lines and return result
    text = "";
    let shift = commonPrefix.length;

    for (let i = 0; i < lines.length; i++) {
        if (lines[i].length) {
            lines[i] = lines[i].slice(shift, lines[i].length);
        }

        text += lines[i] + linebreak;
    }

    return text;
}
function shiftLinesLeft ( text ) { // Determine type of linebreak let linebreak = determineLinebreaks ( text ) ; if ( linebreak === "" ) return text ; let lines = [ ] ; lines = text . split ( linebreak ) ; // Find amount to shift lines let commonPrefix = null ; for ( let i = 0 ; i < lines . length ; i ++ ) { if ( ! lines [ i ] . length ) continue ; let whitespace = lines [ i ] . match ( / ^\s* / ) ; if ( whitespace ) whitespace = whitespace [ 0 ] ; else whitespace = "" ; if ( commonPrefix === null || commonPrefix . startsWith ( whitespace ) ) commonPrefix = whitespace ; } // Shift lines and return result text = "" ; let shift = commonPrefix . length ; for ( let i = 0 ; i < lines . length ; i ++ ) { if ( lines [ i ] . length ) { lines [ i ] = lines [ i ] . slice ( shift , lines [ i ] . length ) ; } text += lines [ i ] + linebreak ; } return text ; }
This function takes a text string and shifts all lines to the left so that
as most leading spaces are removed as possible. All lines are shifted by
the same amount which is determined as the minimum amount of white space
at the beginning of all lines.

@param  {String} text Original text
@return {String} Shifted text
This function takes a text string and shifts all lines to the left so that as most leading spaces are removed as possible . All lines are shifted by the same amount which is determined as the minimum amount of white space at the beginning of all lines .