1.0.1 • Published 4 years ago

url-path-sanitizer v1.0.1

Weekly downloads
179
License
MIT
Repository
github
Last release
4 years ago

Greenkeeper badge Build Status codecov npm npm

url-path-sanitizer

Strip any URL path part with a digit and replace with a placeholder

Installation

npm install url-path-sanitizer
yarn add url-path-sanitizer

Usage

urlPathSanitizer

  • url property is the URL to sanitize - this property is required
  • placeholder - value to replace url path parts with digits. Default is [:id]
  • whitelist - values to ignore when evaluating if it contains a digit
import urlPathSanitizer from 'url-path-sanitizer';

urlPathSanitizer({ url: '/some/path/with/an/id/1' }); // /some/path/with/an/[:id]
urlPathSanitizer({ url: '/another/path/with/an/id/1', placeholder: 'jae' }); // /another/path/with/an/id/jae
urlPathSanitizer({ url: '/a/path/without/a/digit' }); // /a/path/without/a/digit
urlPathSanitizer({ url: '/v1/some/whitelisted/path', whitelist: ['v1'] }); // /v1/some/whitelisted/path