function trimFirstAndLastLines(str)
    {
        return str.replace(/^[ ]*[\n]+|[\n]*[ ]*$/g, '');
    }
This is a special trim which only removes first and last empty lines
and doesn't affect valid leading space on the first line.

@param {String} str   Input string
@return {String}      Returns string without empty first and last lines.