GartorwareCorp / firebase-util

An experimental toolset for Firebase
http://firebase.github.io/firebase-util
MIT License
8 stars 9 forks source link

Firebase-util

Build Status Coverage Status Version

This is a collection of power toys (mostly experimental) and utilities for use in Firebase.

Updated to Firebase SDK v3.0.x

Firebase SDK has been updated to v3.x so several steps need to be taken in order to work with new API. Migration guide is avalaible in: https://firebase.google.com/support/guides/firebase-web

Once the migration steps have been taken, we need to make some changes in our previous firebase v2 code in order to have firebase-util working again. As surely you have realized, most significant changes are:

So what is different with firebase-util?

Collaterally, the way we get a firebase reference. The way we get some objects like .key, .parent, .ref, that are now read-only properties instead of functions. And the lower case firebase namespace, of course!

So basically, now we get a reference like this:

var fb = firebase.database().ref();

Then we use firebase-util like this (note once again the lower case firebase):

var norm = new firebase.util.NormalizedCollection(
   fb.child('login'),
   fb.child('profile')
);
var scrollRef = new firebase.util.Scroll(fb, 'number');
var emailKey = firebase.util.escapeEmail( anEmailAddress );

Finally we retrieve some of the properties like this (without the ()):

var ref = norm.ref;
var key = snapshot.key;

The Tools

Setup

In the browser

With Bower: bower install firebase-util

From the CDN: https://cdn.firebase.com/libs/firebase-util/x.x.x/firebase-util.min.js

<script>
   // off the global Firebase.util namespace
   var emailKey = firebase.util.escapeEmail( anEmailAddress );

   // or in your browserify packages
   //var fbutil = require('firebase-util');
</script>

In Node

var fbutil = require('./firebase-util.js');
var emailKey = fbutil.escapeEmail( anEmailAddress );

Global Utilities

Firebase.util.logLevel(int)

Log debugging info to JavaScript console (or command line in node.js). Defaults to 'warn' (errors and warnings). This can be set or changed at any time to any of the following:

firebase.util.logLevel(true);  // default logging (also accepts 'all' or 'on')
firebase.util.logLevel(false); // all logging off (also accepts 0, 'off' or 'none')
firebase.util.logLevel('error'); // error, warn, info, log, or debug

Debugging can also be enabled in the browser by adding debugLevel=x into the url's query parameters. This allows one to turn on debugging for quick troubleshooting without having to modify any code.

The logLevel() method returns a revert function that can be used to restore the logging level to it's previous value:

// log a whole lotta junk
var revert = firebase.util.logLevel('debug');

// ...run some code...

// revert to default logging
revert();

You can also filter log output with a RegExp:

// only print logs that begin with "Path"
firebase.util.logLevel('debug', /^Path/);

Contributing

See CONTRIBUTING.md

LICENSE

See MIT LICENSE