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

@matrix-widget-toolkit/events

v1.0.0

Published

Matrix event types and helpers without widget dependencies

Readme

@matrix-widget-toolkit/events

@matrix-widget-toolkit/events

This package provides Matrix helpers without widget dependencies.

They can be used in widgets but also in other types of projects, like bots or backend services. For now, the package includes:

  • Helper functions to calculate power levels, including the room creator rules of room version 12 (MSC4289).
  • Types and validators for common Matrix events (m.room.create, m.room.power_levels, m.room.member, m.room.redaction).
  • Helpers for event relations and edits (m.relates_to, m.new_content).
  • Helpers to compute room member display names and to sort events by origin_server_ts.

The helpers are also re-exported by @matrix-widget-toolkit/api, so widgets don't need to depend on this package directly.

Usage

Install it with:

yarn add @matrix-widget-toolkit/events

Check power levels

All helpers take the content of the room's m.room.power_levels event and its m.room.create event.

The examples below use this room:

import type {
  PowerLevelsStateEvent,
  StateEvent,
  StateEventCreateContent,
} from '@matrix-widget-toolkit/events';

const alice = '@alice:example.com';
const bob = '@bob:example.com';
const carol = '@carol:example.com';

const createEvent: StateEvent<StateEventCreateContent> = {
  type: 'm.room.create',
  sender: alice,
  state_key: '',
  event_id: '$create-event-id',
  room_id: '!room-id:example.com',
  origin_server_ts: 0,
  content: { room_version: '12' },
};

const powerLevels: PowerLevelsStateEvent = {
  users: { [bob]: 100 },
  users_default: 0,
  events_default: 0,
  state_default: 50,
  events: { 'm.reaction': 10 },
  kick: 50,
};

hasStateEventPower

Checks if a user can send a state event. It uses the level from events, or state_default (50 if missing).

import { hasStateEventPower } from '@matrix-widget-toolkit/events';

hasStateEventPower(powerLevels, createEvent, bob, 'm.room.topic'); // true
hasStateEventPower(powerLevels, createEvent, carol, 'm.room.topic'); // false

hasRoomEventPower

Checks if a user can send a room event. It uses the level from events, or events_default (0 if missing).

import { hasRoomEventPower } from '@matrix-widget-toolkit/events';

hasRoomEventPower(powerLevels, createEvent, carol, 'm.room.message'); // true
hasRoomEventPower(powerLevels, createEvent, carol, 'm.reaction'); // false
hasRoomEventPower(powerLevels, createEvent, bob, 'm.reaction'); // true

hasActionPower

Checks if a user can perform one of the actions invite, kick, ban, or redact.

import { hasActionPower } from '@matrix-widget-toolkit/events';

hasActionPower(powerLevels, createEvent, bob, 'kick'); // true
hasActionPower(powerLevels, createEvent, carol, 'kick'); // false

calculateUserPowerLevel and ROOM_VERSION_12_CREATOR

Returns the power level of a user. The room creators of room version 12 have a higher power level than any number, so the function returns the ROOM_VERSION_12_CREATOR constant for them instead of a number.

import {
  ROOM_VERSION_12_CREATOR,
  calculateUserPowerLevel,
} from '@matrix-widget-toolkit/events';

calculateUserPowerLevel(powerLevels, createEvent, alice); // ROOM_VERSION_12_CREATOR
calculateUserPowerLevel(powerLevels, createEvent, bob); // 100
calculateUserPowerLevel(powerLevels, createEvent, carol); // 0, from users_default

const level = calculateUserPowerLevel(powerLevels, createEvent, alice);
if (level === ROOM_VERSION_12_CREATOR) {
  // Alice is a room creator
}

compareUserPowerLevelToNormalPowerLevel

Compares a power level returned by calculateUserPowerLevel with a required power level. Use it instead of >=, because it also handles ROOM_VERSION_12_CREATOR.

import {
  ROOM_VERSION_12_CREATOR,
  compareUserPowerLevelToNormalPowerLevel,
} from '@matrix-widget-toolkit/events';

compareUserPowerLevelToNormalPowerLevel(100, 150); // false
compareUserPowerLevelToNormalPowerLevel(ROOM_VERSION_12_CREATOR, 150); // true