lib/libbase64.js
function wrap(str, lineLength) {
    str = (str || '').toString();
    lineLength = lineLength || 76;

    if (str.length <= lineLength) {
        return str;
    }

    let result = [];
    let pos = 0;
    let chunkLength = lineLength * 1024;
    while (pos < str.length) {
        let wrappedLines = str
            .substr(pos, chunkLength)
            .replace(new RegExp('.{' + lineLength + '}', 'g'), '$&\r\n')
            .trim();
        result.push(wrappedLines);
        pos += chunkLength;
    }

    return result.join('\r\n').trim();
}
function wrap(str, lineLength) {
    str = (str || '').toString();
    lineLength = lineLength || 76;

    if (str.length <= lineLength) {
        return str;
    }

    let result = [];
    let pos = 0;
    let chunkLength = lineLength * 1024;
    while (pos < str.length) {
        let wrappedLines = str
            .substr(pos, chunkLength)
            .replace(new RegExp('.{' + lineLength + '}', 'g'), '$&\r\n')
            .trim();
        result.push(wrappedLines);
        pos += chunkLength;
    }

    return result.join('\r\n').trim();
}
function wrap ( str , lineLength ) { str = ( str || '' ) . toString ( ) ; lineLength = lineLength || 76 ; if ( str . length <= lineLength ) { return str ; } let result = [ ] ; let pos = 0 ; let chunkLength = lineLength * 1024 ; while ( pos < str . length ) { let wrappedLines = str . substr ( pos , chunkLength ) . replace ( new RegExp ( '.{' + lineLength + '}' , 'g' ) , '$&\r\n' ) . trim ( ) ; result . push ( wrappedLines ) ; pos += chunkLength ; } return result . join ( '\r\n' ) . trim ( ) ; }
Adds soft line breaks to a base64 string

@param {String} str base64 encoded string that might need line wrapping
@param {Number} [lineLength=76] Maximum allowed length for a line
@returns {String} Soft-wrapped base64 encoded string
Adds soft line breaks to a base64 string