better-username-generator
v1.1.0
Published
Generate random usernames based on your own custom templates and rules
Downloads
4
Maintainers
Readme
Generate random usernames based on your own custom templates and rules!
Installation
# with npm
npm install username-generator
# with yarn
yarn add username-generator
Usage
import { generateUsername } from "username-generator";
generateUsername("{{firstname:m}}_{{lastname}}"); // "john_smith"
Templates
A template is a string that can contain any number of placeholders. Placeholders are replaced with a random value when generating a username. You can use placeholders multiple times in a template, each placeholder will be replaced with a different value.
You can also place your own text in the string, this text will be included in the generated username.
The following placeholders are available:
{{adj}}
- A random adjective.{{noun}}
- A random noun.{{firstname:gender}}
- A random first name. gender can bem
,f
orall
.{{lastname}}
- A random last name.{{number:min:max}}
- A random number betweenmin
andmax
.{{title:gender}}
- A random title. gender can bem
,f
orall
.{{prefix}}
- A random prefix.
An example template could be "{{adj}}{{noun}}{{number:100:999}}"
.
This template would generate a username like bluecat123
.
Additionally any placeholder can be capitalized by adding a ^
before the placeholder name, or made uppercase by adding ^^
before the placeholder name.
For example, {{^adj}}
would generate a username like Bluecat123
, and {{^^adj}}
would generate a username like BLUEcat123
.
Contributing
Prerequisites
- node (lts version)
- yarn (1.^22.10)
Setup
# clone repo
git clone https://github.com/freddie-nelson/username-generator
cd username-generator
# install dependencies
yarn
# start dev server
yarn dev
# run build
node dist/index.esm.js
License
Copyright © 2020 - Present, Freddie Nelson