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

firedum

v3.0.1

Published

A npm package to help you generate documents or users for your firebase project

Downloads

2

Readme

Firedum - an firestore package for quick testing

A package to generate customized mock data to to you firebase project quickly. All mock data gets generated using faker.js Any firedum function that can get passed fields will take all key-value pairs with a falsy value, such as a empty string, and check if the given key is a faker function. If it is, firedum will generate a value for that key with the faker function. For more information please read faker.js documentation

Installation

npm i firedum -D

Usage

// index.js / index.ts
import { fs } from './firebase';
import { firedumAdd } from 'firedum';

await firedumAdd({
	collectionReference: fs.collection('users'),
	fields: {
		firstName: '',
		lastName: 'Bar'
	},
	numberOfDocuments: 10
});

Initialize firebase app

// firebase.js / firebase.ts
import firebase from 'firebase/app';
import 'firebase/firestore';

const app = firebase.initializeApp({
	apiKey: FIREBASE_API_KEY,
	databaseURL: FIREBASE_DATABASE_URL,
	authDomain: FIREBASE_AUTH_DOMAIN,
	projectId: FIREBASE_PROJECT_ID,
	storageBucket: FIREBASE_STORAGE_BUCKET,
	messagingSenderId: FIREBASE_MESSAGING_SENDER_ID,
	appId: FIREBASE_APP_ID,
	measurementId: FIREBASE_MEASUREMENT_ID
});

export const fs = firebase.firestore();

export default app;

Functions

firedumAdd

Adds new documents to a given collection

import { firedumAdd } from 'firedum';

await firedumAdd({
	// a reference to a firestore collection - REQUIRED
	collectionReference: fs.collection('users'),
	fields: {
		// a lsit of fields to be added to the each document
		age: 21,
		firstName: '',
		zipCode: '',
		// NOTE that firedum uses faker.js for generating the mock data,
		// if you pass a key with a falsy value, e.g '', firedum will try generating
		// the value from what the key is, any faker.js function name can be passed as a key
		favoriteColor: ':color'
	},
	// number of items to be added to the collection - defaults to 1
	numberOfDocuments: 10,
	// if documents gets passed firedum will ignore 'numberOfDocuments' variable and only add the given documents
	documents: [
		{ job: 'Teacher', salary: '$1,022' },
		{ job: 'Lawyer', salary: '$1,841' },
		{ job: 'Cook', salary: '$1,197' }
	]
	// NOTE if fields gets passed along with documents all the fields will be added along side each doc,
	// any falsy value will be generated with faker
});

firedumUpdate

Updates every document in a collection

import { firedumUpdate } from 'firedum';

await firedumUpdate({
	// a reference to a firestore collection - REQUIRED
	collectionReference: fs.collection('users'),
	// a lsit of fields to be change to the document
	fields: {
		lastName: 'Baz', // changes the lastName property of each document to 'Baz'
		firstName: '', // will generate a random first name with faker
		age: 54 // changes the age property of each document to 54
		// NOTE if a document doesn't have a given field, firedum will add it
	}
});

firedumCreateUser

Adding new users via authentication with email and password

import firedum, { firedumCreateUser } from 'firedum';

// initialize your app so that firedum can access your the authentication to create new users
firedum(app);

await firedumCreateUser({
	// adds 10 new users
	amountOfUsers: 10, // defaults to 1
	// fields to be added to a users collections in firestore for each user that gets created
	fields: {
		// a lsit of fields to be added to the each document
		age: 21,
		firstName: '',
		zipCode: ''
		// NOTE that firedum uses faker.js for generating the mock data,
		// if you pass a key with a falsy value, e.g '', firedum will try generating
		// the value from what the key is, any faker.js function name can be passed as a key
	},
	// a firestore collection reference to add the user documents to
	// if this is not passed in it will default to the 'users' collection
	usersCollectionReference: fs.collection('users')
	// NOTE that all documents created will have the id of the user that it was created for
});

Nesting

If you would like to have documents with fields but also collections

The following code generates 5 documents in the users collection with a random first and last name. Then each of the of the newly documents gets a new collection called colors, the colors collection then gets 5 new documents with a single field, color

In total 25 documents was created

You can use this technic to nest how many collections you want, be carful tho as the number of document writes will drastically increase the more you nest

import { firedumAdd } from 'firedum';

await firedumAdd({
	collectionReference: fs.collection('users'),
	fields: {
		firstName: '',
		lastName: ''
	},
	numberOfDocuments: 5
}).then(async ({ ids, reference }) => {
	await Promise.all(
		ids.map(async (id) => {
			await firedumAdd({
				collectionReference: reference.doc(id).collection('colors'),
				fields: {
					color: ''
				},
				numberOfDocuments: 5
			});
		})
	);
});

// The exact same thing goes for using the firedumCreateUser function
await firedumCreateUser({
	amountOfUsers: 5,
	fields: {
		firstName: '',
		lastName: ''
	},
	collectionReference: fs.collection('users')
}).then(async ({ ids, reference }) => {
	await Promise.all(
		ids.map(async (id) => {
			await firedumAdd({
				collectionReference: reference.doc(id).collection('colors'),
				fields: {
					color: ''
				},
				numberOfDocuments: 5
			});
		})
	);
});