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

name-generator-mongoose

v1.0.6

Published

Creates mongoose collections of first and last names and generates random full names

Downloads

7

Readme

name-generator-mongoose

This node.js module has two parts. The first part imports a large number of first & last names into the user's MongoDB using Mongoose. The data includes a popularity field to allow filtering based on a name's popularity. It also includes a gender binary field ("M" or "F") for first names.

npm package URL: https://www.npmjs.com/package/name-generator-mongoose

Setup

Install using npm: npm install name-generator-mongoose --save

Connect to your database using Mongoose (outside of the scope of these instructions).

Import module: const ng = require("name-generator-mongoose");

Note: Check out the included example.js for a complete script

Import Data

To import the data, you can run the importNames function that returns a Promise:

const ng = require("name-generator-mongoose");
ng.importNames().then(() => {
    console.log("The names have been imported");
};

You only need to import once (in fact, if it notices data already in the collection, it will stop itself from importing so as to not cause duplicates).

Generating a Random Name

The most basic command is getting a random name name from the entire database:

const ng = require("name-generator-mongoose");
ng.generateName().then((name) => {
    console.log(`${name.firstName} ${name.surname} - ${name.gender}`);
    mongoose.disconnect();
}).catch((err) => {
    console.error(err);
});

To filter by gender or popularity, you can add in an options object:

// This would filter only female first names and \
// use only top 100 most popular first & last names
options = {
    gender: "F",
    top: 100,
};
ng.generateName(options).then((name) => {
    console.log(`${name.firstName} ${name.surname} - ${name.gender}`);
    mongoose.disconnect();
}).catch((err) => {
    console.error(err);
});

Data Attributions

The surname data comes from FiveThirtyEight: https://github.com/fivethirtyeight/data

The first name data comes from the US Social Security Office: https://www.ssa.gov/oact/babynames/background.html

Using Your Own Data

You can overwrite surname.csv and firstname.csv to include your own data. The format is:

// firstname.csv
name,gender('M'/'F'),popularity(int)

//surname.csv
name,,popularity(int)

##Accessing Models If you need access to the mongoose models, you can access as such:

const ng = require("name-generator-mongoose");
const firstNameModel = ng.FirstName
const surnameModel = ng.Surname