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

rspamd-shiki-grammars

v0.2.0

Published

Shiki syntax highlighting grammars for Rspamd map formats

Readme

rspamd-shiki-grammars

Shiki syntax highlighting grammars for Rspamd map file formats.

Grammars

| Language name | Format | |---|---| | rspamd-map | Plain and key-value maps | | rspamd-radix-map | IP/network (radix) maps | | rspamd-regexp-map | Regular expression maps | | rspamd-sa-rules | SpamAssassin-style rule files | | rspamd-composites | Composite symbol definitions |

Installation

npm install rspamd-shiki-grammars

Requires shiki >= 1.0 as a peer dependency.

Usage

Register all grammars at once

import { createHighlighter } from 'shiki'
import { rspamdGrammars } from 'rspamd-shiki-grammars'

const hl = await createHighlighter({
  langs: rspamdGrammars,
  themes: ['github-dark'],
})

const html = hl.codeToHtml(mapContent, {
  lang: 'rspamd-sa-rules',
  theme: 'github-dark',
})

Register individual grammars

import { createHighlighter } from 'shiki'
import {
  rspamdMapGrammar,
  rspamdRadixMapGrammar,
  rspamdRegexpMapGrammar,
  rspamdSaRulesGrammar,
} from 'rspamd-shiki-grammars'

const hl = await createHighlighter({
  langs: [rspamdMapGrammar, rspamdRadixMapGrammar],
  themes: ['nord'],
})

With @shikijs/react (or any Shiki-based React library)

import { codeToHtml } from 'shiki'
import { rspamdGrammars } from 'rspamd-shiki-grammars'

export async function MapViewer({ code }: { code: string }) {
  const html = await codeToHtml(code, {
    lang: 'rspamd-map',
    theme: 'github-light',
    langs: rspamdGrammars,
  })
  return <div dangerouslySetInnerHTML={{ __html: html }} />
}

Map format overview

rspamd-map — plain and key-value maps

Lines are either a bare key, a key value pair, or a comment. Quoted keys ("key with spaces") are supported.

# blocklist
spammer.example.com
"quoted domain.com"
trusted.host   allowlisted

rspamd-radix-map — IP/network maps

Keys are IPv4 or IPv6 addresses and CIDR prefixes. Multiple addresses per line can be comma-separated.

# local networks
10.0.0.0/8
192.168.0.0/16,172.16.0.0/12   internal
2001:db8::/32
[::1]           loopback

rspamd-regexp-map — regular expression maps

Keys are PCRE patterns in any of the forms Rspamd accepts. An optional value follows the pattern.

# Rspamd regexp map
/\bviagra\b/i          drug_spam
/\bclick\s+here\b/iu   clickhere
m{https?://bit\.ly}    shortlink
m!paypal\.com\.ru!i    phishing

Supported pattern flags: i m s x u r O L

rspamd-sa-rules — SpamAssassin-style rules

Supports all directives understood by Rspamd's multimap SA rules parser.

# Drug spam detection
header  DRUG_SUBJ  Subject  =~ /\b(viagra|cialis|levitra)\b/i
rawbody DRUG_BODY  /\b(buy now|order online)\b/i
uri     DRUG_URI   /pills?\.com/i

selector FROM_RU  from.addr  =~ /\.ru$/i

meta     DRUG_COMBO  DRUG_SUBJ && (DRUG_BODY || DRUG_URI)
score    DRUG_COMBO  5.0
describe DRUG_COMBO  Multiple drug spam signals

Directives:

| Directive | Syntax | |---|---| | header | header ATOM Header-Name =~ /pattern/flags | | body | body ATOM /pattern/flags | | rawbody | rawbody ATOM /pattern/flags | | uri | uri ATOM /pattern/flags | | full | full ATOM /pattern/flags | | selector | selector ATOM pipeline =~ /pattern/flags | | meta | meta ATOM expr — boolean/arithmetic over atom names | | score | score ATOM value | | describe | describe ATOM text |

rspamd-composites — composite symbol definitions

UCL-style blocks (as used in local.d/composites.conf) defining composite symbols. The expression value is highlighted as the composite expression language: boolean operators, removal-policy prefixes, group references, and symbol options.

# Combine related signals
PHISHING_COMBO {
    expression = "PHISHING & (SUSPICIOUS_URL | REDIRECTOR_URL)";
    score = 8.0;
}

WHITELIST_SENDER {
    expression = "-FORGED_SENDER & g+:fuzzy & DMARC_POLICY_REJECT[sp]";
    score = -10.0;
    policy = "leave";
    enabled = true;
}

Expression language elements:

| Element | Syntax | |---|---| | Boolean operators | & \| !, or and or not (any case) | | Grouping | ( ... ) | | Removal-policy prefix | ~SYMBOL (keep weight), -SYMBOL (keep both), ^SYMBOL (force remove) | | Group reference | g:name, g+:name, g-:name | | Symbol options | SYMBOL[opt1,opt2], SYMBOL[/regex/i, opt] |

Block properties: expression, score, group, policy, enabled, description.

Development

npm run build      # compile to dist/
npm test           # run 114 Vitest unit tests
npm run test:watch # watch mode

Tests assert TextMate scope names directly via Shiki's includeExplanation API, so grammar regressions are caught at the token level.

License

Apache 2.0 — see LICENSE.