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

backend-randomid

v1.1.6

Published

This section documents the UUID generation utility provided by the `@willeder-inc/backend` package. It includes the `generatedId` function, which generates a unique identifier using the UUID v4 standard.

Downloads

82

Readme

UUID Generation Utility

This section documents the UUID generation utility provided by the @willeder-inc/backend package. It includes the generatedId function, which generates a unique identifier using the UUID v4 standard.

generatedId

The generatedId function creates a universally unique identifier (UUID) using the uuid package. This is useful for generating unique keys for database entries, session IDs, or any other use case where a unique identifier is required.

Example Usage

Here’s an example of how to use the generatedId function:

import { generatedId } from '@willeder-inc/backend';

const uniqueId = generatedId();
console.log('Generated ID:', uniqueId); // Example output: 'e6f2a60c-d4c3-4c6e-9d56-7bcd1e5f0f83'

Unique ID Generation Utility

This section documents the unique ID generation utility provided by the @willeder-inc/backend package. It includes the generateUniqueId function, which creates a shortened unique identifier from a UUID v4.

generateUniqueId

The generateUniqueId function generates a unique identifier by creating a UUID v4 and then truncating it to the first 12 characters. This is useful for scenarios where a shorter unique key is needed while still maintaining a low risk of collisions.

Example Usage

Here’s an example of how to use the generateUniqueId function:

import { generateUniqueId } from '@willeder-inc/backend';

const uniqueId = generateUniqueId();
console.log('Generated Unique ID:', uniqueId); // Example output: 'f6e0b38f7c12'

Random Number Generation Utility

This section documents the random number generation utility provided by the @willeder-inc/backend package. It includes the randomNumber function, which generates a random number or string based on specified length and character set.

randomNumber

The randomNumber function generates a random string of a specified length using a defined character set. This function can be used to create unique identifiers, tokens, or any random strings needed for your application.

Parameters

  • length (number): The desired length of the generated string. Defaults to 6 if not specified.
  • charset ('alphanumeric' | 'alphabetic' | 'numeric' | 'hex' | 'binary' | 'octal'): The character set to use for generating the string:
    • alphanumeric: Includes letters and numbers (e.g., A-Z, a-z, 0-9).
    • alphabetic: Includes only letters (e.g., A-Z, a-z).
    • numeric: Includes only numbers (e.g., 0-9).
    • hex: Includes hexadecimal characters (e.g., 0-9, a-f).
    • binary: Includes binary characters (e.g., 0, 1).
    • octal: Includes octal characters (e.g., 0-7).

Returns

  • string: A randomly generated string of the specified length and character set.

Example Usage

Here’s an example of how to use the randomNumber function:

import { randomNumber } from '@willeder-inc/backend';

const randomNum = randomNumber(8, 'alphanumeric');
console.log('Generated Random Number:', randomNum); // Example output: 'A3cF7g9Z'

MongoDB ObjectId Generation Utility

This section documents the MongoDB ObjectId generation utility provided by the @willeder-inc/backend package. It includes the objectId function, which creates a new unique ObjectId that can be used for database documents.

objectId

The objectId function generates a new MongoDB ObjectId. ObjectIds are 12-byte identifiers typically used as unique identifiers for documents in MongoDB.

Returns

  • mongoose.Types.ObjectId: A newly created ObjectId that can be used as an identifier in MongoDB.

Example Usage

Here’s an example of how to use the objectId function:

import { objectId } from '@willeder-inc/backend';

const newId = objectId();
console.log('Generated ObjectId:', newId); // Example output: ObjectId("507f1f77bcf86cd799439011")

Password Generation Utility

This section documents the password generation utility provided by the @willeder-inc/backend package. It includes the generatePassword function, which creates a secure password that meets specified criteria.

generatePassword

The generatePassword function generates a random password of a specified length and ensures that it meets the requirements defined by a regular expression.

Parameters

  • length: number
    • The desired length of the generated password.
  • RegExp: RegExp
    • A regular expression that the generated password must match. This allows for enforcing rules such as the inclusion of special characters, uppercase letters, etc.

Returns

  • string: A randomly generated password that meets the specified length and regex criteria.

Example Usage

Here’s an example of how to use the generatePassword function:

import { generatePassword } from '@willeder-inc/backend';

// Example regex: at least one uppercase letter and one digit
const passwordRegex = /^(?=.*[A-Z])(?=.*\d).{8,}$/; // At least 8 characters, one uppercase letter, one digit
const passwordLength = 12;

const newPassword = generatePassword(passwordLength, passwordRegex);
console.log('Generated Password:', newPassword); // Example output: 'A1b2c3D4e5F6'