Skip to content

Commit

Permalink
📝
Browse files Browse the repository at this point in the history
  • Loading branch information
IonicaBizau committed Jan 4, 2016
1 parent f321bde commit f78cb4a
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 18 deletions.
70 changes: 56 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
# url.js

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
<script src="https://cdnjs.cloudflare.com/ajax/libs/urljs/1.2.0/url.min.js"></script>
```

## Usage

```html
<script src="path/to/url.js"></script>
<!-- or use the cdn
Expand All @@ -24,6 +25,13 @@ The library is available on [CDNJS](https://cdnjs.com/libraries/urljs) as well.
Url.updateSearchParam("answer", 42);
</script>
```
## CommonJS-compatible

The library is CommonJS-compatible. You can `require("url.js")` in your files.

## Installation

Check out the [`src`](/src) directory to download the needed files and include them on your page.

## Documentation

Expand All @@ -35,16 +43,19 @@ Finds the value of parameter passed in first argument.
- **Boolean** `notDecoded`: If `true`, the result will be encoded.

#### Return
- **String** The parameter value.
- **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.
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.
- **Object** The parsed querystring. Note this will contain empty strings for

### `stringify(queryObj)`
Stringifies a query object.
Expand All @@ -71,15 +82,46 @@ Returns the page url, but not including the domain name.
#### Return
- **String** The page url (without domain).

### `getLocation(newHash)`
hash
Sets/gets the hash value.

#### Params
- **String** `newHash`: The hash to set.

#### Return
- **String** The location hash.

### `_updateAll(newHash)`
Update the full url (pathname, search, hash).

#### Params
- **String** `newHash`: The hash to set.

#### Return
- **String** The set url.

### `getLocation(pathname)`
pathname
Sets/gets the pathname.

#### Params
- **String** `pathname`: The pathname to set.

#### Return
- **String** The set url.

## How to contribute
1. File an issue in the repository, using the bug tracker, describing the
contribution you'd like to make. This will help us to get you started on the
right foot.
2. Fork the project in your account and create a new branch:
`your-great-feature`.
3. Commit your changes in that branch.
4. Open a pull request, and reference the initial issue in the pull request
message.
Have an idea? Found a bug? See [how to contribute][contributing].

## Where is this library used?
If you are using this library in one of your projects, add it in this list. :sparkles:

## License
See the [LICENSE](./LICENSE) file.

[MIT][license] © [jillix][website]

[license]: http://showalicense.com/?fullname=jillix%20%3Ccontact%40jillix.com%3E%20(http%3A%2F%2Fjillix.com)&year=2014#license-mit
[website]: http://jillix.com
[contributing]: /CONTRIBUTING.md
[docs]: /DOCUMENTATION.md
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Url = module.exports = {
module.exports = {
/**
* queryString
* Finds the value of parameter passed in first argument.
Expand Down
54 changes: 51 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "A lightweight JavaScript library to manipulate the page url.",
"main": "lib/index.js",
"directories": {
"example": "example"
"example": "example",
"test": "test"
},
"scripts": {
"test": "node test",
Expand All @@ -16,14 +17,14 @@
],
"repository": {
"type": "git",
"url": "https://github.com/jillix/url.js.git"
"url": "git+https://github.com/jillix/url.js.git"
},
"keywords": [
"url",
"manipulate",
"browser"
],
"author": "jillix <[email protected]>",
"author": "jillix <[email protected]> (http://jillix.com)",
"license": "MIT",
"bugs": {
"url": "https://github.com/jillix/url.js/issues"
Expand All @@ -33,5 +34,52 @@
"ghosty": "^1.1.0",
"lien": "0.0.15",
"tester": "^1.3.0"
},
"blah": {
"title": "url.js",
"description": [
{
"h2": "Demo"
},
{
"p": "Browse the demos on http://jillix.github.io/url.js/"
},
{
"p": "[![](http://i.imgur.com/BYxaxU1.png)](http://jillix.github.io/url.js/)"
},
{
"h2": "CDN"
},
{
"p": "The library is available on [CDNJS](https://cdnjs.com/libraries/urljs) as well. To use it, just do:"
},
{
"code": {
"language": "html",
"content": "<script src=\"https://cdnjs.cloudflare.com/ajax/libs/urljs/1.2.0/url.min.js\"></script>"
}
},
{
"h2": "Usage"
},
{
"code": {
"language": "html",
"content": [
"<script src=\"path/to/url.js\"></script>",
"<!-- or use the cdn",
"<script src=\"https://cdnjs.cloudflare.com/ajax/libs/urljs/1.2.0/url.min.js\"></script>",
"-->",
"<script>",
" Url.updateSearchParam(\"answer\", 42);",
"</script>"
]
}
},
{
"h2": "CommonJS-compatible"
},
{ "p": "The library is CommonJS-compatible. You can `require(\"url.js\")` in your files." }
]
}
}

0 comments on commit f78cb4a

Please sign in to comment.