Skip to content

The trim function signature is (somewhat) misleading #464

@fvilers

Description

@fvilers

From an API point of view, I think the current signature of trim is misleading. Per the documentation:

Trim also handles more than one character to trim.

trim('222__hello__111', '12_') // => hello

At first, I thought that using '12_' as the second argument would trim the target string if it starts and/or ends with the substring 12_; not that every character from '12_' are trimmed from the target. I'd found if more logical that the second argument is an array of potential character/string to be trimmed.

For example:

trim('222__hello__111', ['1', '2', '_']) // => hello

// Or
trim('222__hello__111', Array.from('12_')) // => hello

I know that this would break the current API and would need to deprecate the current signature but this looks more natural/logical.

What do you think?

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