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

@type-editor/util

v0.0.3

Published

Type Editor - Utilities Module

Readme

@type-editor/util

Utility functions for traversing and searching the document tree in Type Editor.

Installation

npm install @type-editor/util
# or
pnpm add @type-editor/util

Overview

This package provides utility functions for navigating and querying the document tree structure. It offers tools for finding parent nodes based on predicates or node types, which is essential for building editor commands and extensions.

API

Functions

findParent(selection, predicate)

Finds the nearest ancestor node in the document tree that satisfies the given predicate.

Parameters:

  • selection - The current editor selection to search from
  • predicate - A callback function that tests each ancestor node

Returns: FindParentResult | null

import { findParent } from '@type-editor/util';

// Find the nearest list item ancestor
const listItem = findParent(selection, node => node.type.name === 'list_item');

if (listItem) {
  console.log('Found list item at position:', listItem.position.pos);
}

findParentByType(selection, nodeType)

Finds the nearest ancestor node of a specific type. A convenience wrapper around findParent.

Parameters:

  • selection - The current editor selection to search from
  • nodeType - The node type to search for

Returns: FindParentResult | null

import { findParentByType } from '@type-editor/util';

// Find the nearest paragraph ancestor
const paragraph = findParentByType(selection, schema.nodes.paragraph);

findCommonParent(selection)

Finds the deepest common ancestor node that contains both ends of the selection.

Parameters:

  • selection - The current editor selection

Returns: FindParentResult | null

import { findCommonParent } from '@type-editor/util';

// Get the container of the current selection
const container = findCommonParent(selection);
if (container) {
  console.log('Selection is within:', container.node.type.name);
}

isInNodeType(state, nodeType, attrs?)

Checks if the current selection is within a node of the specified type, optionally matching specific attributes.

Parameters:

  • state - The current editor state
  • nodeType - The node type to check for
  • attrs (optional) - Attributes to match against

Returns: boolean

import { isInNodeType } from '@type-editor/util';

// Check if cursor is inside a heading
const inHeading = isInNodeType(state, schema.nodes.heading);

// Check if cursor is inside a level 2 heading
const inH2 = isInNodeType(state, schema.nodes.heading, { level: 2 });

Types

FindParentResult

Result of a parent node search operation.

interface FindParentResult {
  /** The resolved position of the found parent node. */
  position: ResolvedPos;
  /** The parent node that was found. */
  node: PmNode;
}

FindCallbackFunction

A callback function used to find nodes in the document tree.

type FindCallbackFunction = (node: PmNode) => boolean;

Dependencies

Peer Dependencies

  • @type-editor/model - Document model types and utilities

License

MIT