GithubHelp home page GithubHelp logo

piraces / guid-ts Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 602 KB

Package for generating and managing globally unique identifiers (GUIDs) v4

Home Page: https://www.npmjs.com/package/guid-ts

License: MIT License

TypeScript 100.00%
npm typescript package guid uuid uuid-generator guid-generator

guid-ts's Introduction

guid-ts

Build and Test Typescript CI Quality Gate Status npm bundle size

Package for generating and managing globally unique identifiers (GUIDs) v4 in Typescript.

Lightweight, simple, dependency free, and reliable package.

This package provides a class which can parse and generate a GUID based on the RFC4122. The package also expose methods to manage GUIDs.

The focus of this package is to provide a simple mechanism to generate and manage v4 UUIDs, following this principles:

  • Keep It Simple Stupid (KISS Principle)
  • Keep it lightweight
  • Dependency free
  • Well tested
  • Reliable
  • RFC compilant (RFC4122)
  • Compatible with all major browsers
  • Up-to-date

Installation

Simply install it with your favourite package manager:

Yarn

yarn add guid-ts

NPM

npm install guid-ts

Usage

import { Guid } from 'guid-ts';

const newGuid = Guid.newGuid(); // => ex: b631e90e-6e7f-488e-88fb-a7c2ef44bb8d

You can use and test the package online on Stackblitz, checkout our example playground: guid-ts-playground.

Documentation

You can find all the code documentation in https://piraces.github.io/guid-ts/index.html. The documentation is generated using TypeDoc, and resides in the docs folder.

How does it works?

The implementation is very simple. It basically generates random numbers to compose a valid v4 UUID, following the specification and a regex to check it.

How do it generates random numbers?

In order to support all browsers as possible, the implementation checks if the browser has implemented the Crypto API (or mscrypto in the case of IE11), in order to generate the random values, since it is a more reliable source for random values. If the crypto object its not available in runtime, then Math.random() is used as a fallback (which is a less reliable source of random values, but available in almost all browsers).

Browsers support

IE / Edge
IE / Edge
Firefox
Firefox
Chrome
Chrome
Safari
Safari
iOS Safari
iOS Safari
Samsung
Samsung
Opera
Opera
IE6-IE11, Edge 2-latest 4-latest 3.1-latest 3.2-latest 4-latest 10-latest

guid-ts's People

Contributors

dependabot[bot] avatar piraces avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.