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

reddit-style-username-generator

v1.13.0

Published

A utility for generating and storing unique username combinations in Redis. This package reads usernames from a file, generates combinations with specified colors and nouns, and stores them in a Redis set.

Downloads

118

Readme

reddit-style-username-generator

A utility for generating and storing unique username combinations in Redis. This package reads usernames from a file, generates combinations with specified colors and nouns, and stores them in a Redis set.

Installation

To install the package, run the following command:

npm install reddit-style-username-generator

Usage

Importing the Class

First, import the class in your TypeScript or JavaScript file:

import { HydrateUsernamesInRedis } from 'reddit-style-username-generator';

Example Usage of generateUsername()

generateUsername() function generates a username by combining a random noun, an optional color, and an optional suffix number. It allows customization of the username format using a separator and the option to include a color.

Function Parameters

  • separator (string): A string that separates different parts of the username. Default is an empty string.
  • enableColor (boolean): A boolean flag to include a color in the username. Default is false.
  • suffixNumber (number, optional): An optional number to be appended at the end of the username. If not provided, a random number is generated.

Function Behavior

  1. noun: Randomly selects a noun from a predefined list.
  2. adjective: Randomly selects an adjective from a predefined list.
  3. color: (Optional) Randomly selects a color from a predefined list if enableColor is true.
  4. randomNumber: Uses the provided suffixNumber if given, otherwise generates a random number.
  5. formattedAdjective: Capitalizes the first letter of the adjective.
  6. formattedColor: (Optional) Capitalizes the first letter of the color if enableColor is true.
  7. formattedNoun: Capitalizes the first letter of the noun.

The function then constructs the username based on the provided parameters and returns it.

Examples

// Example 1: Default parameters (no color, no separator, random number)
generateUsername();
// Possible output: "HappyCat42"

// Example 2: With a separator and color enabled
generateUsername('_', true);
// Possible output: "Happy_Red_Cat57"

// Example 3: With a specific suffix number
generateUsername('-', false, 99);
// Possible output: "Happy-Cat99"

// Example 4: With a separator, color enabled, and specific suffix number
generateUsername('.', true, 7);
// Possible output: "Happy.Red.Cat7"

Example Usage for redis hydration

Here's a complete example demonstrating how to use the package:

// By default this generates 1million unique username 
import { HydrateUsernamesInRedis } from 'reddit-style-username-generator';

const redisOptions = {
  host: 'localhost',
  port: 6379,
};

const hydrateUsernames = new HydrateUsernamesInRedis(redisOptions);

const filePath = './combinations.txt';
const redisKey = 'uniqueUsernames';

// Call the method to store usernames from file to Redis
hydrateUsernames
  .storeUsernamesFromFile(filePath, redisKey)
  .then(() => {
    console.log('Usernames stored successfully.');
  })
  .catch((error) => {
    console.error('Error storing usernames:', error);
  });

Usage

You can use this function to generate usernames for various purposes such as user account names, display names, or any scenario where a unique and customizable username is required. The flexibility in formatting allows for a wide range of possible username combinations.

Contributing

Feel free to contribute by opening issues or submitting pull requests.

License

This project is licensed under the MIT License.