transform

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuiltinTransformers = map[string]Transformer{
	"lowercase":      Lowercase,
	"uppercase":      Uppercase,
	"capitalize":     Capitalize,
	"title":          TitleCase,
	"trim":           Trim,
	"no-punctuation": RemovePunctuation,
	"no-whitespace":  RemoveWhitespace,
}
View Source
var MarkdownListPattern = regexp.MustCompile(`\s*(?:[-*+]|\d+[.)])\s+`)

MarkdownListPattern matches markdown list markers: - Unordered: -, *, + - Ordered: 1., 2., 1), 2), etc. The pattern splits on the marker, leaving the content after each marker.

View Source
var TimeTagPattern = regexp.MustCompile(`<time\s+startYear="(\d+)"(?:\s+startMonth="(\d+)")?(?:\s+startDay="(\d+)")?[^>]*>[^<]*</time>`)

TimeTagPattern matches Workflowy time tags.

Functions

func ApplyGroupResults added in v0.8.1

func ApplyGroupResults(ctx context.Context, client GroupApplier, results []GroupResult, granularity string) error

ApplyGroupResults applies the grouping by creating headers and moving items.

func ApplyResults

func ApplyResults(ctx context.Context, client Applier, results []Result)

func ApplyResultsWithOptions

func ApplyResultsWithOptions(ctx context.Context, client Applier, results []Result, asChild bool)

func ApplySplitResults

func ApplySplitResults(ctx context.Context, client Applier, results []SplitResult)

func BuildUpdateRequest

func BuildUpdateRequest(result *Result) *workflowy.UpdateNodeRequest

func Capitalize

func Capitalize(s string) (string, error)

func CollectSplits

func CollectSplits(items []*workflowy.Item, separator string, field Field, skipEmpty bool, depth int, maxDepth int, results *[]SplitResult)

func CollectSplitsRegex added in v0.8.1

func CollectSplitsRegex(items []*workflowy.Item, pattern *regexp.Regexp, field Field, skipEmpty bool, depth int, maxDepth int, results *[]SplitResult)

func CollectTransformations

func CollectTransformations(items []*workflowy.Item, opts Options, depth int, results *[]Result)

func DateKeyFromTimeTag added in v0.8.1

func DateKeyFromTimeTag(name, granularity string) (string, bool)

DateKeyFromTimeTag extracts a date key from a time tag based on granularity.

func ExtractDateFromTimeTag added in v0.8.1

func ExtractDateFromTimeTag(name string) (year, month, day int, found bool)

ExtractDateFromTimeTag extracts year, month, day from a time tag.

func GenerateTimeTag added in v0.8.1

func GenerateTimeTag(t time.Time, granularity string) string

GenerateTimeTag creates a Workflowy time tag for a given date and granularity.

func ListBuiltins

func ListBuiltins() []string

func Lowercase

func Lowercase(s string) (string, error)

func ParseGroupBy added in v0.8.1

func ParseGroupBy(value string) (field, format, granularity string, err error)

ParseGroupBy parses a --by value into GroupOptions fields.

func ParseOrder added in v0.8.1

func ParseOrder(value, field string) (ascending bool, err error)

ParseOrder parses a --order value.

func RemovePunctuation

func RemovePunctuation(s string) (string, error)

func RemoveWhitespace

func RemoveWhitespace(s string) (string, error)

func Split

func Split(text, separator string, skipEmpty bool) []string

func SplitRegex added in v0.8.1

func SplitRegex(text string, pattern *regexp.Regexp, skipEmpty bool) []string

func TitleCase

func TitleCase(s string) (string, error)

func Trim

func Trim(s string) (string, error)

func UnescapeSeparator

func UnescapeSeparator(s string) string

func Uppercase

func Uppercase(s string) (string, error)

Types

type Applier

