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
All components related to hash value. These components only control the values and do not make any changes to the rest of the parts.
All components work like main components without making changes in
queries.
// Hash Value => #Hello?anyQuery
Hash.v.set("Hello");
// Hash Value => #Hello?anyQuery
Hash.value.set("Hello");
Set new hash value.
value (string) Value of hash
returns HashCpValue
// Hash is => #Hello-World?query=data
// After => #Hello?query=data
Hash.v.set("Hello");
// Hash is => NONE
// After => #Hello-Babe
Hash.v.set("Hello-Babe");
Get hash value.
returns string
// Hash is => #Hello-World
// Returns => "Hello-World"
Hash.v.get();
// Hash is => #Hello?page=1
// Returns => "Hello"
Hash.v.get();
Add string to value.
value (string) Amount to be added.
position (string) Define hole position.
returns HashCpValue
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 HashCpValue
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 => #Hello-World
// After => #simpleHello-World
Hash.v.add("simple", "before");
// Hash value is => #Hello-World?def=false
// After => #Hello-Worldsimple?def=false
Hash.v.add("simple", "after");
// Hash value is => #Hello-World?query
// After => #Hellosimple-World?query
Hash.v.add("simple", "after:Hello");
// Hash value is => #Hello-World
// After => #Hello-simpleWorld
Hash.v.add("simple", "after:-");
// Hash value is => #Hello-World?a=b&c=d
// After => #HBigello-World?a=b&c=d
Hash.v.add("Big", "index:1");
// Hash value is => #Hello-World
// After => #HelloBig-WoBigrld
Hash.v.add("Big", {
position: "after:o",
multiple: true,
});
Clear hash value.
returns HashCpValue
// Hash is => #Hello-World
// After => #
Hash.v.clear();
// Hash is => #Hello-World?a=hello&h=4902
// After => #?a=hello&h=4902
Hash.v.clear();
Check hash value exists.
Check if any hash value exists.
Check if hash value 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-World
// Returns => true
Hash.v.have();
// Hash is => #?page=2
// Returns => false
Hash.v.have();
// Hash is => #Hello-World?Paper
// Returns => true
Hash.v.have("World");
// Hash is => #Hello-World?Pro=none
// Returns => false
Hash.v.have("Pro");
// Hash is => #Hello-World
// Returns => true
Hash.v.have(["Hello", "o", "Wo"]);
Check hash value.
data (string) Any word or string to check
returns boolean
// Hash is => #Hello-World?no=163
// Returns => true
Hash.v.is("Hello-World");
// Hash is => #Hello-World
// Returns => false
Hash.is("World");
Remove parts of hash value.
values (string |
RegExp) Word/RegExp to remove |
values (array)<string |
RegExp> Words to remove |
returns HashCpValue
// Hash is => #Hello-World?p=2
// After => #-World?p=2
Hash.v.remove("Hello");
// Hash is => #Hello-World?t-code=12
// After => #World?t-code=12
Hash.v.remove(["Hello", /\-/g]);
Replace hash value.
from (string |
RegExp) Find anything |
to (string) Replace to anything
returns HashCpValue
// Hash is => #Hello-World?que=val
// After => #Hi-World?que=val
Hash.v.replace("Hello", "Hi");
// Hash is => #Hello-World?i
// After => #Hello+World?i
Hash.v.replace(/-/g, "+");