Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

uuidjs

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uuidjs - npm Package Compare versions

Comparing version 5.0.1 to 5.1.0

8

CHANGELOG.md
# Changelog
## v5.1.0 - 2024-05-12
- Marked `UUID.genV6()` as stable
- Updated documents with RFC 9562 verbiage
- Updated dev dependencies
## v5.0.1 - 2023-03-30

@@ -84,3 +90,3 @@

## v4.2.13 - 2023-01-09
## v4.2.14

@@ -87,0 +93,0 @@ Last version that:

40

dist/uuid.d.ts

@@ -5,4 +5,4 @@ /**

* @author LiosK
* @version v5.0.1
* @license Apache License 2.0: Copyright (c) 2010-2023 LiosK
* @version v5.1.0
* @license Apache License 2.0: Copyright (c) 2010-2024 LiosK
* @packageDocumentation

@@ -15,3 +15,3 @@ */

/**
* Generates a version 4 UUID as a hexadecimal string.
* Generates a UUIDv4 as a hexadecimal string.
* @returns The hexadecimal UUID string.

@@ -39,2 +39,5 @@ */

* The names of UUID internal fields.
*
* Note that these internal fields from the obsolete RFC 4122 are no longer
* used in the current RFC 9562.
* @since 3.0

@@ -45,2 +48,5 @@ */

* The sizes of UUID internal fields.
*
* Note that these internal fields from the obsolete RFC 4122 are no longer
* used in the current RFC 9562.
* @since 3.0

@@ -50,4 +56,4 @@ */

/**
* Creates a version 4 UUID object.
* @returns A version 4 UUID object.
* Creates a UUIDv4 object.
* @returns A UUIDv4 object.
* @since 3.0

@@ -65,2 +71,5 @@ */

* The UUID internal field values as an array of integers.
*
* Note that these internal fields from the obsolete RFC 4122 are no longer
* used in the current RFC 9562.
*/

