devalue-url

A small package to strip values out of a url to get its template

Usage no npm install needed!

<script type="module">
  import devalueUrl from 'https://cdn.skypack.dev/devalue-url';
</script>

README

Devalue URL

Actions Status

Friendly, typed package used to strip values out of URLs, leaving only the URL template, as it might appear in an express app, for example.

Installing

npm install devalue-url

Usage

import { UrlDevaluer } from 'devalue-url';
const urlDevaluer = new UrlDevaluer();
urlDevaluer.devalueUrl('www.example.com/hello/123');
// www.example.com/hello/:intId

Custom Patterns

import { UrlDevaluer } from 'devalue-url';
const urlDevaluer = new UrlDevaluer({
    extraTemplatePatterns: {
        'abcReplacementName': RegExp('abc'),
        'defReplacementName': 'def'
    }
});
urlDevaluer.devalueUrl('www.example.com/hello/abc/def');
// www.example.com/hello/:abcReplacementName/:defReplacementName

Local Setup

git clone https://github.com/briankopp/devalue-url
cd devalue-url
npm install
npm run build
npm run test