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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@atjson/peritext

v0.2.0

Published

Functions for building and transforming peritext documents

Downloads

921

Readme

@atjson/peritext

Functions for creating and manipulating peritext documents directly. The construction functions mark, block, and concat are useful for creating properly-nested documents of the sort that appear in XML-like structures. Peritext documents can of course in general have structures where marks overlap each other in arbitrary ways, but this library doesn't provide explicit means to do so.

A typical case of creating a document might look like

let doc = concat(
  block(Paragraph, { decorations: ["drop-cap"] }, "My introductory paragraph"),
  block(HorizontalRule, {}).set("selfClosing", true),
  block(Paragraph, {}, ["My", mark(Italic, {}, "fancy"), "body paragraph"])
);

PeritextBuilderStep

For convenience, several of the functions in this library (particularly block, mark, and slice) return a PeritextBuilderStep instead of just a regular peritext document. A PeritextBuilderStep is a peritext document, but when it's created it has an extra value attached to it representing the immediate product of the builder function. This value can be accessed with the getValue() method on the PeritextBuilderStep:

let paragraph: PeritextBuilderStep<Block>;

let doc = block(Div, {}, (paragraph = block(Paragraph, {}, "Hello!")));

return insertBefore(doc, paragraph.getValue().id, HorizontalRule, {});

Mutation

All of the functions that construct and modify documents have the property that they shallowly copy any peritext documents in their arguments, but directly mutate any blocks and marks on that document. This potentially-surprising behavior is intentional: this way, one can store the results of intermediate build steps and any such references to marks and blocks in the document will remain accurate after applying further build steps. documents are shallowly-copied in order for the behavior of functions like concat (which take multiple document objects and so could only mutate one of them anyway) to be consistent with the behavior of functions like groupChildren (which could in principle simply mutate the input document directly)