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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@stratware/swrules

v0.1.1

Published

Firebase security rules generator and validator for people by Stratware

Readme

firerules

Purpose

firerules is a small JavaScript builder for generating Firebase Firestore security rules programmatically. It lets you define rules in a structured way and emits a valid Firestore rules file as a string.


How it works

Call the exported firerules function with a define callback. The callback receives an object containing match and helpers, which you use to declare match blocks and allow rules.

firerules returns an object with a build() method that produces the complete Firestore rules text.


Minimal usage

import { firerules } from './index.js';

const rules = firerules(({ match, helpers }) => {
  match('/posts/{postId}', ({ allow }) => {
    allow('read').when(helpers.authenticated);
    allow(['create', 'update']).when(helpers.owner('ownerId'));
  });
});

console.log(rules.build());

API summary

  • firerules(define) Main entry point. Calls define with { match, helpers }.

  • match(path, buildCallback) Declares a Firestore match block. path must follow the builder’s Firestore-style pattern (leading slash, path segments with alphanumerics, underscores, hyphens, and {vars}). buildCallback receives an object exposing allow.

  • allow(ops) Declares an allow rule inside a match block. ops may be a single operation or an array of operations. Chain .when(condition), .if(condition), or .then(condition) to attach the rule condition. These methods are aliases with identical behavior.

  • helpers A collection of predefined helper expressions that can be passed to .when(), .if(), or .then().

  • build() Returns the final Firestore rules string, including:

    • rules_version
    • service cloud.firestore
    • Generated helper functions
    • All declared match blocks and rules

Built-in helpers

  • Authentication and identity authenticated, uid, admin, denyAll

  • Operation state creating, updating, deleting

  • Ownership owner(field), ownerOnCreate(field)

  • Field immutability and change control immutable(fields[]), changedOnly(fields[]), unchanged(fields[])

  • Field presence constraints fieldsOnly(fields[]), fieldsAtLeast(fields[])

  • Size limits maxArray(field, size), maxString(field, size)

  • Composition and utilities pathVarEquals(varName, expr), and(...), or(...), not(cond)


Important details

  • Valid operations are: read, get, list, create, update, delete, write. The write operation expands to create, update, and delete.

  • Helper expressions are de-duplicated. Identical expressions are emitted once as generated Firestore functions:

    function f_xxx() { return <expr>; }
  • The builder logs warnings when:

    • A very large number of match blocks is produced
    • The generated rules text exceeds approximately 200 KB