From 5ba25ae6a1ec4da0032162a5241275db1a5683df Mon Sep 17 00:00:00 2001 From: Simon Lepel Date: Wed, 3 May 2023 10:06:11 +0200 Subject: [PATCH] update readme --- README.md | 128 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 96 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 77fce75..eec6845 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# path-slashes +# Path Slashes [![npm Package Version](https://img.shields.io/npm/v/path-slashes?)](https://www.npmjs.com/package/path-slashes) [![Package Dependencies](https://img.shields.io/badge/deps-none-4cc552)](https://www.npmjs.com/package/path-slashes?activeTab=dependencies) @@ -7,69 +7,133 @@ [![GitHub Repo](https://img.shields.io/badge/repo-public-87ceeb)](https://github.com/simbo/path-slashes) [![License MIT](https://img.shields.io/badge/license-MIT-4cc552)](http://simbo.mit-license.org/) -> Adding or removing of trailing and/or leading slashes in strings, test for -> their existence or join strings with slashes without duplicating them. Native -> Typescript support included. +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`](https://www.npmjs.com/package/path-slashes). + +You can install it: + ```sh -# using npm +# using npm: npm install --save path-slashes -# using yarn +# using yarn: yarn add path-slashes ``` -Or import it from a CDN: +ℹ️ **HINT**: This library is a pure ESM package. (You may want to +[read this](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).) -```html - -``` +## Usage Examples -```html - -``` +```js +import { hasLeadingSlash } from 'path-slashes'; -## Quick Start +// Check if given path has a leading slash +hasLeadingSlash('/foo'); // -> true +hasLeadingSlash('foo'); // -> false +``` ```js -// 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 +hasTrailingSlash('foo/'); // -> true +hasTrailingSlash('foo'); // -> false +``` + +```js +import { withLeadingSlash } from 'path-slashes'; // Ensure given path has a leading slash -withLeadingSlash('foo'); // => '/foo' +withLeadingSlash('foo'); // -> '/foo' +``` + +```js +import { withTrailingSlash } from 'path-slashes'; // Ensure given path has a trailing slash -withTrailingSlash('foo'); // => 'foo/' +withTrailingSlash('foo'); // -> 'foo/' +``` + +```js +import { withoutLeadingSlash } from 'path-slashes'; // Ensure given path has no leading slash -withoutLeadingSlash('/foo/'); // => 'foo/' +withoutLeadingSlash('/foo/'); // -> 'foo/' +``` + +```js +import { withoutTrailingSlash } from 'path-slashes'; // Ensure given path has no trailing slash -withoutTrailingSlash('/foo/'); // => '/foo' +withoutTrailingSlash('/foo/'); // -> '/foo' +``` + +```js +import { withSlashes } from 'path-slashes'; // Ensure given path has both leading and trailing slashes -withSlashes('foo'); // => '/foo/' +withSlashes('foo'); // -> '/foo/' +``` + +```js +import { withoutSlashes } from 'path-slashes'; // Ensure given path has neither leading nor trailing slashes -withoutSlashes('/foo/'); // => 'foo' +withoutSlashes('/foo/'); // -> 'foo' +``` + +```js +import { slashJoin } from 'path-slashes'; // Join path parts and add slashes where necessary -slashJoin('foo', 'bar/', '/baz'); // => 'foo/bar/baz' +slashJoin('foo', 'bar/', '/baz'); // -> 'foo/bar/baz' +``` + +## API + +```ts +function hasLeadingSlash(path: string): boolean; +``` + +```ts +function hasTrailingSlash(path: string): boolean; +``` + +```ts +function withLeadingSlash(path: string): string; +``` + +```ts +function withTrailingSlash(path: string): string; +``` + +```ts +function withSlashes(path: string): string; +``` + +```ts +function withoutLeadingSlash(path: string): string; +``` + +```ts +function withoutTrailingSlash(path: string): string; +``` + +```ts +function withoutSlashes(path: string): string; +``` + +```ts +function slashJoin(...strings: (string | string[])[]): string; ``` ## License and Author