uuid-version4
v0.1.2
Published
Library for generating UUID (universally unique identifier) version 4 strings
Downloads
16
Readme
UUIDv4
Library for generating UUID (universally unique identifier) version 4 strings.
The library will use window.crypto to generate random numbers if it detects that it is available, else it will fallback to use Math.random.
Usage
let uuid: string = UUIDv4.generateUUID();
Sample Angular Karma test
import { TestBed, inject } from '@angular/core/testing';
import { UUIDv4 } from 'uuid-version4';
describe('sample test', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: []
});
});
it('it should generate UUID version 4 string', inject([], () => {
let uuid: string = UUIDv4.generateUUID();
expect(uuid).toBeTruthy();
expect(uuid.length).toBe(36);
expect(uuid[14]).toBe('4');
}));
});
Main source
The main source file is index.ts.
References
- Wikipedia: Universally unique identifier
- Specification: RFC 4122