Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jillix/url.js
:page_with_curl: A lightweight JavaScript library to manipulate the page url.
https://github.com/jillix/url.js
Last synced: 5 days ago
JSON representation
:page_with_curl: A lightweight JavaScript library to manipulate the page url.
- Host: GitHub
- URL: https://github.com/jillix/url.js
- Owner: jillix
- License: mit
- Created: 2014-02-18T15:43:28.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2023-03-06T15:40:45.000Z (over 1 year ago)
- Last Synced: 2024-05-02T06:15:00.607Z (6 months ago)
- Language: CSS
- Homepage: http://jillix.github.io/url.js
- Size: 912 KB
- Stars: 248
- Watchers: 16
- Forks: 25
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# url.js
[![Version](https://img.shields.io/npm/v/urljs.svg)](https://www.npmjs.com/package/urljs) [![Downloads](https://img.shields.io/npm/dt/urljs.svg)](https://www.npmjs.com/package/urljs)
> A lightweight JavaScript library to manipulate the page url.
## Demo
Browse the demos on http://jillix.github.io/url.js/
[![](http://i.imgur.com/BYxaxU1.png)](http://jillix.github.io/url.js/)
## CDN
The library is available on [CDNJS](https://cdnjs.com/libraries/urljs) as well. To use it, just do:
```html
```
## Usage
```html
Url.updateSearchParam("answer", 42);
```
## CommonJS-compatible
The library is CommonJS-compatible. You can `require("url.js")` in your files.
## :cloud: Installation
Check out the [`dist`](/dist) directory to download the needed files and include them on your page.
If you're using this module in a CommonJS environment, you can install it using `npm` or `yarn` and `require` it:
```sh
# Using npm
npm install --save urljs# Using yarn
yarn add urljs
```## :question: Get Help
There are few ways to get help:
1. Please [post questions on Stack Overflow](https://stackoverflow.com/questions/ask). You can open issues with questions, as long you add a link to your Stack Overflow question.
2. For bug reports and feature requests, open issues. :bug:## :memo: Documentation
### `queryString(name, notDecoded)`
Finds the value of parameter passed in first argument.#### Params
- **String** `name`: The parameter name.
- **Boolean** `notDecoded`: If `true`, the result will be encoded.#### Return
- **String|Boolean|Undefined** The parameter value (as string), `true` if the parameter is there, but doesn't have a value, or
`undefined` if it is missing.### `parseQuery(search)`
Parses a string as querystring. Like the `queryString` method does, if
the parameter is there, but it doesn't have a value, the value will
be `true`.#### Params
- **String** `search`: An optional string that should be parsed (default: `window.location.search`).
#### Return
- **Object** The parsed querystring. Note this will contain empty strings for### `stringify(queryObj)`
Stringifies a query object.#### Params
- **Object** `queryObj`: The object that should be stringified.
#### Return
- **String** The stringified value of `queryObj` object.### `updateSearchParam(param, value, push, triggerPopState)`
Adds, updates or deletes a parameter (without page refresh).#### Params
- **String|Object** `param`: The parameter name or name-value pairs as object.
- **String** `value`: The parameter value. If `undefined`, the parameter will be removed.
- **Boolean** `push`: If `true`, the page will be kept in the history, otherwise the location will be changed but by pressing the back button
will not bring you to the old location.
- **Boolean** `triggerPopState`: Triggers the popstate handlers (by default falsly).#### Return
- **Url** The `Url` object.### `getLocation(excludeHash)`
Returns the page url, but not including the domain name.#### Params
- **Boolean** `excludeHash`: If `true`, the location hash will not be appended in the result.
#### Return
- **String** The page url (without domain).### `hash(newHash, triggerPopState)`
Sets/gets the hash value.#### Params
- **String** `newHash`: The hash to set.
- **Boolean** `triggerPopState`: Triggers the hashchange (by default falsly).#### Return
- **String** The location hash.### `_updateAll(s, push, triggerPopState)`
Update the full url (pathname, search, hash).#### Params
- **String** `s`: The new url to set.
- **Boolean** `push`: If `true`, the page will be kept in the history, otherwise the location will be changed but by pressing the back button
will not bring you to the old location.
- **Boolean** `triggerPopState`: Triggers the popstate handlers (by default falsly).#### Return
- **String** The set url.### `pathname(pathname, push, triggerPopState)`
Sets/gets the pathname.#### Params
- **String** `pathname`: The pathname to set.
- **Boolean** `push`: If `true`, the page will be kept in the history, otherwise the location will be changed but by pressing the back button
will not bring you to the old location.
- **Boolean** `triggerPopState`: Triggers the popstate handlers (by default falsly).#### Return
- **String** The set url.### `triggerHashchangeCb()`
Calls the hashchange handlers.### `triggerPopStateCb()`
Calls the popstate handlers.### `onPopState(cb)`
Adds a popstate handler.#### Params
- **Function** `cb`: The callback function.
### `onHashchange(cb)`
Adds a hashchange handler.#### Params
- **Function** `cb`: The callback function.
### `removeHash(push, trigger)`
Removes the hash from the url.#### Params
- **Boolean** `push`: If `true`, the page will be kept in the history, otherwise the location will be changed but by pressing the back button
will not bring you to the old location.
- **Boolean** `trigger`: Triggers the popstate handlers (by default falsly).### `removeQuery(push, trigger)`
Removes the querystring parameters from the url.#### Params
- **Boolean** `push`: If `true`, the page will be kept in the history, otherwise the location will be changed but by pressing the back button
will not bring you to the old location.
- **Boolean** `trigger`: Triggers the popstate handlers (by default falsly).## :yum: How to contribute
Have an idea? Found a bug? See [how to contribute][contributing].## :dizzy: Where is this library used?
If you are using this library in one of your projects, add it in this list. :sparkles:- `ember-cli-mocha-reporter`
## :scroll: License
[MIT][license] © [jillix][website]
[license]: /LICENSE
[website]: http://jillix.com
[contributing]: /CONTRIBUTING.md
[docs]: /DOCUMENTATION.md