1.0.0 • Published 8 months ago
isvaliduuid v1.0.0
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
nilUUIDs (00000000-0000-0000-0000-000000000000).
Installation
npm install isvaliduuidUsage
import isValidUUID from 'isvaliduuid';Basic UUID validation
console.log(isValidUUID('550e8400-e29b-41d4-a716-446655440000')); // true
console.log(isValidUUID('not-a-uuid')); // falseValidating a specific version
console.log(
isValidUUID('550e8400-e29b-41d4-a716-446655440000', { version: 4 }),
);
// true
console.log(
isValidUUID('550e8400-e29b-41d4-a716-446655440000', { version: 1 }),
);
// falseRestricting 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,
}),
);
// falseAPI
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
trueif the UUID is valid according to the given constraints.falseif the UUID is invalid or does not match the specified criteria.
License
Licensed under the Apache License 2.0.