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

unist-util-add

v1.2.0

Published

unist utility to add extension

Downloads

20

Readme

This document is created by ChatGPT.

unist-util-add

unist-util-add is a utility for enhancing the unist ecosystem by providing an easy way to add extensions for toMarkdown, micromark, and fromMarkdown to unified data objects. It simplifies working with markdown processing libraries like remark and micromark by offering a straightforward API to add plugins.

Installation

You can install unist-util-add using npm or yarn:

npm install unist-util-add

yarn add unist-util-add

pnpm add unist-util-add

Usage

Here's how you can use the add function provided by unist-util-add to augment your unist data with extensions:

import { add } from 'unist-util-add'
import type { Data } from 'unified'
import type { Options as ToMarkdownExtension } from 'mdast-util-to-markdown'
import type { Extension as MicromarkExtension } from 'micromark-util-types'
import type { Extension as FromMarkdownExtension } from 'mdast-util-from-markdown'

// Example data object
const data: Data = {}

// Example extensions
const toMarkdownExt: ToMarkdownExtension = {/* your toMarkdown extension */}
const micromarkExt: MicromarkExtension = {/* your micromark extension */}
const fromMarkdownExt: FromMarkdownExtension = {/* your fromMarkdown extension */}

// Add extensions to data
add(data, 'toMarkdownExtensions', toMarkdownExt)
add(data, 'micromarkExtensions', micromarkExt)
add(data, 'fromMarkdownExtensions', fromMarkdownExt)

API

add(data: Data, field: string, value: Extension): void

The add function allows you to add extensions to a unist data object.

Parameters

  • data: The unist data object where the extension should be added.
  • field: A string representing the field name, which can be one of 'toMarkdownExtensions', 'micromarkExtensions', or 'fromMarkdownExtensions'.
  • value: The extension to add, which can be a ToMarkdownExtension, MicromarkExtension, FromMarkdownExtension, or an array of FromMarkdownExtension.

Supported Fields

  • toMarkdownExtensions: Extensions that modify the markdown-to-markdown transformation process.
  • micromarkExtensions: Extensions that modify the micromark parsing process.
  • fromMarkdownExtensions: Extensions that modify the markdown-to-unist tree transformation process.

How It Works

The add function checks if the provided field already exists in the data object. If it does, it pushes the new value onto the existing array. If the field does not exist, it creates a new array with the value as its first item.

For the fromMarkdownExtensions, if an array of extensions is provided, it appends the entire array to the existing list of extensions.

Why Use unist-util-add?

  • Simplifies Plugin Management: Easily manage extensions by providing a unified API for different types of extensions.
  • Improves Readability: Makes your codebase cleaner by reducing the boilerplate required to manage unist data fields.
  • Flexible: Supports adding multiple types of extensions in a consistent manner.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on the GitHub repository.

License

unist-util-add is licensed under the MIT License. See the LICENSE file for more information.