Skip to content

Repository files navigation

Path Slashes

npm Package VersionPackage DependenciesCoveralls githubGitHub Workflow StatusGitHub RepoLicense MIT

A javascript library to add or remove trailing and/or leading slashes in path strings, test for their existence or join path strings with slashes without duplicating them.


Install

This package is published to the npm registry as path-slahes.

You can install it:

# using npm:
npm install --save path-slashes
# using yarn:
yarn add path-slashes

ℹ️ HINT: This library is a pure ESM package. (You may want to read this.)

Usage Examples

import{hasLeadingSlash}from'path-slashes';// Check if given path has a leading slashhasLeadingSlash('/foo');// -> truehasLeadingSlash('foo');// -> false
import{hasTrailingSlash}from'path-slashes';// Check if given path has a trailing slashhasTrailingSlash('foo/');// -> truehasTrailingSlash('foo');// -> false
import{withLeadingSlash}from'path-slashes';// Ensure given path has a leading slashwithLeadingSlash('foo');// -> '/foo'
import{withTrailingSlash}from'path-slashes';// Ensure given path has a trailing slashwithTrailingSlash('foo');// -> 'foo/'
import{withoutLeadingSlash}from'path-slashes';// Ensure given path has no leading slashwithoutLeadingSlash('/foo/');// -> 'foo/'
import{withoutTrailingSlash}from'path-slashes';// Ensure given path has no trailing slashwithoutTrailingSlash('/foo/');// -> '/foo'
import{withSlashes}from'path-slashes';// Ensure given path has both leading and trailing slasheswithSlashes('foo');// -> '/foo/'
import{withoutSlashes}from'path-slashes';// Ensure given path has neither leading nor trailing slasheswithoutSlashes('/foo/');// -> 'foo'
import{slashJoin}from'path-slashes';// Join path parts and add slashes where necessaryslashJoin('foo','bar/','/baz');// -> 'foo/bar/baz'

API

functionhasLeadingSlash(path: string): boolean;
functionhasTrailingSlash(path: string): boolean;
functionwithLeadingSlash(path: string): string;
functionwithTrailingSlash(path: string): string;
functionwithSlashes(path: string): string;
functionwithoutLeadingSlash(path: string): string;
functionwithoutTrailingSlash(path: string): string;
functionwithoutSlashes(path: string): string;
functionslashJoin(...strings: (string|string[])[]): string;

License and Author

MIT © Simon Lepel

About

A javascript library to add or remove trailing and/or leading slashes in path strings, test for their existence or join path strings with slashes without duplicating them.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages