https://github.com/piraces/guid-ts
Package for generating and managing globally unique identifiers (GUIDs) v4
https://github.com/piraces/guid-ts
guid guid-generator npm package typescript uuid uuid-generator
Last synced: 11 months ago
JSON representation
Package for generating and managing globally unique identifiers (GUIDs) v4
- Host: GitHub
- URL: https://github.com/piraces/guid-ts
- Owner: piraces
- License: mit
- Created: 2020-04-22T17:05:43.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-03-04T14:33:30.000Z (almost 3 years ago)
- Last Synced: 2025-01-31T22:17:18.816Z (12 months ago)
- Topics: guid, guid-generator, npm, package, typescript, uuid, uuid-generator
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/guid-ts
- Size: 588 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# guid-ts
 [](https://sonarcloud.io/dashboard?id=piraces_guid-ts) 
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](https://www.ietf.org/rfc/rfc4122.txt).
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)](https://en.wikipedia.org/wiki/KISS_principle)
- Keep it lightweight
- Dependency free
- Well tested
- Reliable
- RFC compilant ([RFC4122](https://www.ietf.org/rfc/rfc4122.txt))
- Compatible with all major browsers
- Up-to-date
## Installation
Simply install it with your favourite package manager:
### Yarn
```shell
yarn add guid-ts
```
### NPM
```shell
npm install guid-ts
```
## Usage
```typescript
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](https://stackblitz.com/edit/guid-ts-playground).
## Documentation
You can find all the code documentation in [https://piraces.github.io/guid-ts/index.html](https://piraces.github.io/guid-ts/index.html).
The documentation is generated using [TypeDoc](https://typedoc.org/), 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](https://caniuse.com/#feat=mdn-api_crypto_getrandomvalues) (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()](https://caniuse.com/#feat=mdn-javascript_builtins_math_random) is used as a fallback (which is a less reliable source of random values, but available in almost all browsers).
## Browsers support
| [
](http://godban.github.io/browsers-support-badges/)
IE / Edge | [
](http://godban.github.io/browsers-support-badges/)
Firefox | [
](http://godban.github.io/browsers-support-badges/)
Chrome | [
](http://godban.github.io/browsers-support-badges/)
Safari | [
](http://godban.github.io/browsers-support-badges/)
iOS Safari | [
](http://godban.github.io/browsers-support-badges/)
Samsung | [
](http://godban.github.io/browsers-support-badges/)
Opera |
| --------- | --------- | --------- | --------- | --------- | --------- | --------- |
| IE6-IE11, Edge | 2-latest | 4-latest | 3.1-latest | 3.2-latest | 4-latest | 10-latest