Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
"lint": "eslint src/**",
"test": "nyc mocha --require @babel/register",
"compile": "babel ./src -d ./lib",
"copy-types": "node scripts/copy-types.js",
"verify": "npm run lint && npm run test",
"build": "npm run clean && npm run lint && npm run compile && npm run test",
"build": "npm run clean && npm run lint && npm run compile && npm run copy-types && npm run test",
"prepublishOnly": "npm run build",
"upgrade-interactive": "npm-check-updates --interactive",
"trypublish": "npm publish || true",
Expand Down
44 changes: 44 additions & 0 deletions scripts/copy-types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env node

/**
* Copy TypeScript definition files from src/ to lib/
* This ensures .d.ts files are included in the build output
*/

import { copyFile, mkdir, readdir } from 'node:fs/promises';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const projectRoot = join(__dirname, '..');
const srcDir = join(projectRoot, 'src');
const libDir = join(projectRoot, 'lib');

try {
// Ensure lib directory exists
await mkdir(libDir, { recursive: true });

// Read all files in src directory
const files = await readdir(srcDir);

// Copy all .d.ts files
const typeFiles = files.filter(file => file.endsWith('.d.ts'));

for (const file of typeFiles) {
const srcPath = join(srcDir, file);
const destPath = join(libDir, file);
await copyFile(srcPath, destPath);
console.log(`Copied ${file} to lib/`);
}

if (typeFiles.length === 0) {
console.log('No TypeScript definition files found in src/');
}
} catch (error) {
if (error.code !== 'ENOENT') {
console.error('Error copying type definitions:', error);
process.exit(1);
}
}

26 changes: 26 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @module jscombguid
* @description A high-performance sequential GUID generator that creates sortable, unique identifiers
* with microsecond precision. The generator combines a base UUID with timestamp and counter information
* to ensure uniqueness and chronological sortability.
*/

/**
* Generates a sequential GUID (Globally Unique Identifier) that is sortable by creation time.
* This implementation creates a COMB (Combined GUID) that embeds a timestamp with microsecond precision
* and includes additional entropy sources to minimize collision probability.
*
* @returns A 36-character GUID string in the format: xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
*
* @example
* ```typescript
* import generateSequentialGuid from 'jscombguid';
*
* const guid = generateSequentialGuid();
* console.log(guid); // e.g., "550e8400-e29b-41d4-a716-446655440000"
* ```
*/
declare function generateSequentialGuid(): string;

export default generateSequentialGuid;