This package allows one to generate DigitalOcean-style usernames. The logic for the generator is taken from IPv4's generator.
Example:
const Generator = require("do-usernames");
const myGenerator = new Generator({
nouns: arr => [...arr, "Crustacean"],
size: 32
});
console.log(myGenerator.getNames(5));
A class, Generator
, is exported.
#
means static.
.
means an instance property.
A list of sea creatures, taken from IPv4's generator.
An array of sea objects, taken from IPv4's generator
An array of adjectives, taken from IPv4's generator.
An array of sizes, taken from IPv4's generator.
An array of action descriptors, taken from IPv4's generator.
An array of ocean-related colors, taken from IPv4's generator.
An array of sea nouns. This is created by combining Generator#SEA_CREATURES
and Generator#SEA_OBJECTS
.
An array of sea adjectives. This is created by combining Generator#ADJECTIVE_DESCRIPTORS
, Generator#SIZE_DESCRIPTORS
, and Generator#CREATURE_DESCRIPTORS
.
Creates a Generator
. colors
, nouns
, and descriptors
can each be either a function, in which case the first argument to that function is the built-in array, and the return value is used as the word pool, or an array, in which case the array is used as the word pool. size
must be a number (if given),
Example:
new Generator({
colors: arr => [...arr, "CoralPink"]
});
new Generator({
colors: ["SeaGreen", "CoralPink", "Cyan"]
});
new Generator();
new Generator({
size: 16
});
These functions return colors
, nouns
, and descriptors
respectively. They do not clone the array, so be careful while modifying it.
Returns the current maximum username size of the generator.
Allows for post-initalization modification of the nouns
, colors
, and descriptors
array. These functions will throw if an empty array (or non-array) is given, so make sure the input is valid.
Sets the maximum username size of the generator.
These functions are aliases for each other. They return either one value or an array of values, depending on the amount. Each value is a username generated from the word pools in the generator.
- Run
npm i -g do-usernames
. - Run
do-usernames [amount]
.
To contribute, clone the repository, code away, and then make a pull request when you're ready.
Once you've written code, but you want to test it, run npm test
. This will run an automated test collection to see if your code breaks anything important. If you are adding new features, try to add tests for those features to test/test.js
.