type Applier interface {
	UpdateNode(ctx context.Context, itemID string, req *workflowy.UpdateNodeRequest) (*workflowy.UpdateNodeResponse, error)
	CreateNode(ctx context.Context, req *workflowy.CreateNodeRequest) (*workflowy.CreateNodeResponse, error)
}

type DateGroup added in v0.8.1

type DateGroup struct {
	DateKey        string        `json:"date_key"`
	TimeTag        string        `json:"time_tag"`
	HeaderID       string        `json:"header_id,omitempty"`
	ExistingHeader bool          `json:"existing_header"`
	Items          []GroupedItem `json:"items"`
	CreatedID      string        `json:"created_id,omitempty"`
}

DateGroup represents a group of items under a date header.

func (DateGroup) String added in v0.8.1

func (g DateGroup) String() string

type Field

type Field int
const (
	FieldName Field = 1 << iota
	FieldNote
)

func DetermineFields

func DetermineFields(name, note bool) Field

type GroupApplier added in v0.8.1

type GroupApplier interface {
	Applier
	MoveNode(ctx context.Context, itemID string, req *workflowy.MoveNodeRequest) (*workflowy.MoveNodeResponse, error)
}

GroupApplier extends Applier with MoveNode for group operations.

type GroupOptions added in v0.8.1

type GroupOptions struct {
	Field       string // "created" or "modified"
	Format      string // Go time format string for grouping
	Granularity string // "year", "month", "day", or custom
	Ascending   bool   // Sort order (false = newest first)
	DryRun      bool
}

GroupOptions configures the group transform.

type GroupResult added in v0.8.1

type GroupResult struct {
	ParentID    string        `json:"parent_id"`
	ParentURL   string        `json:"parent_url"`
	Groups      []DateGroup   `json:"groups"`
	Applied     bool          `json:"applied"`
	NoDateItems []GroupedItem `json:"no_date_items,omitempty"`
}

GroupResult represents the result of grouping children.

func CollectGroupResults added in v0.8.1

func CollectGroupResults(items []*workflowy.Item, opts GroupOptions) []GroupResult

CollectGroupResults groups children of the given items by date.

func (GroupResult) String added in v0.8.1

func (r GroupResult) String() string

type GroupedItem added in v0.8.1

type GroupedItem struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	URL       string `json:"url"`
	Timestamp int64  `json:"timestamp"`
	DateKey   string `json:"date_key"`
}

GroupedItem represents an item that will be grouped.

type Options

type Options struct {
	Transformer Transformer
	Fields      Field
	DryRun      bool
	Interactive bool
	Depth       int
	AsChild     bool
}

type Result

type Result struct {
	Item       *workflowy.Item `json:"-"`
	ID         string          `json:"id"`
	URL        string          `json:"url"`
	Field      string          `json:"field"`
	Original   string          `json:"original"`
	New        string          `json:"new"`
	Applied    bool            `json:"applied"`
	Skipped    bool            `json:"skipped,omitempty"`
	SkipReason string          `json:"skip_reason,omitempty"`
	Error      error           `json:"error,omitempty"`
	CreatedID  string          `json:"created_id,omitempty"`
}

func (Result) String

func (r Result) String() string

type SplitResult

type SplitResult struct {
	ParentID   string   `json:"parent_id"`
	ParentURL  string   `json:"parent_url"`
	Original   string   `json:"original"`
	Parts      []string `json:"parts"`
	CreatedIDs []string `json:"created_ids,omitempty"`
	Applied    bool     `json:"applied"`
	Skipped    bool     `json:"skipped,omitempty"`
	SkipReason string   `json:"skip_reason,omitempty"`
}

func (SplitResult) String

func (r SplitResult) String() string

type Transformer

type Transformer func(string) (string, error)

func ResolveTransformer

func ResolveTransformer(transformName, execCmd string) (Transformer, error)

func ShellTransformer

func ShellTransformer(cmdTemplate string) Transformer

Jump to

Keyboard shortcuts

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