Giter Club home page Giter Club logo

unist-util-types's Introduction

unist-util-types

github release npm module type: esm license conventional commits typescript vitest yarn

unist utility types

Contents

What is this?

This package contains TypeScript definitions for working with unist and its ecosystem of utilities.

Install

This package is ESM only.

In Node.js (version 18+) with yarn:

yarn add @flex-development/unist-util-types
See Git - Protocols | Yarn  for details regarding installing from Git.

Use

import type {
  Ancestor,
  Children,
  Column,
  InclusiveDescendant,
  Index,
  Line,
  Match,
  MatchChildren,
  MatchInclusiveDescendant,
  MatchProperties,
  MatchValue,
  Offset,
  Parents,
  PositionalInfo,
  Test,
  TestFunction,
  Type,
  Value
} from '@flex-development/unist-util-types'

API

Ancestor<Tree, Child>

Collect nodes in Tree that can be ancestors of Child.

source: src/ancestor.ts

Children<T>

Extract children from tree T.

  • T (Node): tree to extract children from

source: src/children.ts

Column

Column in a source file (1-indexed integer).

source: src/column.ts

Decrement<[I]>

Subtract 1 from I while I is in the range [1, 10].

  • I (Uint): number to subtract from
    • default: 10

source: src/decrement.ts

InclusiveDescendant<Tree[, Max][, Depth]>

Collect all inclusive descendants of Tree.

  • Tree (Node): tree to collect descendants from
  • Max (Uint): maximum search depth
    • default: 10
  • Depth (Uint): current search depth
    • default: 0

source: src/descendant-inclusive.ts

Increment<[I]>

Add 1 to I while I is in the range [0, 9].

  • I (Uint): number to add to
    • default: 0

source: src/increment.ts

Index

Number of preceding siblings of a child node.

source: src/index-number.ts

IsAncestor<Tree, Child[, Max][, Depth]>

Check if Tree is an ancestor of Child.

  • Tree (Node): tree to check
  • Child (Node): expected child node
  • Max (Uint): maximum search depth
    • default: 10
  • Depth (Uint): current search depth
    • default: 0

source: src/is-ancestor.ts

IsParent<Tree, Child>

Check if Tree is the parent of Child.

source: src/is-parent.ts

Line

Line in a source file (1-indexed integer).

source: src/line.ts

Match<N, Check>

Check if node N passes a test.

  • N (Node): node to check
  • Check (Test): node test

source: src/match.ts

MatchChildren<N[, Check]>

Extract children from node N if it passes a test.

  • N (Node): node to check
  • Check (Test): node test

source: src/match-children.ts

MatchInclusiveDescendant<Tree, Check[, Max]>

Check if inclusive descendants of Tree pass a test.

  • Tree (Node): tree to check
  • Check (Test): node test
  • Max (Uint): maximum search depth
    • default: 10

source: src/src/match-descendant-inclusive.ts

MatchProperties<N[, Check]>

Extract properties of node N if it passes a test.

Properties of N are all fields except type.

  • N (Node): node to check
  • Check (Test): node test

source: src/match-properties.ts

MatchValue<N[, Check]>

Extract the value of node N if it passes a test.

  • N (Node): node to check
  • Check (Test): node test

source: src/match-value.ts

Offset

Index of a character in a source file (0-indexed integer).

source: src/offset.ts

Parents<Tree[, Child]>

Collect nodes in Tree that can be parents of Child.

All parents will be included in the resulting union if Child is any.

  • Tree (Node): tree to collect parents from
  • Child (Node): expected child node
    • default: any

source: src/parents.ts

PositionalInfo<[T]>

Object containing the positional information of tree T.

  • T (Node): tree to get positional information from

source: src/positional-info.ts

Test

Union of test types for a Node.

See unist-util-is for more details.

source: src/test.ts

TestFunction<[T][, P][, U]>

Check if a node passes a test.

fn(node[, index][, parent])

Parameters:

  • node (T): node to check
  • index (Index | undefined): index of node in parent.children
  • parent (Parent | undefined): parent of node

Returns:

boolean | undefined | void test result for node

source: src/test-function.ts

Type<[T]>

Extract type from tree T.

  • T (Node): tree to extract type from

source: src/type.ts

Uint

Number used for iteration.

Range: [0, 10]

source: src/uint.ts

Value<[T]>

Extract the value of tree T.

  • T (Node): tree to extract value from

source: src/value.ts

Contribute

See CONTRIBUTING.md.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

unist-util-types's People

Contributors

dependabot[bot] avatar unicornware avatar flex-development[bot] avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.