EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Software Development Software Development Tutorials TypeScript Tutorial TypeScript UUID
 

TypeScript UUID

Updated April 6, 2023

TypeScript UUID

 

 

Introduction to TypeScript UUID

A Universal Unique Identifier is called UUID in TypeScript. They are also known as Globally Unique Identifiers represented as GUID and is a Microsoft version of UUID. A UUID is 16 bytes value or 128 bits long used to guarantee uniqueness across time and space. A UUID is represented by hexadecimal value, which can be used to identify the rows uniquely in a database table by acting as a primary key, and UUID’s were originally used in Apollo Network Computing System, after which it was used in Distributed Computing Environment’s Open Software Foundation and later in the platform of Microsoft Windows.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Syntax to define UUID in TypeScript class:

function getuuid()
{
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, variable_name =>
(variable_name ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> variable_name / 4).toString(16)
);
}
  • Where ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g is equivalent to replacing the value 10000000-1000-4000-8000-100000000000 to hexadecimal characters,
  • crypto.getRandomValues is used to generate random numbers cryptographically which are stored in the array UintArray passed as parameter to the crypto.getRandomValues function.

Working of UUID in TypeScript

  • A universal unique identifier is a hexadecimal value created to uniquely identify the rows in a database table which acts as a primary key is called UUID in TypeScript.
  • The Microsoft version of UUID is called Globally Unique Identifier, represented as GUID.
  • A UUID is 16 bytes value or 128 buts long and guarantees uniqueness across space and time.
  • UUID’s were originally used in Apollo Network Computing System, after which it was used in Distributed Computing Environment’s Open Software Foundation and later in the platform of Microsoft Windows.

Examples of TypeScript UUID

Given below are the examples of TypeScript UUID:

Example #1

TypeScript program generates a Universally Unique Identifier or UUID by replacing the standard value with hexadecimal characters and generating random numbers cryptographically and displaying the generated UUID as the output of the screen.

Code:

function getuuid()
{
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, fun =>
(fun ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> fun / 4).toString(16)
);
}
console.log('The UUID generated using the standard function is', getuuid());

Output:

TypeScript UUID 1

In the above program, ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g is equivalent to replacing the value 10000000-1000-4000-8000-100000000000 to hexadecimal characters, crypto.getRandomValues is used to generate random numbers cryptographically which are stored in the array UintArray passed as parameter to the crypto.getRandomValues function and that is how the UUID is generated, which is displayed as the output on the screen.

Example #2

TypeScript program generates a Universally Unique Identifier or UUID by replacing the standard value with hexadecimal characters and generating random numbers cryptographically and displaying the generated UUID as the output of the screen.

Code:

function getuuid()
{
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, fun =>
(fun ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> fun / 4).toString(16)
);
}
console.log('The UUID generated using the standard function is', getuuid());

Output:

TypeScript UUID 2

In the above program, ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g is equivalent to replacing the value 10000000-1000-4000-8000-100000000000 to hexadecimal characters, crypto.getRandomValues is used to generate random numbers cryptographically which are stored in the array UintArray passed as parameter to the crypto.getRandomValues function and that is how the UUID is generated, which is displayed as the output on the screen.

Example #3

TypeScript program generates a Universally Unique Identifier or UUID by replacing the standard value with hexadecimal characters and generating random numbers cryptographically and displaying the generated UUID as the output of the screen.

Code:

function getuuid()
{
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, fun =>
(fun ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> fun / 4).toString(16)
);
}
console.log('The UUID generated using the standard function is', getuuid());

Output:

TypeScript UUID 3

In the above program, ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g is equivalent to replacing the value 10000000-1000-4000-8000-100000000000 to hexadecimal characters, crypto.getRandomValues is used to generate random numbers cryptographically which are stored in the array UintArray passed as parameter to the crypto.getRandomValues function and that is how the UUID is generated, which is displayed as the output on the screen.

Example #4

TypeScript program generates a Universally Unique Identifier or UUID by replacing the standard value with hexadecimal characters and generating random numbers cryptographically and displaying the generated UUID as the output of the screen.

Code:

function getuuid()
{
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, fun =>
(fun ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> fun / 4).toString(16)
);
}
console.log('The UUID generated using the standard function is', getuuid());

Output:

cryptographically

In the above program, ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g is equivalent to replacing the value 10000000-1000-4000-8000-100000000000 to hexadecimal characters, crypto.getRandomValues is used to generate random numbers cryptographically which are stored in the array UintArray passed as parameter to the crypto.getRandomValues function and that is how the UUID is generated, which is displayed as the output on the screen.

Example #5

TypeScript program generates a Universally Unique Identifier or UUID by replacing the standard value with hexadecimal characters and generating random numbers cryptographically and displaying the generated UUID as the output of the screen.

Code:

function getuuid()
{
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, fun =>
(fun ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> fun / 4).toString(16)
);
}
console.log('The UUID generated using the standard function is', getuuid());

Output:

replacing the standard value with hexadecimal characters

In the above program, ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g is equivalent to replacing the value 10000000-1000-4000-8000-100000000000 to hexadecimal characters, crypto.getRandomValues is used to generate random numbers cryptographically which are stored in the array UintArray passed as parameter to the crypto.getRandomValues function and that is how the UUID is generated, which is displayed as the output on the screen.

Rules and Regulations for Generating UUID

  • A UUID must be 16 bytes long or 128 bits value.
  • A UUID must be a unique value uniquely identifying the rows in a database table.
  • A UUID must be made the primary key to identify the rows in the database table uniquely.
  • A UUID can be generated only after it is converted to 16 bytes long hexadecimal value.
  • The scope of UUID is universal, and the generated UUID is 16 bytes long, separated by a hypen to 5 different groups.

Recommended Articles

We hope that this EDUCBA information on “TypeScript UUID” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

  1. TypeScript Dictionary
  2. TypeScript Generic
  3. TypeScript Types
  4. What is TypeScript?

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - ENROLL NOW