GithubHelp home page GithubHelp logo

advance-username-generator's Introduction

Username Generator

Description

usernameGenerator is a flexible JavaScript library designed to integrate seamlessly with Express.js controllers. It efficiently generates unique usernames based on user-provided criteria without blocking the event loop, ideal for handling HTTP requests within an Express application.

Installation

Install the package using npm:

npm install username-generator

Features

  • Asynchronous Username Generation: Perfect for real-time web applications.
  • Customizable: Supports custom lengths, inclusion of symbols, and various separators.
  • Express Compatibility: Optimized for use within Express.js server environments.

API Reference

usernameGenerator(options: UsernameGeneratorInput): Promise<string>

Generates a unique username based on provided options.

Parameters

  • fullName (string): The user's full name from which the username will be generated.
  • usedUsernames (string[]): An array of usernames already in use to ensure uniqueness.
  • minLength (number): Optional. Minimum length of the username, default is 8 characters.
  • allowSymbols (boolean): Optional. Whether to include symbols, default is false.
  • separator (string): Optional. Character to replace spaces in names, default is an empty string.

Returns

  • Promise: A promise that resolves to the generated username.

Example Usage

Below is an example of how usernameGenerator can be used:

import { usernameGenerator, UsernameGeneratorInput } from 'username-generator';

async function generateAndLogUsername() {
  const options: UsernameGeneratorInput = {
    fullName: 'John Doe', // Full name
    usedUsernames: ['johndoe', 'john_doe', 'johndoe1'], // List of used usernames
    allowSymbols: false, // Symbols allowed in username
    minLength: 6, // Minimum length of the username
    separator: '_', // Separator between first and last name
  };

  try {
    const username = await usernameGenerator(options); // Generate username
    console.log('Generated Username:', username); // Log the generated username
  } catch (error) {
    console.error('Error during username generation:', error); // Log error if username generation fails
  }
}

generateAndLogUsername(); // Call the function to generate and log a username

This example demonstrates how the usernameGenerator function can be used to generate a username with customized options.

Support

For support, issues, or further documentation, please visit our GitHub repository.

advance-username-generator's People

Contributors

liu-purnomo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.