# url-value-parser

> extracts and replaces values and IDs in URLs

Latest version **2.2.0** (published 2022-09-02) · MIT-0 license · 0 weekly downloads

## Install

```sh
npm install url-value-parser
pnpm add url-value-parser
yarn add url-value-parser
bun add url-value-parser
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.0 |
| Published | 2022-09-02 |
| First published | 2016-11-26 |
| Weekly downloads | 0 |
| License | MIT-0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=6.0.0 |
| Dependencies | 0 |
| Unpacked size | 7.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Konstantin Pogorelov |
| Maintainers | disjunction |
| Keywords | url, parse, replace, id |

## Links

- npm: https://www.npmjs.com/package/url-value-parser
- Repository: https://github.com/disjunction/url-value-parser
- Homepage: https://github.com/disjunction/url-value-parser#readme
- Issues: https://github.com/disjunction/url-value-parser/issues
- npm.io page: https://npm.io/package/url-value-parser

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 2.2.0 (latest) — 2022-09-02
- 2.1.0 — 2021-12-08
- 2.0.3 — 2021-04-22
- 2.0.1 — 2019-02-09
- 2.0.0 — 2018-08-08
- 1.0.0 — 2016-11-26

## README

[![build status](https://api.travis-ci.org/disjunction/url-value-parser.png)](https://travis-ci.org/disjunction/url-value-parser)
[![Coverage Status](https://coveralls.io/repos/github/disjunction/url-value-parser/badge.svg?branch=master&bust=1)](https://coveralls.io/github/disjunction/url-value-parser?branch=master)

# UrlValueParser

A helper ES6 class letting you extract values from URL paths,
leaving the other parts untouched.

It uses an internal class `ValueDetector` determining
what is a value and what is not. By default the following
path chunks are considered values:

* decimal numbers
* strings in UUID format
* hex numbers consisting of 7 or more characters
  and consistent lower or upper case
* long base64 encoded strings
* JSON Web Tokens (JWT)

You can customize all of the logic by providing options,
overriding methods or providing your own value detector.
See the source - it's easy, i promise.

## Usage

```javascript
const UrlValueParser = require('url-value-parser');
const parser = new UrlValueParser(/* {options} */);

parser.parsePathValues('/some/path/154/userId/ABC363AFE2');
/*
 here the values would be 154 and ABC363AFE2
 thus it returns:

  {
    chunks: ['some', 'path', '154', 'userId', 'ABC363AFE2'],
    valueIndexes: [2, 5]
  }
*/

parser.replacePathValues('/some/path/154/userId/ABC363AFE2', '#id');
// returns: /some/path/#id/userId/#id
```

## Options

* **replaceMasks** - use custom masks instead of built-in
* **extraMasks** - add your custom masks additionally to the built-in ones
* **minHexLength** - when using built-in masks, count only long enough HEX values, **DEFAULT: 7**
* **minBase64Length** - when using built-in masks, count only long enough base64 values, **DEFAULT: 66**

If strings are provided in an array to **replaceMasks** and **extraMasks**,
then they're automatically converted into RegExp

Example:

```javascript
const parser = new UrlValueParser({
  minHexLength: 4,
  extraMasks: [
    /^z_.*$/,
    '^[0-9]+\\.[0-9]+$'
  ]
});
```

## License

MIT No Attribution License

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