1.0.11 • Published 3 years ago

@googlicius/build-url v1.0.11

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Build URL

A helper to build url with query params as easy way. Helpful when your application routing or state management based on URL query params.

Installation

npm install @googlicius/build-url

Or Yarn:

yarn add @googlicius/buil-url

Usage

import buildUrl from '@googlicius/build-url';

buildUrl('http://my-website.com/post', {
  queryParams: {
    page: 2,
  },
});

// Output: http://my-website.com/post?page=2

Add another query param

buildUrl('http://my-website.com/post?page=2', {
  queryParams: {
    sort: 'title:asc',
  },
});

// Output: http://my-website.com/post?page=2&sort=title%3Aasc

Input url/path is omitted

buildUrl({
  queryParams: {
    sort: 'title:asc',
  },
});

// Output: /?sort=title%3Aasc

Remove a query param

buildUrl('images?page=2&sort=title:asc', {
  queryParams: {
    page: null,
  },
});

// Output: /images?sort=title%3Aasc

Always returns absolute url

// Assume that current url is: http://awesome-website.com

buildUrl('/posts', {
  returnAbsoluteUrl: true,
  queryParams: {
    page: 2,
  },
});

// Output: http://awesome-website.com/posts?page=2

License

MIT

1.0.9

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.4

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago