GithubHelp home page GithubHelp logo

flex-development / esast-util-builder Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 2.31 MB

esast utility to build trees

Home Page: https://github.com/flex-development/esast-util-builder

License: BSD 3-Clause "New" or "Revised" License

TypeScript 21.30% Shell 1.66% JavaScript 76.31% Ruby 0.73%
ast builder esast syntax syntax-tree tree unist unist-util util

esast-util-builder's Introduction

esast-util-builder

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

esast utility to build trees

Contents

What is this?

This is a tiny but useful utility for building esast nodes.

When should I use this?

Use this package when you need to create esast nodes.

If you need to build nodes for other ASTs, use unist-util-builder instead.

Install

This package is ESM only.

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

yarn add @flex-development/esast-util-builder
See Git - Protocols | Yarn Β for details regarding installing from Git.

In Deno with esm.sh:

import { u } from 'https://esm.sh/@flex-development/esast-util-builder'

In browsers with esm.sh:

<script type="module">
  import { u } from 'https://esm.sh/@flex-development/esast-util-builder'
</script>

Use

TODO: use

API

This package exports the identifier u. There is no default export.

u(type[, builder])

Build an esast node using a child node array, properties object, or value.

If builder is omitted, a void node (a node with only a type field) will be created.

πŸ‘‰ Undefined literals must be created using a properties object, rather than a value. Passing undefined will create a void node.

Type Parameters

  • T (Type<AnyNode>) - esast node type
Parameters
  • type (T) - esast node type
  • builder (Builder<T>, optional) - node children, properties, or value
Returns

Match<AnyNode, T> new esast node.

AnyNode

Union of nodes that can occur in esast (TypeScript type).

πŸ‘‰ This type is exported from @flex-development/esast.
See AnyNode for more details.

Builder<[T]>

Construct a union of esast node builders (TypeScript type).

See also: ub.AnyBuilder, ub.Builder

type Builder<T extends Type = Type<AnyNode>> = T extends Type<AnyNode>
  ? ub.Builder<Match<AnyNode, T>> extends infer B extends ub.AnyBuilder
    ? B extends ub.BuilderValue
      ? B
      : B extends readonly Node[]
        ? B[number][]
        : {
            [K in keyof B]: K extends 'children'
              ? B[K] extends infer U extends readonly Node[]
                ? U[number][]
                : never
              : B[K]
          }
    : never
  : never

Match<N, Check>

Check if node N passes a test. (TypeScript type).

πŸ‘‰ This type is exported from @flex-development/unist-util-types.
See Match<N, Check> for more details.

Type<[T]>

Extract type from node T (TypeScript type).

πŸ‘‰ This type is exported from @flex-development/unist-util-types.
See Type<[T]> for more details.

Types

This package is fully typed with TypeScript.

Related

  • esast β€” ecmascript abstract syntax tree format

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.

esast-util-builder's People

Contributors

dependabot[bot] avatar unicornware avatar

Watchers

Lucian 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.