Skip to content

donvercety/js-uid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 

Repository files navigation

js-uid

Simple & safe unique id generator.

NodeJS compatable but not published, get the code directly :)

const uid = require('./uid');

uid(); // 16290fd3be3

Browser

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script src="uid.js"></script>
    <script>
        uid(); // 16290fd3be3
    </script>

</body>
</html>

..or if you are modern :)

export const uid = (prev => {
    return () => {
        let date = Date.now();

        if (date <= prev) {
                date = ++prev;
        } else {
                prev = date;
        }

        return date.toString(36);
    }
})(0);

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published