EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials TypeScript Tutorial TypeScript UUID
Secondary Sidebar
TypeScript Tutorial
  • TypeScript Basic and Advanced
    • What is TypeScript?
    • Typescript Examples
    • TypeScript Versions
    • TypeScript Operators
    • JavaScript dump object
    • JavaScript get Method
    • Webpack ReactJS
    • Code Generator JavaScript
    • JavaScript Projects
    • Call Stack JavaScript
    • JavaScript Projects GitHub
    • JavaScript Filter Function
    • JavaScript nan
    • JavaScripttimestamp
    • TypeScript loop
    • CoffeeScript
    • TypeScript Webpack
    • setTimeout TypeScript
    • DHTMLX
    • CoffeeScript for loop
    • TypeScript number
    • JavaScript export module
    • TypeScript string contains
    • TypeScript Inheritance
    • TypeScript get
    • TypeScript undefined
    • TypeScript Global Variable
    • TypeScript Dictionary
    • TypeScript Generic
    • TypeScript Cast Object
    • TypeScript Optional Parameters
    • TypeScript? switch
    • TypeScript promise
    • TypeScript tuple
    • TypeScript Hashmap
    • TypeScript let
    • TypeScript Getter
    • TypeScript Pattern Matching
    • TypeScript number to string
    • TypeScript substring
    • TypeScript?lambda
    • TypeScript UUID
    • TypeScript JSDoc
    • TypeScript Decorators
    • Typescript for loop
    • TypeScript HTTP Request
    • TypeScript Abstract Class
    • TypeScript Question Mark
    • TypeScript Nullable
    • TypeScript reduce
    • TypeScript Mixins
    • TypeScript keyof
    • TypeScript string to number
    • TypeScript JSON parse
    • TypeScript const
    • TypeScript declare module
    • TypeScript String
    • TypeScript filter
    • TypeScript Multiple Constructors
    • TypeScript? Set
    • TypeScript string interpolation
    • TypeScript instanceof
    • TypeScript JSON
    • TypeScript Arrow Function
    • TypeScript generator
    • TypeScript namespace
    • TypeScript default parameter
    • TypeScript cast
    • TypeScript babel
    • Typescript Key-Value Pair
    • TypeScript if
    • TypeScript keyof Enum
    • TypeScript wait
    • TypeScript Optional Chaining
    • TypeScript JSX
    • TypeScript Version Check
    • TypeScript Unit Testing
    • TypeScript Handbook
    • TypeScript module
    • TypeScript Extend Interface
    • TypeScript npm
    • TypeScript pick
    • TypeScript Interface Default Value
    • JavaScript import module
    • Obfuscate Javascript
    • TypeScript basics
    • setInterval TypeScript
  • Type of Union
    • TypeScript Object Type
    • TypeScript type check
    • TypeScript promise type
    • TypeScript JSON type
    • TypeScript Union Types
    • TypeScript typeof
    • TypeScript Types
  • TypeScript Array
    • TypeScript Array of Objects
    • Methods TypeScript Array
    • TypeScript remove item from array
    • TypeScript add to array
    • TypeScript Array Contains
  • Function Of Array
    • TypeScript Function Interface
    • TypeScript Functions
    • TypeScript Export Function
    • TypeScript function return type

TypeScript UUID

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.

Syntax to define UUID in TypeScript class:

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

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
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

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

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

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*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?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more