Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
uuid-v4-validator
Advanced tools
Generate, manage and validate easily Universally Unique Identifiers v4
This package provides the essential methods to generate and validate Universally Unique Identifiers v4, that you can use for naming or identify elements in a list, documents in a databases, variables or whatever you want.
Is a collision between 2 randomly generated UUIDs possible? According to the Birthday Paradox, the probability of finding a collision between 2 UUID within 103 trillion UUIDs is one in a billion. The number of random UUIDs which need to be generated in order to have a 50% probability of at least one collision is 2.71 quintillion.
npm install uuid-v4-validator
UUIDv4.id
UUIDv4.stopExecutionAtError
UUIDv4.generate
UUIDv4.validate
UUIDv4.renewId
Create a UUIDv4 instance with an own generated random id. You can pass a custom uuid that will be validate. ⚠ Generate an error if the provided id doesn't pass the validation.
get: The current id. It's always valid set: Set a new custom id. ⚠ Generate an error if the provided id doesn't pass the validation.
⚠ NOT SAFE - Generate a warn instead of stopping execution at runtime, this allow the storage of invalid ids
Generate a new UUID v4 string.
Return true if the provided UUID v4 string passes the validation or the provided Object or UUIDv4 instance has a valid UUID v4 and format
Generate a new instance id that will override the old one
import UUIDv4 from "uuid-v4-validator";
const userId = new UUIDv4();
console.log(userId);
// Return a UUIDv4 instance
// Expected output: UUIDv4 { _id: "s4F68hFDf-d3R5-4Rt6-dRgi-dEji85feY51s" }
console.log(userId.id);
// Return UUID as string
// Expected output: "s4F68hFDf-d3R5-4Rt6-dRgi-dEji85feY51s"
import UUIDv4 from "uuid-v4-validator";
const userId1 = new UUIDv4("s4F68hFDf-d3R5-4Rt6-dRgi-dEji85feY51s");
console.log(userId);
// Return a UUIDv4 instance
// Expected output: UUIDv4 { _id: "s4F68hFDf-d3R5-4Rt6-dRgi-dEji85feY51s" }
const userId2 = new UUIDv4("s4F68hF");
// Execution stops due to an error
// Expected output: The provided UUIDv4 "s4F68hF" string doesn't pass the validation. Use a valid UUIDv4 string or generate a new one
import UUIDv4 from "uuid-v4-validator";
const importedId = "s4F68hFDf-d3R5-4Rt6-dRgi-dEji85feY51s";
console.log(UUIDv4.validate(importedId));
// Return true if the provided ID respect the UUID v4 standards
// Expected output: true
const importedIdInstance = new UUIDv4();
console.log(UUIDv4.validate(importedIdInstance));
// Return true if the provided object is a valid UUIDv4 instance and the ID respects the UUID v4 standards
// Expected output: true
const importedIdObject = {
_id: "s4F68hFDf-d3R5-4Rt6-dRgi-dEji85feY51s"
};
console.log(UUIDv4.validate(importedIdObject));
// Return true if the provided object can be casted to a valid UUIDv4 instance and the ID respect the UUID v4 standards
// Expected output: true
import UUIDv4 from "uuid-v4-validator";
const uuidv4Instance = new UUIDv4();
const validId = "s4F68hFDf-d3R5-4Rt6-dRgi-dEji85feY51s";
const invalidId = "s4F68";
uuidv4Instance.id = validId;
console.log(uuidv4Instance.id);
// Return true if the provided ID respect the UUID v4 standards
// Expected output: true
uuidv4Instance.id = invalidId;
// Execution stops due to an error
// Expected output: The provided UUIDv4 "s4F68h" string doesn't pass the validation. Use a valid UUIDv4 string or generate a new one
UUID v4 package released under MIT License. See LICENSE for details.
FAQs
Generate, manage and validate Universally Unique Identifiers v4
The npm package uuid-v4-validator receives a total of 1,928 weekly downloads. As such, uuid-v4-validator popularity was classified as popular.
We found that uuid-v4-validator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.