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 management as string.
Set new hash as string.
value (string
) Value of hash
returns Hash
// Hash is => #Hello-World
// After => #Hello
Hash.set("Hello");
// Hash is => NONE
// After => #Hello-Babe?type=1
Hash.set("Hello-Babe?type=1");
Get all hash as string.
returns string
// Hash is => #Hello-World
// Returns => "Hello-World"
Hash.get();
Add value to hash.
value (string
) Amount to be added.
position (string
) Define hole position.
returns Hash
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 Hash
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 value is => #Hello-World
// After => #simpleHello-World
Hash.add("simple", "before");
// Hash value is => #Hello-World
// After => #Hello-Worldsimple
Hash.add("simple", "after");
// Hash value is => #Hello-World
// After => #Hellosimple-World
Hash.add("simple", "after:Hello");
// Hash value is => #Hello-World
// After => #Hello-simpleWorld
Hash.add("simple", "after:-");
// Hash value is => #Hello-World
// After => #HBigello-World
Hash.add("Big", "index:1");
// Hash value is => #Hello-World
// After => #HelloBig-WoBigrld
Hash.add("Big", {
position: "after:o",
multiple: true,
});
Clear all hash.
push_state (boolean
) [default: true] Remove # using push state?
returns Hash
// Hash is => #Hello-World
// After => NONE
Hash.clear();
// Hash is => #Hello-World
// After => #
Hash.clear(false);
Check hash exists.
Check if any hash exists.
Check if any hash exists.
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.have();
// Hash is => #Hello-World
// Returns => true
Hash.have("World");
// Hash is => #Hello-World
// Returns => false
Hash.have("Pro");
// Hash is => #Hello-World
// Returns => true
Hash.have(["Hello", "o", "Wo"]);
Check hash value.
data (string
) Any word or string to check
returns boolean
// Hash is => #Hello-World
// Returns => true
Hash.is("Hello-World");
// Hash is => #Hello-World
// Returns => false
Hash.is("World");
Lock hash value.
options (object
) All lock options
boolean
) don’t let it unlockedreturns Hash
// Hash is => #Hello-World
Hash.lock();
// Hash is => #Hello-World
// Can't be changed or unlocked
Hash.lock({
force: true,
});
Check if hash is locked.
returns boolean
// Hash is => #Hello-World
Hash.lock();
// Returns => true
Hash.isLocked();
Unlock hash if not locked with force.
returns Hash
// unlock it
Hash.unlock();
Remove parts of hash as string.
values (string |
RegExp ) Word/RegExp to remove |
values (array )<string |
RegExp > Words to remove |
returns Hash
// Hash is => #Hello-World
// After => #-World
Hash.remove("Hello");
// Hash is => #Hello-World
// After => #World
Hash.remove(["Hello", /\-/g]);
Replace hash as string.
from (string |
RegExp ) Find anything |
to (string
) Replace to anything
returns Hash
// Hash is => #Hello-World
// After => #Hi-World
Hash.replace("Hello", "Hi");
// Hash is => #Hello-World
// After => #Hello+World
Hash.replace(/-/g, "+");