Giter Site home page Giter Site logo

simbo / path-slashes Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 493 KB

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.

License: MIT License

JavaScript 7.65% TypeScript 67.89% Shell 24.47%
javascript typescript string slash path join leading trailing slashes

path-slashes's Introduction

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

path-slashes's People

Contributors

simbo avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.