npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

path-slashes

v2.0.1

Published

Adding or removing of trailing and/or leading slashes in strings, test for their existence or join strings with slashes without duplicating them.

Downloads

46

Readme

Path Slashes

npm Package Version Package Dependencies Coveralls github GitHub Workflow Status GitHub Repo License 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 slash
hasLeadingSlash('/foo'); // -> true
hasLeadingSlash('foo'); // -> false
import { hasTrailingSlash } from 'path-slashes';

// Check if given path has a trailing slash
hasTrailingSlash('foo/'); // -> true
hasTrailingSlash('foo'); // -> false
import { withLeadingSlash } from 'path-slashes';

// Ensure given path has a leading slash
withLeadingSlash('foo'); // -> '/foo'
import { withTrailingSlash } from 'path-slashes';

// Ensure given path has a trailing slash
withTrailingSlash('foo'); // -> 'foo/'
import { withoutLeadingSlash } from 'path-slashes';

// Ensure given path has no leading slash
withoutLeadingSlash('/foo/'); // -> 'foo/'
import { withoutTrailingSlash } from 'path-slashes';

// Ensure given path has no trailing slash
withoutTrailingSlash('/foo/'); // -> '/foo'
import { withSlashes } from 'path-slashes';

// Ensure given path has both leading and trailing slashes
withSlashes('foo'); // -> '/foo/'
import { withoutSlashes } from 'path-slashes';

// Ensure given path has neither leading nor trailing slashes
withoutSlashes('/foo/'); // -> 'foo'
import { slashJoin } from 'path-slashes';

// Join path parts and add slashes where necessary
slashJoin('foo', 'bar/', '/baz'); // -> 'foo/bar/baz'

API

function hasLeadingSlash(path: string): boolean;
function hasTrailingSlash(path: string): boolean;
function withLeadingSlash(path: string): string;
function withTrailingSlash(path: string): string;
function withSlashes(path: string): string;
function withoutLeadingSlash(path: string): string;
function withoutTrailingSlash(path: string): string;
function withoutSlashes(path: string): string;
function slashJoin(...strings: (string | string[])[]): string;

License and Author

MIT © Simon Lepel