An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

[![Build Status](https://travis-ci.org/kaelzhang/node-pre-suf.svg?branch=master)](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