Skip to content

Enhance _.surround() with leftWrapper and rightWrapper instead of just wrapper #303

@taivo

Description

@taivo

Currently surround allows only 1 wrapper parameter. Allowing an optional 2nd wrapper parameter would make it useful for enclosing a string with HTML tags or parentheses and brackets.

Here is the current surround implementation:

surround: function(str, wrapper) {
    return [wrapper, str, wrapper].join('');
}

May I suggest we upgrade it to this:

surround: function(str, lWrapper, rWrapper) {
    return [lWrapper, str, rWrapper || lWrapper].join('');
}

Just throwing this out there because I thought it can be useful. If there is no objection or obvious flaw with the suggested change, I will put in a PR by tomorrow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions