# super-url-path

> A super library for formatting URL paths, similar to TS static grammar detection.

Latest version **1.0.1** (published 2019-03-01) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2019-03-01 |
| First published | 2019-02-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | evio |
| Maintainers | evio |
| Keywords | url, regexp, path, format |

## Links

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

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2019-03-01
- 1.0.0 — 2019-02-28

## README

# super-url-path

A super library for formatting URL paths, similar to TS static grammar detection.

## Install

```shell
npm i super-url-path
```

## Usage

Usually it is used in this way:

```javascript
const SuperUrlPath = require('SuperUrlPath');
const uri = new SuperUrlPath('/abc/des/abc-d_:{abc:string}*x--a{cde?:number}-d/test{value:string}');
console.log(uri.exec('/abc/des/abc-d_:dista*x--a123-d/testdd'));
console.log(uri.router({
  abc: 'dddd',
  cde: 345,
  value: 'dafa'
}))
```

## Variable Grammar

it likes typescript:

```shell
abc: string
# or
abc?: string
```

You should use it like this:

```shell
/abc/des/abc-d_:{abc:string}*x--a{cde?:number}-d/test{value:string}
```

### uri.router(options)

create a new url by options.

```javascript
uri.router({
  abc: 'dddd',
  cde: 345,
  value: 'dafa'
}))
```

### uri.match(url)

Judging whether URL conforms to the rules. it returns a boolean value.

```javascript
uri.match('/abc/des/abc-d_:dista*x--a123-d/testdd'); // true or false
```

### uri.exec(url)

Get the value of the variable from the rule and return a JSON data format

```javascript
const SuperUrlPath = require('SuperUrlPath');
const uri = new SuperUrlPath('/abc/des/abc-d_:{abc:string}*x--a{cde?:number}-d/test{value:string}');
console.log(uri.exec('/abc/des/abc-d_:dista*x--a123-d/testdd'));
// => { abc: 'dista', cde: '123', value: 'dd' }
```

## Add custom data format

use `SuperUrlPath.addType(name, regexp_string)`

- **name** `string` the datatype name.
- **regexp_string** `string` a String Regular Expression.

```javascript
const SuperUrlPath = require('SuperUrlPath');
SuperUrlPath.addType('user_id', 'user_(\\d+)_uuid_[a-zA-Z0-9]');
// then you can use like this
const uri = new SuperUrlPath('/interface/api/user/custom_{user: user_id}/{id: number}');
```

# License

`super-url-path` is [MIT licensed](https://opensource.org/licenses/MIT).

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