# trailing-slash-it

> Add or remove trailing slashes.

Latest version **0.3.0** (published 2017-02-21) · GPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install trailing-slash-it
pnpm add trailing-slash-it
yarn add trailing-slash-it
bun add trailing-slash-it
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2017-02-21 |
| First published | 2016-12-19 |
| Weekly downloads | 0 |
| License | GPL-3.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | misund |
| Maintainers | misund |
| Keywords | trailing slashes, forward slashes, backslashes, slashes, string manipulation |

## Links

- npm: https://www.npmjs.com/package/trailing-slash-it
- Repository: https://github.com/misund/trailing-slash-it
- Homepage: https://github.com/misund/trailing-slash-it#readme
- Issues: https://github.com/misund/trailing-slash-it/issues
- npm.io page: https://npm.io/package/trailing-slash-it

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 0.3.0 (latest) — 2017-02-21
- 0.2.2 — 2017-02-20
- 0.2.1 — 2017-02-20
- 0.2.0 — 2017-01-19
- 0.1.1 — 2016-12-19
- 0.1.0 — 2016-12-19

## README

[![Build Status](https://travis-ci.org/misund/trailing-slash-it.svg?branch=master)](https://travis-ci.org/misund/trailing-slash-it)

`trailing-slash-it` appends a forward slash to a string. It will remove trailing
forward slashes if they exist already, before adding a trailing forward
slash. This prevents double slashing a string or path.

## Install

```
$ npm install --save trailing-slash-it
```

## Usage

```js
var trailingSlashIt = require('trailing-slash-it');

trailingSlashIt('foo'); // 'foo/'

trailingSlashIt('foo/'); // 'foo/'
trailingSlashIt('foo//'); // 'foo/'
trailingSlashIt('foo///'); // 'foo/'

trailingSlashIt('foo\\'); // 'foo/'
trailingSlashIt('foo\\\\'); // 'foo/'
trailingSlashIt('foo\\/\\/'); // 'foo/'
```

If you need to make sure that something does NOT have a trailing slash, you can
do that as well:

```js
import {
  trailingSlashIt,
  unTrailingSlashIt,
} from 'trailing-slash-it';

trailingSlashIt('foo'); // 'foo/'

unTrailingSlashIt('foo'); // 'foo'

unTrailingSlashIt('foo/'); // 'foo'
unTrailingSlashIt('foo//'); // 'foo'
unTrailingSlashIt('foo///'); // 'foo'

unTrailingSlashIt('foo\\'); // 'foo'
unTrailingSlashIt('foo\\\\'); // 'foo'
unTrailingSlashIt('foo\\/\\/'); // 'foo'
```

Based on WordPress' PHP function [trailingslashit()](https://github.com/WordPress/WordPress/blob/c7988f1f0311a8a3eadfe9a78c0c82971822d728/wp-includes/formatting.php#L2357-L2388).

## Changelog

0.3.0 - Strip backslashes as well as forward slashes.

## License

GNU GPLv3

---
_Source: https://npm.io/package/trailing-slash-it · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
