tango-es6-guid-generator
v1.0.1
Published
Simple ES6 JavaScript GUID Generator
Maintainers
Readme
tango-es6-guid-generator
A lightweight, dependency-free RFC4122 v4 GUID generator for Node.js projects built using ES6 modules.
tango-es6-guid-generator provides a small API for generating cryptographically secure GUIDs, along with helper functions for validation and testing.
✨ Features
- RFC4122 v4 compliant GUID generation
- Cryptographically secure randomness using Node’s built-in
cryptomodule - ES6 module support
- Clean
importsyntax - No CommonJS boilerplate
- Clean
- Zero runtime dependencies
- Public validation helpers for testing and consumer use
📦 Installation
npm install tango-es6-guid-generator🚀 Quick Start
import {
generateGuid,
generateEmptyGuid,
isGuidV4,
isEmptyGuid
} from 'tango-es6-guid-generator';
const generatedGuid = generateGuid();
console.log(generatedGuid); // e.g. "3f9c2a1e-6d7e-4b6a-9c3a-8d1e2f4a9b7c"
console.log(isGuidV4(generatedGuid)); // true🧪 Examples
Example 1 — Generate a GUID
const generatedGuid = generateGuid();
// Always returns a valid, non-empty RFC4122 v4 GUIDExample 2 — Generate Empty GUID
const emptyGuid = generateEmptyGuid();
console.log(emptyGuid);
// "00000000-0000-0000-0000-000000000000"The empty GUID is provided as an explicit value and is never returned by generateGuid().
Example 3 — Helpers
isGuidV4('not-a-guid'); // false
isGuidV4(generateGuid()); // true
isEmptyGuid(generateEmptyGuid()); // true
isEmptyGuid(generateGuid()); // falseThese helpers are useful for:
- testing
- input validation
📚 Public API
tango-es6-guid-generator exposes four functions.
generateGuid()
const generatedGuid = generateGuid();- Returns a cryptographically secure RFC4122 v4 GUID
- Always returns a non-empty value
- Never returns the empty GUID
generateEmptyGuid()
const emptyGuid = generateEmptyGuid();- Returns the all-zero GUID:
00000000-0000-0000-0000-000000000000
isGuidV4(value)
isGuidV4(value);- Returns
trueifvalueis a valid RFC4122 v4 GUID - Returns
falseotherwise
isEmptyGuid(value)
isEmptyGuid(value);- Returns
trueifvalueequals the empty GUID - Returns
falseotherwise
🧠 Implementation Notes
- This module targets Node.js
- Randomness is sourced from Node’s built-in
crypto.randomBytes - No browser or Web Crypto support is included by design
🎯 Design Philosophy
tango-es6-guid-generator is intentionally minimal.
- Small, explicit API
- No configuration
- No mutable global state
- No external dependencies
- Predictable behavior
- Easy to test and reason about
