A library of useful functions to ease working with URL query parameters.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
dist
src
.gitignore
LICENSE
README.md
gulpfile.js
index.html
node_modules
package.json

README.md

urls.js: URL Library

A library of useful functions to ease working with URL query parameters.

Try the tests.

How to include the script

This include can be added to the header or placed inline before the script is invoked.

<script src="./js/urls.js"></script>

How to control the script

load

data = urls.load(url);

Converts the query parameters from a URL into an object of name-value pairs.

data : {object} - An object filled with name-value pairs. e.g. {foo:bar}

url : {string} - An URL with query parameters. e.g. http://domain.com/?foo=bar

save

url = urls.save(path, data);

Saves an object of name-value pairs as the query parameters of a URL.

url : {string} - An URL with query parameters. e.g. http://domain.com/?foo=bar

path : {string} - An URL without query parameters. e.g. http://domain.com/

data : {object} - An object filled with name-value pairs. e.g. {foo:bar}

replace

url = urls.replace(url, name, value);

Replaces the value of a query parameter in a URL.

url : {string} - An URL with query parameters. e.g. http://domain.com/?foo=bar

name : {string} - Name of a parameter stored as a query parameter.

value : {string} - Value to be stored as a query parameter.

How to build the script

This project uses node.js from http://nodejs.org/

This project uses gulp.js from http://gulpjs.com/

The following commands are available for development:

  • npm install - Installs the prerequisites.
  • gulp import - Re-imports libraries from supporting projects to ./src/libs/ if available under the same folder tree.
  • gulp dev - Builds the project for development purposes.
  • gulp dist - Builds the project for deployment purposes.
  • gulp watch - Continuously recompiles updated files during development sessions.
  • gulp serve - Serves the project on a temporary web server at http://localhost:8500/.
  • gulp php - Serves the project on a temporary php server at http://localhost:8500/.

License

This work is licensed under a Creative Commons Attribution 3.0 Unported License. The latest version of this and other scripts by the same author can be found at http://www.woollymittens.nl/