esamattis / esamattis/underscore.string
New function 'around()' to surround a substring with a string
Open
- Dominant language
- JavaScript
- Stars
- 3.4k
- Forks
- 367
- PR merge metrics
- No merged PRs in 30d
Description
`surround` itself is limited, as I would like to add something arround a substring, not the entire string.
Example:
```
around("1234x6789", 5, '>>', '<<'); // -> "1234>>x<<6789"
around("1234x6789", 4, 6, '>>', '<<'); // -> "123>>4x6<<789"
around("This is an apple", 8, 10, '[', ']'); // -> "This is [an] apple"
around("This is an apple", 'apple', '[', ']'); // -> "This is an [apple]"
around("This is pretty awesome!", /pre(tt)y/, ':', ':'); // -> "This is pre:tt:y awesome!"
```
Or something along these lines...
Right now I can only do it by manually doing 2 slices or splices.
Contributor guide
Assessment
This issue has not been assessed yet.