JSPM

url-value-parser

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 638169
  • Score
    100M100P100Q185731F
  • License WTFPL

extracts and replaces values and IDs in URLs

Package Exports

  • url-value-parser

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (url-value-parser) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

build status Coverage Status

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

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

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

For options, see the source