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

firebase-extractions

v1.0.0

Published

Data extraction helpers for Firebase Realtime Database & Firestore.

Downloads

3

Readme

About

firebase-extractions is a small but useful Firebase library when dealing with Realtime Database and Firestore in a NodeJS environment and want the ability to quickly convert database results from the Realtime/Firestore classes to JavaScript arrays for generic use.

Installation

  1. npm install firebase-extractions
  2. Use any 3 of the Firebase extractions you would like by requiring them.

Extractions

documentSnapshotExtract(documentSnapshot, options)

Options

  • id (String) - Determines what the key of the document will be transformed into inside the document in the array. Defaults to id.

  • createTime (Boolean) - Determines if the Firestore-created createTime field is included in each of the documents in the array. Defaults to false.

  • updateTime (Boolean) - Determines if the Firestore-managed updateTime field is included in each of the documents in the array. Defaults to false.

Usage

const {documentSnapshotExtract} = require('firebase-extractions/firestore');

async function myFunction() {
  const documentSnapshot = await firebase.firestore().collection('starWarsCharacters').doc('8NTYBpwuIMqTOthjFQmo').get();
  const documentObject = documentSnapshotExtract(documentSnapshot);
  return documentObject;
}
// starWarsCharacters.8NTYBpwuIMqTOthjFQmo in Firestore contains:
{
  awesome: true,
  name: 'Han Solo'
}

// documentSnapshotExtract will return:
{
  awesome: true,
  name: 'Han Solo',
  id: '8NTYBpwuIMqTOthjFQmo'
}

querySnapshotToArray(querySnapshot, options)

Options

  • id (String) - Determines what the key of the document will be transformed into inside the document in the array. Defaults to id.

  • createTime (Boolean) - Determines if the Firestore-created createTime field is included in each of the documents in the array. Defaults to false.

  • updateTime (Boolean) - Determines if the Firestore-managed updateTime field is included in each of the documents in the array. Defaults to false.

Usage

const {querySnapshotToArray} = require('firebase-extractions/firestore');

async function myFunction() {
  const querySnapshot = await firebase.firestore().collection('starWarsCharacters').where('awesome', '==', true).get();
  const queryArray = querySnapshotToArray(querySnapshot);
  return queryArray;
}
// The starWarsCharacters collection in Firestore contains three documents:
  { awesome: true, name: 'Han Solo' }
  { name: 'Chewbacca', awesome: true }
  { awesome: true, name: 'Luke Skywalker' }

// querySnapshotToArray will return:
[
  { awesome: true, name: 'Han Solo', id: '8NTYBpwuIMqTOthjFQmo' },
  { name: 'Chewbacca', awesome: true, id: 'FE8WR6xpp1lOzFekIYUg' },
  { awesome: true, name: 'Luke Skywalker', id: 'WzOckx5xi1Ey4RyvidQN' }
]

dataSnapshotToArray(dataSnapshot, options)

Options

  • id (String) - Determines what the key of the document will be transformed into inside the document in the array. Defaults to id.

Usage

const {dataSnapshotToArray} = require('firebase-extractions/realtime');

async function myFunction() {
  const dataSnapshot = await firebase.database().ref('myRef').once('value');
  const dataArray = dataSnapshotToArray(dataSnapshot);
  return dataArray;
}
// myRef in Realtime Database contains:
{
  '0': { value: 0.5088880012102084 },
  '1': { value: 0.9535393149597968 },
  '2': { value: 0.4611710290005855 },
  '3': { value: 0.2894852393934524 },
  '4': { value: 0.8502272343304937 },
  '5': { value: 0.0933006449631725 },
  '6': { value: 0.9143575962510133 },
  '7': { value: 0.2773014226416699 },
  '8': { value: 0.3828858181135896 },
  '9': { value: 0.9859912263060917 },
  '10': { value: 0.913326366088267 }
}

// dataSnapshotToArray will return:
[
  { value: 0.5088880012102084, id: '0' },
  { value: 0.9535393149597968, id: '1' },
  { value: 0.4611710290005855, id: '2' },
  { value: 0.2894852393934524, id: '3' },
  { value: 0.8502272343304937, id: '4' },
  { value: 0.0933006449617925, id: '5' },
  { value: 0.9143575962510133, id: '6' },
  { value: 0.2773014226416699, id: '7' },
  { value: 0.3828858181135946, id: '8' },
  { value: 0.9859912263060917, id: '9' },
  { value: 0.9133263616088267, id: '10' }
]