Skip to content

Instantly share code, notes, and snippets.

@jeonghwan-kim
Last active May 18, 2022 00:33
Show Gist options
  • Save jeonghwan-kim/6e9b57674e00efbe2fa645486b4bb7c8 to your computer and use it in GitHub Desktop.
Save jeonghwan-kim/6e9b57674e00efbe2fa645486b4bb7c8 to your computer and use it in GitHub Desktop.
Generate hash-like id
const createId = (text = Date.now().toString().substring(0, 10)) => {
const m = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]; // 0 ~ 9
let hash = "";
for (let i = 0; i < text.length; i++) {
if (i > 6) {
hash += text[i];
} else {
hash += m[Number(text[i])];
}
}
return hash.toUpperCase();
};
createId() // example: BGFCIDD703
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment