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

@shopascart/uuid

v1.2.4

Published

A uuid generator

Downloads

13

Readme

Unique ID

Description

The UniqueID algorithm is designed to generate unique identifiers for various purposes, such as user IDs, product IDs, order IDs, and so on. The algorithm generates IDs of two types: string and number. The string IDs consist of a prefix (optional), a UUID (Universal Unique Identifier), a timestamp, a random number, and a random bit. The number IDs are generated based on a random number, a timestamp, and a random bit.

How It Works

  1. It generates a single random bit using the RandomBits function.

  2. It gets the current timestamp using new Date().getTime().

  3. It creates an array of random characters from the alphanumeric character set "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".

  4. It generates a random 64-bit integer using Math.random() * 100000000 * 0x100000000

  5. It generates a UUID using crypto.randomBytes.

  6. It concatenates the prefix (if present), the UUID, the timestamp, the random number, and the random bit to create a unique string.

  7. If the requested type is "string", it returns the unique string truncated to the specified length.

  8. If the requested type is "number", it returns a unique number generated by concatenating the timestamp, the random number, and the random bit, and truncating to the specified length.

For string identifiers, the elements are combined into a single string in the following format: [prefix]_[uuid][timestamp][randomNumber][randomBit]. The prefix is optional. The resulting string is then truncated to the desired length specified in the constructor.

For number identifiers, the elements are concatenated into a single string in the following format: [randomNumber][timestamp][randomBit]. The resulting string is then converted to a number and truncated to the desired length specified in the constructor.

The UniqueID algorithm provides a UUID wrapper function that exposes two methods: generate and test. The UUID function is a wrapper function to the UniqueID class. It provides a more user-friendly interface for generating and testing unique IDs by exposing two methods: generate and test. These methods internally call the corresponding methods of the UniqueID class and provide the necessary options and parameters. The function takes an optional options parameter that can be used to configure the prefix, length, and type of the unique ID.

The generate method generates a unique ID based on the options provided, or by default, generates a unique ID with a length of 16 characters and a type of "string". It returns the generated unique ID.

The test method tests the uniqueness of the unique ID algorithm by generating a large number of unique IDs and checking for duplicates. It returns a boolean that indicates whether the list of generated unique IDs are unique or not.

Installation

npm install @shopascart/uuid

Usage

import UUID from '@shopascart/uuid';

const uuid = new UUID();
const uniqueID = uuid.generate();

Limitations

The algorithm may have collisions (i.e., generate the same ID twice) in extremely rare cases. The probability of a collision is extremely low, but it is not zero. The algorithm is still in development and may be improved in the future.