1.0.0 • Published 4 months ago

isvaliduuid v1.0.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
4 months ago

isValidUUID

Archetype: Node.js package

isvaliduuid validates a UUID. Professional, minimal and atomic. The missing piece often needed alongside the default crypto library.

Features

  • Validates general UUID format.
  • Supports checking against specific UUID versions.
  • Allows restricting the highest allowed version.
  • Rejects nil UUIDs (00000000-0000-0000-0000-000000000000).

Installation

npm install isvaliduuid

Usage

import isValidUUID from 'isvaliduuid';

Basic UUID validation

console.log(isValidUUID('550e8400-e29b-41d4-a716-446655440000')); // true
console.log(isValidUUID('not-a-uuid')); // false

Validating a specific version

console.log(
    isValidUUID('550e8400-e29b-41d4-a716-446655440000', { version: 4 }),
);
// true
console.log(
    isValidUUID('550e8400-e29b-41d4-a716-446655440000', { version: 1 }),
);
// false

Restricting the highest version allowed

console.log(
    isValidUUID('550e8400-e29b-41d4-a716-446655440000', {
        maxVersion: 5,
    }),
);
// true
console.log(
    isValidUUID('550e8400-e29b-61d4-a716-446655440000', {
        maxVersion: 5,
    }),
);
// false

API

isValidUUID(uuid: string, options?: object): boolean

Parameters

  • uuid (string): The UUID string to validate.
  • options (object, optional):
    • version (string | number): The specific version to check against. Default: "ALL" (allows all versions).
    • maxVersion (number): The maximum allowable UUID version. Default: 7.

Returns

  • true if the UUID is valid according to the given constraints.
  • false if the UUID is invalid or does not match the specified criteria.

License

Licensed under the Apache License 2.0.