From cc1b149b85ad815a7c20cb8a9de44c9cf85cf3ed Mon Sep 17 00:00:00 2001 From: ryanande Date: Wed, 7 Jan 2026 13:19:33 -0700 Subject: [PATCH 1/2] Add TypeScript type definitions - Add TypeScript definition file (src/index.d.ts) for generateSequentialGuid function - Add build script to copy .d.ts files from src/ to lib/ during build - Update build process to include type definition copying step - Fixes issue where consuming applications with strict TypeScript fail to compile --- package.json | 3 ++- scripts/copy-types.js | 48 +++++++++++++++++++++++++++++++++++++++++++ src/index.d.ts | 26 +++++++++++++++++++++++ 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 scripts/copy-types.js create mode 100644 src/index.d.ts diff --git a/package.json b/package.json index b0d7c2f..36e6438 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/copy-types.js b/scripts/copy-types.js new file mode 100644 index 0000000..02e1814 --- /dev/null +++ b/scripts/copy-types.js @@ -0,0 +1,48 @@ +#!/usr/bin/env node + +/** + * Copy TypeScript definition files from src/ to lib/ + * This ensures .d.ts files are included in the build output + */ + +import { readdir, copyFile, mkdir } from 'fs/promises'; +import { join, dirname } from 'path'; +import { fileURLToPath } from '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'); + +async function copyTypeDefinitions() { + 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); + } + } +} + +copyTypeDefinitions(); + diff --git a/src/index.d.ts b/src/index.d.ts new file mode 100644 index 0000000..b91a892 --- /dev/null +++ b/src/index.d.ts @@ -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; + From e2e62f3e00dbbf0a3552e53272cd0a3726113f3f Mon Sep 17 00:00:00 2001 From: ryanande Date: Wed, 7 Jan 2026 13:21:43 -0700 Subject: [PATCH 2/2] Refactor copy-types script to use top-level await and fix import sorting --- scripts/copy-types.js | 56 ++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/scripts/copy-types.js b/scripts/copy-types.js index 02e1814..6d2d6ec 100644 --- a/scripts/copy-types.js +++ b/scripts/copy-types.js @@ -5,9 +5,9 @@ * This ensures .d.ts files are included in the build output */ -import { readdir, copyFile, mkdir } from 'fs/promises'; -import { join, dirname } from 'path'; -import { fileURLToPath } from 'url'; +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); @@ -15,34 +15,30 @@ const projectRoot = join(__dirname, '..'); const srcDir = join(projectRoot, 'src'); const libDir = join(projectRoot, 'lib'); -async function copyTypeDefinitions() { - 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/`); - } +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); - } + 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); } } -copyTypeDefinitions(); -