Package Exports
- @spomni/unify-url
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 (@spomni/unify-url) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@spomni/unify-url
Abstract
The function to unify query part of the url string.
This function removes query parameters with no values and sorts the rest of them.
Install
npm i @spomni/unify-urlUsage
const unifyUrl = require('@spomni/unify-url')
const unsortedUrl = 'http://some.dom/pa/th?p2=v2&p1=v1#hash'
const withoutValuesUrl = 'http://some.dom/pa/th?p1=v1&p3=&p4&p2=v2#hash'
const unifiedUnsorted = unifyUrl(unsortedUrl)
const unifiedWithoutValue = unifyUrl(withoutValuesUrl)
console.log(unifiedUnsorted) // => http://some.dom/pa/th?p1=v1&p2=v2#hash
console.log(unifiedUnsorted === unifiedWithoutValue) // => trueExceptions
The unifyUrl(url) function throws an instance of UnifyUrlError on the next cases:
- the "url" argument is not string;
- an url contains more than one "?" characters;
- an url contains more than one "#" characters rightly from the "?";
- any query param contains more than one "=" characters;