Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/hashids@2/dist/hashids.min.js"></script>
</body>
</html>
 
(() => {
const hashids = new Hashids(
  /* salt: string */ 
  undefined,
  /* minLength: number */ 
  undefined,
  /* alphabet: string */ 
  undefined,
  /* these chars can't be next to one another: string */ 
  undefined,
);
const hashidsWithSalt = new Hashids('BlPfqsuFlw3PDS6F');
  
for (let i = 0; i < 5; i++) {
  const encoded = hashids.encode(1, 2, 3 + i);
  const decoded = hashids.decode(encoded);
  console.log(decoded, encoded);
  const encodedWithSalt = hashidsWithSalt.encode(1, 2, 3 + i);
  const decodedWithSalt = hashidsWithSalt.decode(encodedWithSalt);
  console.log(decodedWithSalt, encodedWithSalt);
}
// Try to decode hashid generated from different salt but get nothing
console.log(hashids.decode('o2fXhV'));
console.log(hashidsWithSalt.decode('o2fXhV'));
})()
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers