From b2bed26be5745c2fd91b808b2527369fadf3c28c Mon Sep 17 00:00:00 2001 From: "exe.dev user" Date: Sun, 3 May 2026 22:11:04 +0000 Subject: [PATCH] Add Lines: Sort A-Z, Sort Z-A, and Unique processors Co-authored-by: Shelley --- textfilters.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/textfilters.go b/textfilters.go index 16e5a72..cfaabaf 100644 --- a/textfilters.go +++ b/textfilters.go @@ -8,6 +8,7 @@ import ( "errors" "fmt" "regexp" + "sort" "strconv" "strings" @@ -280,6 +281,41 @@ var TextFilters = map[string]TextProcessor{ }, }, + "sort-lines-asc": { + Label: "Lines: Sort A-Z", + Filter: func(ctx context.Context, input string) (resp TextFilterResponse, err error) { + lines := strings.Split(input, "\n") + sort.Strings(lines) + return TextFilterResponse{Output: strings.Join(lines, "\n")}, nil + }, + }, + + "sort-lines-desc": { + Label: "Lines: Sort Z-A", + Filter: func(ctx context.Context, input string) (resp TextFilterResponse, err error) { + lines := strings.Split(input, "\n") + sort.Sort(sort.Reverse(sort.StringSlice(lines))) + return TextFilterResponse{Output: strings.Join(lines, "\n")}, nil + }, + }, + + "unique-lines": { + Label: "Lines: Unique", + Filter: func(ctx context.Context, input string) (resp TextFilterResponse, err error) { + lines := strings.Split(input, "\n") + seen := make(map[string]struct{}, len(lines)) + dst := make([]string, 0, len(lines)) + for _, line := range lines { + if _, ok := seen[line]; ok { + continue + } + seen[line] = struct{}{} + dst = append(dst, line) + } + return TextFilterResponse{Output: strings.Join(dst, "\n")}, nil + }, + }, + "remove-blank-lines": { Label: "Lines: Remove Blank Lines", Filter: func(ctx context.Context, input string) (resp TextFilterResponse, err error) {