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-path

v1.0.0

Published

A tool to help you model your schema and provide a navigatable tree rather than magic strings everywhere.

Downloads

53

Readme

firebase-path helps you get rid of magic strings when addresing nodes of your database.

You supply firebase-path with a JSON model of your document structure and then you can use a JSON path like API to create the compound paths you need to interact with the firebase API.

Quick Overview

The Firebase API takes a path built of node names separated by slashes. Take the following database for example:

crackling-fire-1555  
 |-- books
     |-- -KNoPkHeKNH4M2vogoWG
     |   |-- author: "Wells, H.G." 
     |   |-- title: "The Time Machine" 
     |
     |-- -KNwSOCCgPxnJr_lfdPR
     |   |-- author: "Azimov, Isaac"
     |   |-- title: "Caves of Steel"
     |
     |-- -KNwrrfKCZQU2z303jsj
         |-- author: "Verne, Jules"
         |-- title: "Mysterious Island"

It is made up of both well defined nodes and some that were created with the Firebase push API. To create a reference to the book by Jules Verne you would need this path "books/-KNwrrfKCZQU2z303jsj" There are multiple ways to construct a path using constants, but all seemed lacking.

firebase-path lets you define a simple json schema

const schema = {
                    books: {
                        '<bookId>': {
                            author: {},
                            title: {}
                        }
                    }
                }

And convert that to an object tree

const children = firebasePath.fromJson(schema)

Using that tree, you can request a path

const authorPath = children
                    .books
                    .bookId('-KNwrrfKCZQU2z303jsj')
                    .author
                    .path()
// 'books/-KNwrrfKCZQU2z303jsj/author'
const ref = firebase.database().ref(authorPath)

Types of children

There are two types of children in the object tree; named and template. A named child is created when the name of the document key is designed ahead of time. In our example the named children are books, author, and title.

A template child is created where you don't know what the key name in the database will be until after the the completion of calling firebase's push operation. In other words you can't know the key name until after the data has been added to firebase. You specify a template node by wrapping a meaningful name in less than and greater than symbols. In our example bookId is the only template node.

API

Each node has the following properties:

key the name of the current child within the path.

path a function that returns a full path string needed to interact with the firebase API.

There are also three static API functions:

isRoot a function that returns true if the object passed to it is the root of the firebase-path object tree. In our example isRoot would return true when it is pased the children variable.

isChild a function that returns true if the object passed to it is a decendent of the root element.

isPath a function that returns true if theh object passed is either a root or a child element.

These API will be useful if you are building tools that expect a path element to be passed to it.