https://github.com/kaelzhang/node-pre-suf
Manipulate strings with prefixes and suffixes.
https://github.com/kaelzhang/node-pre-suf
manipulating-strings prefix suffix
Last synced: 9 months ago
JSON representation
Manipulate strings with prefixes and suffixes.
- Host: GitHub
- URL: https://github.com/kaelzhang/node-pre-suf
- Owner: kaelzhang
- License: other
- Created: 2016-07-12T13:11:39.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2019-03-17T12:12:45.000Z (over 7 years ago)
- Last Synced: 2025-09-30T18:34:45.354Z (9 months ago)
- Topics: manipulating-strings, prefix, suffix
- Language: JavaScript
- Size: 7.81 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-MIT
Awesome Lists containing this project
README
[](https://travis-ci.org/kaelzhang/node-pre-suf)
# pre-suf
Manipulate strings with prefixes and suffixes.
## Install
```sh
$ npm install pre-suf --save
```
## Usage
```js
const presuf = require('pre-suf')
presuf.ensureLeading('path/to', '/') // '/path/to'
presuf.removeEnding('/path/to//', '/') // '/path/to'
```
### presuf.ensureLeading(str, prefix)
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`.
### presuf.removeLeading(str, prefix)
Removes the leading `prefix` of `str`.
```js
presuf.removeLeading('/abc', '/a') // 'bc'
presuf.removeLeading('/a/abc', '/a') // 'bc'. removes 2 groups of '/a'
```
### presuf.ensureEnding(str, suffix)
### presuf.removeEnding(str, suffix)
## License
MIT