New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

firebase-json

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

firebase-json

Parser for JSON based Firebase rules files

latest
Source
npmnpm
Version
0.4.0
Version published
Weekly downloads
3.2K
-8.87%
Maintainers
1
Weekly downloads
 
Created
Source

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 git@github.com: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

Keywords

firebase

FAQs

Package last updated on 25 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts