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

v0.4.0

Published

Parser for JSON based Firebase rules files

Downloads

11,880

Readme

firebase-json

Parser for Firebase rules JSON files.

It supersedes RFC 7159 with those additions:

  • support multi line ("/* [...] */") and single line ("// [...]") comments;
  • support multi line strings (without escaping the line feed);
  • disallow duplicate keys in objects;
  • and allow trailing commas in objects and array.

Example

To parse Firebase rules:

const json = require('firebase-json');
const fs = require('js');
const rules = json.parse(fs.readFileSync('./rules.json', 'utf8'));

console.log(rules);

Motivation

This is primarily used to load rules for targaryen test.

The alternatives are:

  • To strip the comment with strip-json-comments and to not use multi line string.
  • To write the rules in json5 and compile them before testing them in targaryen or upload them (json5 rules using multi line string won't be compatible with Firebase format).
  • To write the rules in Firebase's bolt and compile the rules before testing them with targaryen; for deployment, firebase-tools support bolt rules.

Those solutions might limit or disrupt your current work flow or deployment. Parsing the rule might also allow us later to map a rule syntax or evaluation error to a specific place in the JSON file similarly to Firebase simulator.

Installation

npm install firebase-json

API

  • parse(json: rules): any

    Parse the firebase-json encoded string.

  • load(filePath: string, options: void|string|object): Promise<any,Error>

    Read the file and parse its firebase-json encoded content.

  • loadSync(filePath: string, options: void|string|object): any

    Read the file synchronously and parse its firebase-json encoded content.

  • ast(json: rules): {type: string, expression: object, loc: object}

    Parse the firebase-json encoded string into an to intermediary AST. It uses the ESTree AST schema and returns an "ExpressionStatement" node.

Tests

git clone [email protected]:dinoboff/firebase-json.git
cd firebase-json
npm i
npm test

Contributors

Firebase-json is maintained by Damien Lebrun.

The parser is generated by David Majda's Pegjs. The firebase-json grammar definition is based on Pegjs JSON grammar example.

License

MIT License

Copyright (c) 2017 Damien Lebrun