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
var trailingSlashIt = require('trailing-slash-it');
trailingSlashIt('foo');
trailingSlashIt('foo/');
trailingSlashIt('foo//');
trailingSlashIt('foo///');
If you need to make sure that something does NOT have a trailing slash, you can
do that as well:
import {
trailingSlashIt,
unTrailingSlashIt,
} from 'trailing-slash-it';
trailingSlashIt('foo');
unTrailingSlashIt('foo');
unTrailingSlashIt('foo/');
unTrailingSlashIt('foo//');
unTrailingSlashIt('foo///');
Based on WordPress' PHP function trailingslashit().
License
GNU GPLv3