Manipulate strings with prefixes and suffixes.
$ npm install pre-suf --save
const presuf = require('pre-suf')
presuf.ensureLeading('path/to', '/') // '/path/to'
presuf.removeEnding('/path/to//', '/') // '/path/to'
Ensures that the new string will have prefix
at the beginning of str
.
If str
does not begin with prefix
, prefix
will be added to the beggining of str
.
Removes the leading prefix
of str
.
presuf.removeLeading('/abc', '/a') // 'bc'
presuf.removeLeading('/a/abc', '/a') // 'bc'. removes 2 groups of '/a'
MIT