# path-path

> path-path, transform pathname to regular expressions

Latest version **0.1.0** (published 2018-08-30) · ISC license · 0 weekly downloads

## Install

```sh
npm install path-path
pnpm add path-path
yarn add path-path
bun add path-path
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2018-08-30 |
| First published | 2018-08-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 189.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Matias Trujillo Olivares |
| Maintainers | uppercod |

## Links

- npm: https://www.npmjs.com/package/path-path
- Repository: https://github.com/UpperCod/path-path
- Homepage: https://github.com/UpperCod/path-path#readme
- Issues: https://github.com/UpperCod/path-path/issues
- npm.io page: https://npm.io/package/path-path

## Recent versions

- 0.1.0 (latest) — 2018-08-30
- 0.0.4 — 2018-08-27
- 0.0.3 — 2018-08-26
- 0.0.2 — 2018-08-26
- 0.0.1 — 2018-08-26
- 0.0.0 — 2018-08-26

## README

# path-path

Create a regular expression to compare pathnames based on wildcards, similar to how **Express.js** does it, all in <760 bytes gzip.

## create( path: string ):{ path: string, regExp: RegExp, params: array }

This function allows transforming the expression based on wildcards to a regular expression, with capture of parameters, this returns an object that is composed of the following properties:

* path : {string},  Is the origin of the expression.
* regExp : {RegExp}, Is the regular expression create from `path`.
* params : {array}, Are the parameters associative with the `path`

### Static pathname

```js
import {create} from "path-path";
create("/folder")
```

### Pathname with parameter

```js
import {create} from "path-path";
create("/:folder")
```

### Pathname with optional parameter

```js
import {create} from "path-path";
create("/:folder?")
```

### Pathname with optional parameter of multiple captures

```js
import {create} from "path-path";
create("/folder/:any...")
```


### Static pathname any

```js
import {create} from "path-path";
create("/folder/**")
```

## getSearch( search: string, params?: Object = {} )

allows to obtain from a URL, the `search` parameters associated with it.

```js
import {getSearch} from "path-path";
getSearch("id=10&url=www.example.com?id=100") // {id: 10, url: "www.example.com?id=100"}
```

## compare( route: return create, path: string, params?: = {} )

Verify if `path` is a valid route for `route`, it also obtains the search parameters of the route, if true, the comparison returns an object with the parameters of the route.

```js
import {create, compare} from "path-path";

let route = create("/folder/:subfolder");

compare(route,"/parent/child") // {subfolder: "child"}
compare(route,"/parent") // false

```
## resolve(origin: string, merge:string)

Permite promediar 2 pathname tomado como base merge, esta función trabaja con las mismas expresiones asociadas a `create`.

```js
import {resolve} from "path-path";

resolve("/parent/child","/**/next") // "/parent/next"

resolve("/parent/child/subchild","/parent/:any...") // "/parent/child/subchild"

resolve("/parent/child","/**") // "/parent"
```

## join(a:string,b:string)

It allows joining 2 path, averaging the intersection with the slash character **"/"**.

```js
import {join} from "path-path";

join("/a","/b") // /a/b
join("/a","b") // /a/b
join("/a/","b") // /a/b
```

---
_Source: https://npm.io/package/path-path · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
