UNPKG

firebase-token-generator

Version:

A utility to generate signed Firebase Authentication Tokens

35 lines (30 loc) 1.07 kB
goog.provide('fb.tokengenerator.json'); goog.require('goog.json'); /** * Evaluates a JSON string into a javascript object. * * @param {string} str A string containing JSON. * @return {*} The javascript object representing the specified JSON. */ fb.tokengenerator.json.parse = function(str) { if (typeof JSON !== 'undefined' && goog.isDef(JSON.parse)) { return JSON.parse(str); } else { // NOTE: We could just use eval(), since this case is so rare and the strings we parse are always pretty safe // (generated by the server or the developer). But goog.json.parse is only a few lines of code, so not // bothering for now. return goog.json.parse(str); } }; /** * Returns JSON representing a javascript object. * @param {Object} data Javascript object to be stringified. * @return {string} The JSON contents of the object. */ fb.tokengenerator.json.stringify = function(data) { if (typeof JSON !== 'undefined' && goog.isDef(JSON.stringify)) { return JSON.stringify(data); } else { return goog.json.serialize(data); } };