Socket
Book a DemoInstallSign in
Socket

uuid-v9

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uuid-v9

0.1.0
bundlerRubygems
Version published
Maintainers
1
Created
Source

UUID v9

Fast, lightweight, zero-dependency Ruby implementation of UUID version 9

The v9 UUID supports both sequential (time-based) and non-sequential (random) UUIDs with an optional prefix of up to four bytes, an optional checksum, and sufficient randomness to avoid collisions. It uses the UNIX timestamp for sequential UUIDs and CRC-8 for checksums. A version digit can be added if desired, but is omitted by default.

To learn more about UUID v9, please visit the website: https://uuidv9.jhunt.dev

Installation

Install UUID v9 from Rubygems

gem install uuid-v9

Usage

require 'uuid-v9'

ordered_id = UUIDv9::UUIDv9.generate
prefixed_ordered_id = UUIDv9::UUIDv9.generate(prefix: 'a1b2c3d4')
unordered_id = UUIDv9::UUIDv9.generate(timestamp: false)
prefixed_unordered_id = UUIDv9::UUIDv9.generate(prefix: 'a1b2c3d4', timestamp: false)
ordered_id_with_checksum = UUIDv9::UUIDv9.generate(checksum: true)
ordered_id_with_version = UUIDv9::UUIDv9.generate(version: true)
ordered_id_with_legacy_mode = UUIDv9::UUIDv9.generate(legacy: true)

is_valid = UUIDv9::UUIDv9.valid?(ordered_id)
is_valid_with_checksum = UUIDv9::UUIDv9.valid?(ordered_id_with_checksum, checksum: true)
is_valid_with_version = UUIDv9::UUIDv9.valid?(ordered_id_with_version, version: true)

Backward Compatibility

Some UUID validators check for specific features of v1 or v4 UUIDs. This causes some valid v9 UUIDs to appear invalid. Three possible workarounds are:

  • Use the built-in validator (recommended)
  • Use legacy mode*
  • Bypass the validator (not recommended)

*Legacy mode adds version and variant digits to immitate v1 or v4 UUIDs depending on the presence of a timestamp.

License

This project is licensed under the MIT License.

FAQs

Package last updated on 17 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.