Package Exports
- @irmmr/hash.js
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 (@irmmr/hash.js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Hash.js
Please use only version 1.6 or higher.
Hash.js is a simple javascript library by pure js that manage the page location.hash. to change, add, set, check, get the hash value or query you can use this library. The page hash is a combination of 2 parts, "value" and "query". This value is set as follows: #value?query. This principle may be incorrect, but it is defined in this library!
Usage
As mentioned this library used for managing page location hash. What is the page's hash? Page's hash is a value that defined in url and starts with a "#". for example : https://site.com/#some-value.
This library can do these works for you:
change: Change the page's hash value or queryadd: Add some values or queries to page's hashevaluate- Evaluate and check hash values and queriesset- Set vlues and queries to page's hashupdate- Update hash values and queriesclear- Clear the page's hashremove- Remove some parts of page's hashmanage- Manage the changes of page's hash- ...
Structure
The functions of this library are summarized in 3 sections. The main part is called lib and is used as a constructor that you need create an object from it to use its features. The other section is info and just shows the library versions. The last section is event that only have two mods and have listeners duty: load and change
load: The page's load event listenerchange: The page's hashchange event listenerIn addition to this types, this library can be used from
window.location.HashModule.
// use Hash.js main library
const hsh = Hash();
// use Hash.js information
const inf = Hash().info();
// use Hash.js event
Hash().event(listener, function () {
// do somthing ...
});Examples
I will add some examples soon ...
These do not include all features.
// To use, you must use this way.
const hsh = Hash();// Simple example for set and get page's hash.
// set a simple value
hsh.set('hello'); // page's hash => #hello
// get location's hash
let ha = hsh.get(); // returns => 'hello// Simple example for set and get query
// #{value}?{query}
// set a query
hsh.setQuery({
a : 'b',
c : 'd',
e : null
}); // page's hash => #?a=b&c=d&e
// get query
let hq = hsh.getQuery(); // returns => Object { a: "b", c: "d", e: null }
let a = hsh.getQuery('a'); // returns => 'b'// Get the location's hash query and value
// set value and query
hsh.set('value?a=1&b=2&redirect=/'); // page's hash => #value?a=1&b=2&redirect=/
// set value and query
hsh.setValue('new-value'); // page's hash => #new-value?a=1&b=2&redirect=/
hsh.setQuery({
page: 1,
redirect: '/home'
}) // page's hash => #new-value?page=1&redirect=/home// Lock location's hash
// set a value before
hsh.set('hello'); // page's hash => #hello
// lock it
hsh.lock();
// set new value
hsh.set('goodbye'); // page's hash => #hello
hsh.set('anything'); // page's hash => #hello
hsh.clear(); // page's hash => #helloHow to use ?
To using Hash.js, you need add hash.js as a script to your html codes!
<script src="path/to/hash.js"></script>