Skip to content

Instantly share code, notes, and snippets.

@moltar
Created March 20, 2018 22:28
Show Gist options
  • Save moltar/1438292862de624b87e4ed8088f60fd6 to your computer and use it in GitHub Desktop.
Save moltar/1438292862de624b87e4ed8088f60fd6 to your computer and use it in GitHub Desktop.
duid conflict
const duid = require('short-duid')
const inst = duid.init({
shardId: 1,
salt: 'foo',
epochStart: 1517363935892
})
for (let i = 0; i < 100000; i += 1) {
const ids = inst.getDUIDInt(1)
const id = ids[0]
const hashed = inst.hashidEncode([id])
const back = inst.hashidDecode(hashed)[0]
if (id !== back) {
console.log(i, ids, id, hashed, back)
process.exit()
}
}
@phpb-com
Copy link

phpb-com commented Jun 19, 2022

Replying 4 years later :-( The init should be prepended with “new”. And it should be fixed now, I think

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment