Creating Unique Ids in Deno

deno
Published on April 8, 2021

In Deno MD5 unique ids can be created using the uuid library. This is a standard library which is reviewed by the Deno team.

Deno supports version 1, 4 & 5 for creating unique ids.

Version 1 Unique ID

A version 1 unique id is time based. It is generated through a combination of network card MAC address and timestamp.

import { v1 } from "https://deno.land/std@0.91.0/uuid/mod.ts";

// v1 unique id
let uniqid = v1.generate();

Version 4 Unique ID

A version 4 unique id is randomly generated. These are truly random strings, and probably this can be used for most use-cases.

import { v4 } from "https://deno.land/std@0.91.0/uuid/mod.ts";

// v4 unique id
let uniqid = v4.generate();

Version 5 Unique ID

A version 5 unique id is generated by SHA-1 hashing a namespace and a value.

import { v5 } from "https://deno.land/std@0.91.0/uuid/mod.ts";

// v5 unique id
// namespace & value parameters need to be passed
let uniqid = v5.generate({ namespace: '06ad671e-8f31-11eb-a13c-87fe3344692e', value: 'testkey '});

Namespace must be a valid unique id in the format 00000000-0000-0000-0000-000000000000. Value can be anything.

The same namespace with the same value will always create the same unique id.

In this Tutorial
    Comments
    Loading Comments