From 5bed23e0b7f03fed139d7d6235a209f6468184a9 Mon Sep 17 00:00:00 2001 From: Ryan Anderson Date: Tue, 23 Dec 2025 16:08:28 -0600 Subject: [PATCH] docs: improve README with better examples and accurate info - Remove outdated moment.js dependency mention - Add TypeScript support documentation - Add ES Modules, CommonJS, and TypeScript usage examples - Add practical use cases section - Add API documentation - Improve description and features list --- README.md | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index dca63a1..4cb75fb 100644 --- a/README.md +++ b/README.md @@ -4,16 +4,17 @@ [![Build Status](https://github.com/ryanande/JsCombGuid/workflows/CI/badge.svg)](https://github.com/ryanande/JsCombGuid/actions) [![Coverage Status](https://coveralls.io/repos/github/ryanande/JsCombGuid/badge.svg?branch=master)](https://coveralls.io/github/ryanande/JsCombGuid?branch=master) -A high-performance JavaScript Sequential GUID Generator that creates sortable, unique identifiers with microsecond precision. +A high-performance JavaScript Sequential GUID Generator that creates sortable, unique identifiers with microsecond precision. Perfect for databases, distributed systems, and any scenario where you need sortable, unique IDs. ## Features - **High Performance**: Optimized for speed with minimal memory allocations - **Microsecond Precision**: Uses high-resolution timestamps for better uniqueness -- **Sortable**: GUIDs are chronologically sortable +- **Sortable**: GUIDs are chronologically sortable by creation time - **Collision Resistant**: Multiple entropy sources and a counter for high-frequency generation - **RFC4122 Compliant**: Generates valid UUID v4 format -- **Zero Dependencies**: Only requires moment.js for date calculations +- **Zero Dependencies**: Pure JavaScript with no external dependencies +- **TypeScript Support**: Includes TypeScript type definitions ## Installation @@ -23,6 +24,8 @@ npm install jscombguid ## Usage +### ES Modules (Recommended) + ```javascript import generateSequentialGuid from 'jscombguid'; @@ -34,6 +37,36 @@ console.log(guid); // e.g., "550e8400-e29b-41d4-a716-446655440000" const guids = Array.from({ length: 10 }, () => generateSequentialGuid()); ``` +### CommonJS + +```javascript +const generateSequentialGuid = require('jscombguid'); + +const guid = generateSequentialGuid(); +``` + +### TypeScript + +```typescript +import generateSequentialGuid from 'jscombguid'; + +const guid: string = generateSequentialGuid(); +``` + +### Use Cases + +```javascript +// Database primary keys +const userId = generateSequentialGuid(); + +// Sortable transaction IDs +const transactionIds = Array.from({ length: 100 }, () => generateSequentialGuid()); +// These can be sorted chronologically! + +// Distributed system identifiers +const sessionId = generateSequentialGuid(); +``` + ## Performance The generator is optimized for high-performance scenarios: @@ -58,6 +91,20 @@ This combination ensures: - Microsecond precision - Collision resistance +## API + +### `generateSequentialGuid()` + +Generates a sequential GUID string. + +**Returns:** `string` - A 36-character GUID in UUID v4 format + +**Example:** +```javascript +const guid = generateSequentialGuid(); +// "550e8400-e29b-41d4-a716-446655440000" +``` + ## Benchmarks ```javascript