@@ -77,2 +86,5 @@ readonly intFields: readonly number[] & {

* The UUID internal field values as an array of binary strings.
*
* Note that these internal fields from the obsolete RFC 4122 are no longer
* used in the current RFC 9562.
*/

@@ -89,2 +101,5 @@ readonly bitFields: readonly string[] & {

* The UUID internal field values as an array of hexadecimal strings.
*
* Note that these internal fields from the obsolete RFC 4122 are no longer
* used in the current RFC 9562.
*/

@@ -150,4 +165,4 @@ readonly hexFields: readonly string[] & {

/**
* Creates a version 1 UUID object.
* @returns A version 1 UUID object.
* Creates a UUIDv1 object.
* @returns A UUIDv1 object.
* @since 3.0

@@ -157,3 +172,3 @@ */

/**
* Re-initializes the internal state for version 1 UUID creation.
* Re-initializes the internal state for UUIDv1 and UUIDv6 creation.
* @since 3.0

@@ -163,3 +178,3 @@ */

/**
* The persistent internal state for version 1 UUID creation.
* The persistent internal state for UUIDv1 and UUIDv6 creation.
*/

@@ -172,10 +187,7 @@ private static _state;

/**
* Creates a version 6 UUID object. This function is experimentally provided
* based on the draft RFC and may be changed or removed in the future without
* conforming to semantic versioning requirements.
* @returns A version 6 UUID object.
* Creates a UUIDv6 object.
* @returns A UUIDv6 object.
* @since v4.2.13
* @experimental
*/
static genV6(): UUID;
}

@@ -5,4 +5,4 @@ /**

* @author LiosK
* @version v5.0.1
* @license Apache License 2.0: Copyright (c) 2010-2023 LiosK
* @version v5.1.0
* @license Apache License 2.0: Copyright (c) 2010-2024 LiosK
* @packageDocumentation

@@ -14,10 +14,10 @@ */

*/
class UUID {
export class UUID {
// Core Component {{{
/**
* Generates a version 4 UUID as a hexadecimal string.
* Generates a UUIDv4 as a hexadecimal string.
* @returns The hexadecimal UUID string.
*/
static generate() {
var rand = UUID._getRandomInt, hex = UUID._hexAligner;
var rand = _a._getRandomInt, hex = _a._hexAligner;
return (hex(rand(32), 8) + // time_low

@@ -66,12 +66,12 @@ "-" +

static useMathRandom() {
UUID._getRandomInt = UUID._mathPRNG;
_a._getRandomInt = _a._mathPRNG;
}
/**
* Creates a version 4 UUID object.
* @returns A version 4 UUID object.
* Creates a UUIDv4 object.
* @returns A UUIDv4 object.
* @since 3.0
*/
static genV4() {
var rand = UUID._getRandomInt;
return new UUID(rand(32), // time_low
var rand = _a._getRandomInt;
return new _a(rand(32), // time_low
rand(16), // time_mid

@@ -81,4 +81,3 @@ 0x4000 | rand(12), // time_hi_and_version

rand(8), // clock_seq_low
rand(48) // node
);
rand(48));
}

@@ -98,3 +97,3 @@ /**

(l.toLowerCase() === "urn:uuid:" && t === "")) {
return new UUID(parseInt(r[2], 16), parseInt(r[3], 16), parseInt(r[4], 16), parseInt(r[5], 16), parseInt(r[6], 16), parseInt(r[7], 16));
return new _a(parseInt(r[2], 16), parseInt(r[3], 16), parseInt(r[4], 16), parseInt(r[5], 16), parseInt(r[6], 16), parseInt(r[7], 16));
}

@@ -114,4 +113,4 @@ }

constructor(_timeLow, _timeMid, _timeHiAndVersion, _clockSeqHiAndReserved, _clockSeqLow, _node) {
var names = UUID.FIELD_NAMES, sizes = UUID.FIELD_SIZES;
var bin = UUID._binAligner, hex = UUID._hexAligner;
var names = _a.FIELD_NAMES, sizes = _a.FIELD_SIZES;
var bin = _a._binAligner, hex = _a._hexAligner;
// @ts-ignore

@@ -172,3 +171,3 @@ this.intFields = new Array(6);

equals(uuid) {
if (!(uuid instanceof UUID)) {
if (!(uuid instanceof _a)) {
return false;

@@ -184,13 +183,13 @@ }

// }}}
// UUID Version 1 Component (1 of 2) {{{
// UUIDv1 Component (1 of 2) {{{
/**
* Creates a version 1 UUID object.
* @returns A version 1 UUID object.
* Creates a UUIDv1 object.
* @returns A UUIDv1 object.
* @since 3.0
*/
static genV1() {
if (UUID._state == null) {
UUID._state = new UUIDState();
if (_a._state == null) {
_a._state = new UUIDState();
}
var now = new Date().getTime(), st = UUID._state;
var now = new Date().getTime(), st = _a._state;
if (now != st.timestamp) {

@@ -201,7 +200,7 @@ if (now < st.timestamp) {

st.timestamp = now;
st.tick = UUID._getRandomInt(12); // up to 4095, allowing 5904 tick per msec
st.tick = _a._getRandomInt(12); // up to 4095, allowing 5904 tick per msec
}
else if (st.tick < 9992) {
// advance sub-millisecond fraction up to 9999 100-nanoseconds
st.tick += 1 + UUID._getRandomInt(3);
st.tick += 1 + _a._getRandomInt(3);
}

@@ -213,3 +212,3 @@ else {

// format time fields
var tf = UUID._getTimeFieldValues(st.timestamp);
var tf = _a._getTimeFieldValues(st.timestamp);
var tl = tf.low + st.tick;

@@ -221,10 +220,10 @@ var thav = (tf.hi & 0xfff) | 0x1000; // set version '0001'

var csl = st.sequence & 0xff;
return new UUID(tl, tf.mid, thav, cshar, csl, st.node);
return new _a(tl, tf.mid, thav, cshar, csl, st.node);
}
/**
* Re-initializes the internal state for version 1 UUID creation.
* Re-initializes the internal state for UUIDv1 and UUIDv6 creation.
* @since 3.0
*/
static resetState() {
UUID._state = new UUIDState();
_a._state = new UUIDState();
}

@@ -245,16 +244,13 @@ /**

// }}}
// UUID Version 6 Component {{{
// UUIDv6 Component {{{
/**
* Creates a version 6 UUID object. This function is experimentally provided
* based on the draft RFC and may be changed or removed in the future without
* conforming to semantic versioning requirements.
* @returns A version 6 UUID object.
* Creates a UUIDv6 object.
* @returns A UUIDv6 object.
* @since v4.2.13
* @experimental
*/
static genV6() {
if (UUID._state == null) {
UUID._state = new UUIDState();
if (_a._state == null) {
_a._state = new UUIDState();
}
var now = new Date().getTime(), st = UUID._state;
var now = new Date().getTime(), st = _a._state;
if (now != st.timestamp) {

@@ -265,7 +261,7 @@ if (now < st.timestamp) {

st.timestamp = now;
st.tick = UUID._getRandomInt(12); // up to 4095, allowing 5904 tick per msec
st.tick = _a._getRandomInt(12); // up to 4095, allowing 5904 tick per msec
}
else if (st.tick < 9992) {
// advance sub-millisecond fraction up to 9999 100-nanoseconds
st.tick += 1 + UUID._getRandomInt(3);
st.tick += 1 + _a._getRandomInt(3);
}

@@ -286,3 +282,3 @@ else {

var csl = st.sequence & 0xff;
return new UUID(th, tm, tlav, cshar, csl, st.node);
return new _a(th, tm, tlav, cshar, csl, st.node);
}

@@ -293,3 +289,3 @@ }

// Advanced Random Number Generator Component {{{
UUID._mathPRNG = UUID._getRandomInt;
UUID._mathPRNG = _a._getRandomInt;
(() => {

@@ -314,2 +310,5 @@ if (typeof crypto !== "undefined" && crypto.getRandomValues) {

* The names of UUID internal fields.
*
* Note that these internal fields from the obsolete RFC 4122 are no longer
* used in the current RFC 9562.
* @since 3.0

@@ -327,2 +326,5 @@ */

* The sizes of UUID internal fields.
*
* Note that these internal fields from the obsolete RFC 4122 are no longer
* used in the current RFC 9562.
* @since 3.0

@@ -335,9 +337,8 @@ */

*/
UUID.NIL = new UUID(0, 0, 0, 0, 0, 0);
UUID.NIL = new _a(0, 0, 0, 0, 0, 0);
/**
* The persistent internal state for version 1 UUID creation.
* The persistent internal state for UUIDv1 and UUIDv6 creation.
*/
UUID._state = null;
export { UUID };
// UUID Version 1 Component (2 of 2) {{{
// UUIDv1 Component (2 of 2) {{{
class UUIDState {

@@ -344,0 +345,0 @@ constructor() {

@@ -7,11 +7,7 @@ import { UUID } from "uuidjs";

// Create UUID objects and get string representations
console.log(UUID.genV4().toString());
console.log(UUID.genV1().hexNoDelim);
console.log(UUID.genV1().toString());
console.log(UUID.genV6().hexString);
console.log(UUID.genV4().hexNoDelim);
console.log(UUID.parse("84d9ca79-4d66-4373-91a0-a12d673e71be").urn);
// Get UUID internal field values
console.log(UUID.genV4().hexFields.node);
console.log(UUID.genV1().intFields.timeLow);
console.log(UUID.genV4().bitFields[2]);
UUID.genV1();
UUID.genV6();
{
"name": "uuidjs",
"version": "5.0.1",
"version": "5.1.0",
"title": "UUID.js",

@@ -34,4 +34,4 @@ "description": "RFC-compliant UUID Generator for JavaScript",

"guid",
"rfc",
"4122",
"rfc9562",
"rfc4122",
"universally",

@@ -49,6 +49,6 @@ "globally",

"devDependencies": {
"qunit": "^2.19.4",
"typedoc": "^0.23.28",
"typescript": "^5.0.2"
"qunit": "^2.20.1",
"typedoc": "^0.25.13",
"typescript": "^5.4.5"
}
}

@@ -36,12 +36,12 @@ # UUID.js - RFC-compliant UUID Generator for JavaScript

UUID.js is a JavaScript/ECMAScript library to generate RFC 4122 compliant
Universally Unique IDentifiers (UUIDs). This library supports both version 4
UUIDs (UUIDs from random numbers) and version 1 UUIDs (time-based UUIDs), and
provides an object-oriented interface to print a generated or parsed UUID in a
variety of forms.
UUID.js is a JavaScript/ECMAScript library to generate RFC 9562 compliant
Universally Unique IDentifiers (UUIDs). This library supports UUIDv4 (random
number-based UUIDs), UUIDv1 (Gregorian time-based UUIDs), and UUIDv6 (Reordered
Gregorian time-based UUIDs). It also provides an object-oriented interface to
print a generated or parsed UUID in a variety of forms.
## Features
- Generates version 4 UUIDs (UUIDs from random numbers) and version 1 UUIDs
(time-based UUIDs)
- Generates UUIDv4 (random number-based UUIDs), UUIDv1 (Gregorian time-based
UUIDs), and UUIDv6 (Reordered Gregorian time-based UUIDs)
- Provides an object-oriented interface to print various string representations

@@ -52,3 +52,3 @@ of a generated or parsed UUID

- Appends extra random bits to compensate for the lower timestamp resolution of
JavaScript than that required for version 1 UUIDs
JavaScript than that required for UUIDv1 and UUIDv6
- Comes with a lot of test cases including format checks and statistical tests

@@ -67,19 +67,22 @@ to maintain a high-quality code base

`UUID.generate()` returns a version 4 UUID as a hexadecimal string.
`UUID.generate()` returns a UUIDv4 as a hexadecimal string.
```javascript
// Create a version 4 UUID as a hexadecimal string
// Create a UUIDv4 as a hexadecimal string
console.log(UUID.generate()); // fa84cf42-ffdf-4975-b42b-31ab5fb983eb
```
`UUID.genV4()`, `UUID.genV1()`, and `UUID.parse()` return a UUID object that has
various fields and methods.
`UUID.genV4()`, `UUID.genV1()`, `UUID.genV6()`, and `UUID.parse()` return a UUID
object that has various fields and methods.
```javascript
// Create a version 4 (random number-based) UUID object
// Create a UUIDv4 (random number-based UUID) object
const objV4 = UUID.genV4();
// Create a version 1 (time-based) UUID object
// Create a UUIDv1 (Gregorian time-based UUID) object
const objV1 = UUID.genV1();
// Create a UUIDv6 (Reordered Gregorian time-based UUID) object
const objV6 = UUID.genV6();
// Create a UUID object from a hexadecimal string

@@ -101,17 +104,3 @@ const uuid = UUID.parse("a0e0f130-8c21-11df-92d9-95795a3bcd40");

console.log(objV1.version); // 1
// Get internal field values in 3 different forms via 2 different accessors
console.log(uuid.intFields.timeLow); // 2699096368
console.log(uuid.bitFields.timeMid); // "1000110000100001"
console.log(uuid.hexFields.timeHiAndVersion); // "11df"
console.log(uuid.intFields.clockSeqHiAndReserved); // 146
console.log(uuid.bitFields.clockSeqLow); // "11011001"
console.log(uuid.hexFields.node); // "95795a3bcd40"
console.log(uuid.intFields[0]); // 2699096368
console.log(uuid.bitFields[1]); // "1000110000100001"
console.log(uuid.hexFields[2]); // "11df"
console.log(uuid.intFields[3]); // 146
console.log(uuid.bitFields[4]); // "11011001"
console.log(uuid.hexFields[5]); // "95795a3bcd40"
console.log(objV6.version); // 6
```

@@ -121,3 +110,3 @@

Copyright (c) 2010-2023 LiosK
Copyright (c) 2010-2024 LiosK

@@ -141,3 +130,3 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use

- [RFC 4122](https://www.ietf.org/rfc/rfc4122.txt)
- [RFC 9562](https://www.rfc-editor.org/rfc/rfc9562)
- [GitHub Repository](https://github.com/LiosK/UUID.js)

@@ -144,0 +133,0 @@ - [npm Package](https://www.npmjs.com/package/uuidjs)

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc