npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

uuidjs

v5.1.0

Published

RFC-compliant UUID Generator for JavaScript

Downloads

38,521

Readme

UUID.js - RFC-compliant UUID Generator for JavaScript

npm License

Synopsis

<!-- HTML5 -->
<script type="module">
  import { UUID } from "https://unpkg.com/uuidjs@^5";
  const uuid = UUID.generate();
</script>
// Node.js
import { UUID } from "uuidjs";
const uuid = UUID.generate();
// TypeScript
import { UUID } from "uuidjs";
const str: string = UUID.generate();
const obj: UUID = UUID.genV4();
# Command-line
npx uuidjs

Description

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 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 of a generated or parsed UUID
  • Utilizes a cryptographically secure pseudo-random number generator if available, whereas falling back to Math.random() otherwise
  • Appends extra random bits to compensate for the lower timestamp resolution of JavaScript than that required for UUIDv1 and UUIDv6
  • Comes with a lot of test cases including format checks and statistical tests to maintain a high-quality code base

Usage Examples

Import UUID class:

import { UUID } from "uuidjs";
// or on browsers:
// import { UUID } from "https://unpkg.com/uuidjs@^5";

UUID.generate() returns a UUIDv4 as a hexadecimal string.

// Create a UUIDv4 as a hexadecimal string
console.log(UUID.generate());   // fa84cf42-ffdf-4975-b42b-31ab5fb983eb

UUID.genV4(), UUID.genV1(), UUID.genV6(), and UUID.parse() return a UUID object that has various fields and methods.

// Create a UUIDv4 (random number-based UUID) object
const objV4 = UUID.genV4();

// 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
const uuid = UUID.parse("a0e0f130-8c21-11df-92d9-95795a3bcd40");

// Get string representations of a UUID object
console.log(uuid.toString());   // "a0e0f130-8c21-11df-92d9-95795a3bcd40"
console.log(uuid.hexString);    // "a0e0f130-8c21-11df-92d9-95795a3bcd40"
console.log(uuid.hexNoDelim);   // "a0e0f1308c2111df92d995795a3bcd40"
console.log(uuid.bitString);    // "101000001110000 ... 1100110101000000"
console.log(uuid.urn);          // "urn:uuid:a0e0f130-8c21-11df-92d9-95795a3bcd40"

// Compare UUID objects
console.log(objV4.equals(objV1));   // false

// Get UUID version numbers
console.log(objV4.version); // 4
console.log(objV1.version); // 1
console.log(objV6.version); // 6

License

Copyright (c) 2010-2024 LiosK

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Author

LiosK [email protected]

See Also