Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
simbo committed May 3, 2023
1 parent 3b52d5b commit 5ba25ae
Showing 1 changed file with 96 additions and 32 deletions.
128 changes: 96 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
<script
type="module"
src="https://cdn.jsdelivr.net/npm/path-slashes/dist/path-slashes.modern.js"
></script>
```
## Usage Examples

```html
<script
type="module"
src="https://unpkg.com/browse/path-slashes/dist/path-slashes.modern.js"
></script>
```
```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
Expand Down

0 comments on commit 5ba25ae

Please sign in to comment.