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

nvrng

v1.5.1

Published

Not very random temporary name generator

Downloads

5

Readme

Codecov Coverage

nvrng

Not very random temporary name generator

Description

NVRNG generates array of random readable names, like 'Silver Raccoon', 'Purple Snake' or sets of real names like 'Aaron Smith', etc. NVRNG can create sets for different genders (like 'Lemon Stallion' or 'Marble Actress'). NVRNG uses vocabulary in json format.

Installation

npm install nvrng --save

Example

const { NVRNG } = require('nvrng');

let gen = new NVRNG();
gen.upload('./file.json');
let [err, nameset] = gen.getSet(5);

Here nameset is of type Set

Some predefined vocabularies can be found in vocabularies folder in repository

EN Colored Animals

RU Colored Animals

EN Common Names

Please, make pull request if found any errors or if you have any other vocabulary to suggest.

Methods

constructor({ limit = 100000 })

limit - max number of attempts to create set

upload(filename, { shuffle = true }) => err

Setup vocabulary. Returns error. If everything is ok, then returns null;

filename - path to json vocabulary

shuffle - to shuffle vocabulary after upload

setup(data, { shuffle = true }) => err

Setup vocabulary. Returns error. If everything is ok, then returns null;

data - JSON object, the vocabulary

shuffle - to shuffle vocabulary after upload

getSet(size, { gender = Genders.Any, output = OutputFormat.Set, include, exclude, delimiter = ' ', format = StringFormat.NoFormat, noJoin = false }) => [err, set]

Generate set of random names. Returns array. First element is error (null if ok), second is a set of names;

gender - gender, possible values are 'n', 'f', 'm', or 'a'. You can also use Enum Genders with values

  • Genders.Any
  • Genders.Female
  • Genders.Male
  • Genders.Nuetral

if bad value is used then getSet will return error and null;

Note that possible variants depend on your vocabulary file. Hence, if there is only 'n' gender, then you can not use 'f' or 'm' gender. 'a' value will return list with random genders.

output - output format. Possible formats are 'set', 'array', 'object', or

  • OutputFormat.Set
  • OutputFormat.Array
  • OutputFormat.Object

format - string output format. Possible values are 'lowercase', 'uppercase', 'capitalize', 'noformat', or

  • StringFormat.Lowercase
  • StringFormat.Uppercase
  • StringFormat.Capitalize
  • StringFormat.NoFormat

Note, don't forget to export enums with NVRNG:

let { NVRNG, OutputFormat, Genders, StringFormat } = require('nvrng');

if bad value is used, then getSet will return error and set.

include - array or set of values that would be injected to output set, default is empty set. For example, if include is 3 unique strings long and you generate 5 new strings, then output would be 5 + 3 = 8 strings long

exclude - array or set of values that must be ommitted in output set, default is empty set

delimiter - char to join random words, default is ' '

noJoin - not to join elements of string. Returns collection of arrays, for example

let gen = new NVRNG();
gen.upload(__dirname + '/../examples/simplest4.json');

let [err, set] = gen.getSet(3, { format: StringFormat.Capitalize, noJoin: true });
console.log(set);

prints

Set {
  [ 'Red', 'Horse', 'With', 'Notebook' ],
  [ 'Green', 'Horse', 'With', 'Keys' ],
  [ 'Yellow', 'Duck', 'With', 'Keys' ] }

Be careful with include in this case. noJoin uses concatenated strings to compare values and join strings with delimiter.

getOne({ gender = Genders.Any, exclude, delimiter = ' ', format = StringFormat.NoFormat, noJoin = false }) => [err, string]

Returns array of error and single string (or array, if noJoin is used). Same options as in getSet (except include and output).

getKeys => Array

Returns array of keys available for uploaded vocabulary

const filename = __dirname + '/../examples/gender.json';
err = gen.upload(filename);
console.log(gen.getKeys()); //[ 'f', 'm', 'n' ]

Vocabulary

Vocabulary is a json object which contains one or more objects ("spaces") with 1 to 3 different arrays. For example

{
    "adjectives": {
        "n": ["red", "orange", "yellow", "green", "blue", "dark blue", "purple"]
    },
    "nouns": {
        "n": ["cat", "dog", "cow", "horse", "mouse", "duck", "elephant"]
    }
}

or

{
    "adjectives": {
        "n": ["red", "orange", "yellow", "green", "blue", "dark blue", "purple"],
        "f": ["red", "orange", "yellow", "green", "blue", "dark blue", "purple"],
        "m": ["red", "orange", "yellow", "green", "blue", "dark blue", "purple"]
    },
    "nouns": {
        "n": ["artist",  "heir",     "server",   "chicken", "spouse",  "horse",    "person"],
        "f": ["actress", "princess", "waitress", "hen",     "wife",    "mare",     "woman"],
        "m": ["actor",   "prince",   "waiter",   "rooster", "husband", "stallion", "man"]
    }
}

Number of "spaces" is not limited. If one array can be used for different genders (like adjective for male and female animals in english, or second name for both male and female first name) then it can be substituted with one "a" array, see EN Common Names. Array must contain at least one word.

NOTE: if "a" is used, then "space" must not have any other keys. Also, all keys from all different "spaces" must match, except for an "a" key. If vocabulary has any errors then upload method will return error with description of the problem.

Examples

let { NVRNG, OutputFormat, Genders, StringFormat } = require('../index.js');

let gen = new NVRNG();
gen.upload(__dirname + '/../examples/simplest4.json');

let [err, set] = gen.getSet(3, { delimiter: '-', format: StringFormat.Capitalize });

console.log(err);
set.forEach(item => console.log(item));

let newname;
[err, newname] = gen.getOne({ delimiter: '-', format: StringFormat.Capitalize, exclude: set });

console.log(newname);

Output is

null
Dark-blue-Mouse-With-Notebook
Purple-Dog-With-Gun
Green-Elephant-With-Gun
Purple-Dog-With-Car

Generate sets with yield

let yGen = (function* () {
    let exSet = new Set();
    for (;;) {
        let [err, next] = gen.getOne({ exclude: exSet });
        exSet.add(next);
        yield next;
    }
})();

for (let i = 0; i < 10; i++) {
    console.log(yGen.next().value);
}

Testing

Clone repository and run

npm run test

npm run cover