formatter

package
v0.4.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2023 License: MIT Imports: 1 Imported by: 0

README

Formatter

formatter 包用于实现对代码的生成及格式化。在本项目中用于前端的代码生成。

本包的设计参考 prettier 实现,提供 indent / join / line 等工具方法。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(doc Doc, options *Options) string

Types

type Doc

type Doc interface {
	// contains filtered or unexported methods
}

func If

func If(condition bool, doc Doc) Doc

type DocContent

type DocContent string

func NewDocContent

func NewDocContent(code string) *DocContent

type DocGroup

type DocGroup struct {
	Docs []Doc
}

func Content

func Content(contents ...interface{}) *DocGroup

func Group

func Group(docs ...Doc) *DocGroup

func Join

func Join(sep Doc, docs ...Doc) *DocGroup

type DocNode

type DocNode struct {
	Type  DocNodeType
	Child Doc
}

func Indent

func Indent(doc Doc) *DocNode

func LineBreak

func LineBreak() *DocNode

type DocNodeType

type DocNodeType string
const (
	DocNodeIndent    DocNodeType = "string"
	DocNodeLineBreak DocNodeType = "linebreak"
)

type Formatter

type Formatter struct {
	// contains filtered or unexported fields
}

func NewFormatter

func NewFormatter(options *Options) *Formatter

func (*Formatter) Format

func (f *Formatter) Format(doc Doc) string

type Options

type Options struct {
	IndentWidth int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL