A simple and flexible JavaScript library that manages "window.location.hash". With the ability to support queries. (#value?query)
This project is maintained by irmmr
These components are for managing queries as strings and do not process queries at all.
// Hash is => #Hello?repeat=10
// Returns => Object { repeat: 10 }
Hash.q.get();
// Returns => "repeat=10"
Hash.q.str.get();
Set query string.
string (string) Query value
returns HashCpQueryStr
// Hash is => #hey?name=jj
// After => #hey?name=f&age=90
Hash.q.str.set("name=f&age=90");
Get query as string.
returns string
// Hash is => #hey?name=jj&age=90
// Returns => "name=jj&age=90"
Hash.q.str.get();
Add string to query.
value (string) Amount to be added.
position (string) Define hole position.
returns HashCpQueryStr
value (string) Amount to be added.
options (object) Options to define position, index.
string) Define position.boolean) For use in position after and before.returns HashCpQueryStr
number): Set position in an index with number.string) Set position after a value or string.string) Set position before a value or string.// Hash is => #hey?wea=cloud
// After => #hey?simplewea=cloud
Hash.q.str.add("simple", "before");
// Hash is => #hey?wea=cloud
// After => #hey?wea=cloudsimple
Hash.q.str.add("simple", "after");
// Hash is => #hey?wea=cloud
// After => #hey?weasimple=cloud
Hash.q.str.add("simple", "after:wea");
// Hash is => #hey?wea=cloud
// After => #hey?wea=simplecloud
Hash.q.str.add("simple", "after:=");
// Hash is => #hey?wea=cloud
// After => #hey?wBigea=cloud
Hash.q.str.add("Big", "index:1");
// Hash is => #hey?wea=cloud&m=14
// After => #hey?wea=>cloud&m=>14
Hash.q.str.add(">", {
position: "after:=",
multiple: true,
});
Check hash value exists.
Looking for any query as string.
Check if hash query str contains anything.
data (string) Any word or string to check
Check if any hash exists (multiple).
data (array)<string> Words to check
returns boolean
// Hash is => #Hello?name=lola
// Returns => true
Hash.q.str.have();
// Hash is => #Hello
// Returns => false
Hash.q.str.have();
// Hash is => #Hello?name=lola
// Returns => true
Hash.q.str.have("me");
// Hash is => #Hello?name=lola
// Returns => false
Hash.q.str.have("s");
// Hash is => #Hello?name=lola
// Returns => true
Hash.q.str.have(["name", "lola", "a"]);
Check equality.
data (string) Anything to check
returns boolean
// Hash is => #pa?p=11&flame=783
// Returns => true
Hash.q.str.is("p=11&flame=783");
// Hash is => #pa?p=11&flame=783
// Returns => false
Hash.q.str.is("p=11&fl");
Remove parts of hash query as string.
values (string |
RegExp) Word/RegExp to remove |
values (array)<string |
RegExp> Words to remove |
returns HashCpQueryStr
// Hash is => #msg?name=hoe&date=802-5225
// After => #msg?name=hoe&5225
Hash.q.str.remove("date=802-");
// Hash is => #msg?name=hoe&date=802-5225
// After => #msg?na=hoe&date=-
Hash.q.str.remove(["me", /[\d+]/g]);
Replace hash query as string.
from (string |
RegExp) Find anything |
to (string) Replace to anything
returns HashCpQueryStr
// Hash is => #msg?name=hoe&age=10
// After => #msg?name=jay&age=10
Hash.q.str.replace("hoe", "jay");
// Hash is => #msg?name=hoe&age=10
// After => #msg?name=hoe+age=10
Hash.q.str.replace(/\&/g, "+");