npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ouid-h47

v1.0.2

Published

A Node.js package to generate optimized unique IDs with timestamp and random component.

Downloads

6

Readme

OUID (Optimized Unique Identifier)

npm GitHub GitHub issues

Node.js package designed to generate optimized unique identifiers (OUID) that incorporate both a timestamp and a random component. These identifiers are suitable for a variety of applications, including database keys, session identifiers, and unique references in distributed systems.

Features

  • Optimized Unique Identifiers (OUID): Combines a timestamp with a random string to ensure uniqueness and optimize sorting.
  • Timestamp-Based: IDs include a timestamp component, which makes them naturally sortable by creation time.
  • High Performance: Designed to generate unique IDs quickly and efficiently.
  • Simple API: Easy-to-use function to generate IDs with no configuration required.
  • Collision Resistant: Built to minimize the risk of generating duplicate IDs even in high-throughput environments.

Benefits

  • Improved Performance: By including a timestamp, OUIDs can be indexed and sorted more efficiently in databases.
  • Distributed System Friendly: The randomness and timestamp components ensure uniqueness across distributed systems.
  • Ease of Use: Simplifies the process of generating unique identifiers without needing to configure or manage external libraries.

Installation

Install the package using npm:

npm install ouid-h47

Usage

const { ouid } = require('ouid-h47');

// Generate a new optimal ID
const newID = ouid();
console.log('Generated optimal ID:', newID);

Performance

The performance chart below illustrates the time taken to insert batches of IDs into a MySQL database using ouid. Each batch represents a set of IDs generated and inserted sequentially.

Performance Chart

Performance Testing Details

The performance testing was conducted using a Node.js script (test-load.js) that simulates inserting batches of IDs into a MySQL database. Each batch contains a number of IDs generated by ouid, and the time taken to insert each batch was recorded.

The data reflects the average time (in milliseconds) required to complete each batch insertion, providing insights into the efficiency and scalability of ouid in real-world database operations.

Interpretation

  • Batch Insertion Time: Indicates how quickly ouid can generate and insert IDs into a database.
  • Scalability: The consistent performance across batches demonstrates the package's reliability even under load.
  • Optimization: By leveraging both timestamp and random components, ouid ensures efficient indexing and sorting of IDs within the database.

This performance data highlights the suitability of ouid for applications requiring fast and reliable unique identifier generation, such as high-throughput systems and distributed databases.

API

ouid()

Generates a new optimal ID composed of a timestamp and a random string.

  • Returns: string - A unique ID with 26 characters (10 timestamp + 16 random).

Testing

The testing framework used for ouid is Jest. To run tests:

  1. Install Jest globally or locally in your project:
npm install --save-dev jest
  1. Create a test.js file with the following content:
const { ouid } = require('ouid-h47');

// Example test
test('Generate Optimal ID Test', () => {
  const id = ouid();
  expect(typeof id).toBe('string');
  expect(id.length).toBe(26);
  expect(id).toMatch(/^[0-9a-zA-Z]{26}$/);
});
  1. Add this line to package.json
"scripts": {
    "test": "jest"
  },
  1. Run Jest to execute the tests:
npm test

Contributing

Contributions are welcome! For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

This project is licensed under the ISC License - see the LICENSE file for details.