Created
October 22, 2022 23:43
-
-
Save nick1n/611a2220c9038b688d5b0eabf8dc1a46 to your computer and use it in GitHub Desktop.
Tiny cuid, not secure, fast, less than 170 bytes, uses a random session id instead of fingerprint.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let | |
text, | |
base36 = (number) => number.toString(36), | |
randomStr = (length) => { | |
for ( | |
text = ""; | |
text.length < length; | |
text = base36(Math.random()).slice(2, length + 2) | |
); | |
return text | |
}, | |
session = randomStr(4), | |
count = 0, | |
cuid = () => | |
"c" + | |
base36(Date.now()) + | |
("000" + base36(count++)).slice(-4) + | |
session + | |
randomStr(8) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let t,b=(n)=>n.toString(36),r=(l)=>{for(t="";t.length<l;t=b(Math.random()).slice(2,l+2));return t},s=r(4),c=0,cuid=()=>"c"+b(Date.now())+("000"+b(c++)).slice(-4)+s+r(8) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment