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?
From an API point of view, I think the current signature of
trimis misleading. Per the documentation:At first, I thought that using
'12_'as the second argument would trim the target string if it starts and/or ends with the substring12_; 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:
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?