peasytext

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: MIT Imports: 9 Imported by: 0

README

peasytext-go

Go Reference Go Report Card GitHub stars

Go client for the PeasyText API -- text case conversion, slug generation, word counting, and encoding utilities with tools for camelCase, snake_case, kebab-case, PascalCase, and more. Zero dependencies beyond the Go standard library.

Built from PeasyText, a comprehensive text processing toolkit offering free online tools for case conversion, slug generation, word counting, and text analysis. The glossary covers text concepts from character encodings to Unicode normalization, while guides explain text processing strategies and encoding best practices.

Try the interactive tools at peasytext.com -- Text Counter, Case Converter, Slug Generator, and more.

peasytext-go demo -- text case conversion, slug generation, and word count tools in Go terminal

Table of Contents

Install

go get github.com/peasytools/peasytext-go

Requires Go 1.21+.

Quick Start

package main

import (
	"context"
	"fmt"
	"log"

	peasytext "github.com/peasytools/peasytext-go"
)

func main() {
	client := peasytext.New()
	ctx := context.Background()

	// List available text tools
	tools, err := client.ListTools(ctx, nil)
	if err != nil {
		log.Fatal(err)
	}
	for _, t := range tools.Results {
		fmt.Printf("%s: %s\n", t.Name, t.Description)
	}
}

What You Can Do

Text Processing Tools

Text transformation is fundamental to software development -- from generating URL-safe slugs for blog posts to converting variable names between camelCase and snake_case during code generation. Case conversion tools handle the mechanical work of transforming text between naming conventions used across programming languages (camelCase in JavaScript, snake_case in Python, kebab-case in CSS). Word counting and character analysis help content authors meet length requirements for SEO titles, meta descriptions, and social media posts.

Tool Description Use Case
Text Counter Count words, characters, sentences, and paragraphs Content length validation, SEO metadata
Case Converter Convert between camelCase, snake_case, kebab-case, PascalCase Code generation, API field mapping
Slug Generator Create URL-safe slugs from any text input Blog posts, CMS content, URL routing
package main

import (
	"context"
	"fmt"
	"log"

	peasytext "github.com/peasytools/peasytext-go"
)

func main() {
	client := peasytext.New()
	ctx := context.Background()

	// Fetch the case converter tool details
	tool, err := client.GetTool(ctx, "text-case-converter")
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Tool: %s\n", tool.Name)           // Case converter tool
	fmt.Printf("Category: %s\n", tool.Category)   // Text processing category

	// List supported text formats
	formats, err := client.ListFormats(ctx)
	if err != nil {
		log.Fatal(err)
	}
	for _, f := range formats.Results {
		fmt.Printf("%s (%s): %s\n", f.Name, f.Extension, f.MimeType)
	}

	// List available format conversions from plain text
	conversions, err := client.ListConversions(ctx, &peasytext.ListConversionsOptions{Source: str("text")})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("Found %d conversion paths from text\n", len(conversions.Results))
}

func str(s string) *string { return &s }

Learn more: Text Counter · Case Converter · Text Encoding Guide

Browse Text Reference Content

The text processing glossary explains key concepts from basic character encodings to advanced Unicode normalization forms. Understanding the difference between ASCII and UTF-8, how byte order marks (BOM) affect file parsing, and when to use URL encoding versus Base64 helps developers handle text data correctly across platforms and programming languages.

Glossary Term Description
Slug URL-safe string derived from a title or phrase, using hyphens and lowercase
Case Conversion Transforming text between naming conventions like camelCase and snake_case
UTF-8 Variable-width character encoding capable of representing all Unicode code points
Whitespace Characters representing horizontal or vertical space in text rendering
// Browse text processing glossary terms
glossary, err := client.ListGlossary(ctx, &peasytext.ListOptions{Search: str("case-conversion")})
if err != nil {
	log.Fatal(err)
}
for _, term := range glossary.Results {
	fmt.Printf("%s: %s\n", term.Term, term.Definition) // Text processing concept definition
}

// Read in-depth guides on text encoding and conversion
guides, err := client.ListGuides(ctx, &peasytext.ListGuidesOptions{Category: str("formatting")})
if err != nil {
	log.Fatal(err)
}
for _, g := range guides.Results {
	fmt.Printf("%s (%s)\n", g.Title, g.AudienceLevel) // Guide title and difficulty level
}

Learn more: Slug Glossary · ASCII Glossary · Regex Cheat Sheet

Search and Discovery

The unified search endpoint queries across all text tools, glossary terms, guides, and supported formats simultaneously. This is useful for building text editor plugins, documentation search, or CLI tools that need to discover text processing capabilities.

// Search across all text tools, glossary, and guides
results, err := client.Search(ctx, "slugify url", nil)
if err != nil {
	log.Fatal(err)
}
fmt.Printf("Found %d tools, %d glossary terms\n",
	len(results.Results.Tools),
	len(results.Results.Glossary)) // Cross-content text processing search results

Learn more: BOM Glossary · Slug Generator · All Text Guides

API Client

The client wraps the PeasyText REST API with typed Go structs and zero external dependencies.

client := peasytext.New()
// Or with a custom base URL:
// client := peasytext.New(peasytext.WithBaseURL("https://custom.example.com"))
ctx := context.Background()

// List tools with pagination
tools, _ := client.ListTools(ctx, &peasytext.ListOptions{Page: 1, Limit: 10})

// Get a specific tool by slug
tool, _ := client.GetTool(ctx, "text-case")
fmt.Println(tool.Name, tool.Description)

// Search across all content
results, _ := client.Search(ctx, "slugify url", nil)
fmt.Printf("Found %d tools\n", len(results.Results.Tools))

// Browse the glossary
glossary, _ := client.ListGlossary(ctx, &peasytext.ListOptions{Search: str("case-conversion")})
for _, term := range glossary.Results {
	fmt.Printf("%s: %s\n", term.Term, term.Definition)
}

// Discover guides
guides, _ := client.ListGuides(ctx, &peasytext.ListGuidesOptions{Category: str("formatting")})
for _, g := range guides.Results {
	fmt.Printf("%s (%s)\n", g.Title, g.AudienceLevel)
}

// List file format conversions
conversions, _ := client.ListConversions(ctx, &peasytext.ListConversionsOptions{Source: str("text")})

// Get format details
format, _ := client.GetFormat(ctx, "slug")
fmt.Printf("%s (%s): %s\n", format.Name, format.Extension, format.MimeType)

Helper for optional string parameters:

func str(s string) *string { return &s }
Available Methods
Method Description
ListTools(ctx, opts) List tools (paginated, filterable)
GetTool(ctx, slug) Get tool by slug
ListCategories(ctx, opts) List tool categories
ListFormats(ctx, opts) List file formats
GetFormat(ctx, slug) Get format by slug
ListConversions(ctx, opts) List format conversions
ListGlossary(ctx, opts) List glossary terms
GetGlossaryTerm(ctx, slug) Get glossary term
ListGuides(ctx, opts) List guides
GetGuide(ctx, slug) Get guide by slug
ListUseCases(ctx, opts) List use cases
Search(ctx, query, limit) Search across all content
ListSites(ctx) List Peasy sites
OpenAPISpec(ctx) Get OpenAPI specification

Full API documentation at peasytext.com/developers/. OpenAPI 3.1.0 spec: peasytext.com/api/openapi.json.

Learn More About Text Processing

Also Available

Language Package Install
Python peasytext pip install "peasytext[all]"
TypeScript peasytext npm install peasytext
Rust peasytext cargo add peasytext
Ruby peasytext gem install peasytext

Peasy Developer Tools

Part of the Peasy Tools open-source developer ecosystem.

Package PyPI npm Go Description
peasy-pdf PyPI npm Go PDF merge, split, rotate, compress -- peasypdf.com
peasy-image PyPI npm Go Image resize, crop, convert, compress -- peasyimage.com
peasy-audio PyPI npm Go Audio trim, merge, convert, normalize -- peasyaudio.com
peasy-video PyPI npm Go Video trim, resize, thumbnails, GIF -- peasyvideo.com
peasy-css PyPI npm Go CSS minify, format, analyze -- peasycss.com
peasy-compress PyPI npm Go ZIP, TAR, gzip compression -- peasytools.com
peasy-document PyPI npm Go Markdown, HTML, CSV, JSON conversion -- peasyformats.com
peasytext PyPI npm Go Text case conversion, slugify, word count -- peasytext.com

License

MIT

Documentation

Overview

Package peasyimage provides a Go client for the PeasyText API.

PeasyText offers text tools including format, convert, encode, and analyze. This client requires no authentication and has zero external dependencies.

Usage:

client := peasyimage.New()
tools, err := client.ListTools(ctx)
term, err := client.GetGlossaryTerm(ctx, "webp")

Index

Constants

View Source
const DefaultBaseURL = "https://peasytext.com"

DefaultBaseURL is the default PeasyText API base URL.

View Source
const DefaultTimeout = 30 * time.Second

DefaultTimeout is the default HTTP client timeout.

Variables

This section is empty.

Functions

This section is empty.

Types

type Category

type Category struct {
	Slug        string `json:"slug"`
	Name        string `json:"name"`
	Description string `json:"description"`
	ToolCount   int    `json:"tool_count"`
}

Category represents a tool category.

type Client

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

Client is the PeasyText API client.

func New

func New(opts ...Option) *Client

New creates a new PeasyText API client.

func (*Client) GetFormat

func (c *Client) GetFormat(ctx context.Context, slug string) (*Format, error)

GetFormat returns a single format by slug.

func (*Client) GetGlossaryTerm

func (c *Client) GetGlossaryTerm(ctx context.Context, slug string) (*GlossaryTerm, error)

GetGlossaryTerm returns a single glossary term by slug.

func (*Client) GetGuide

func (c *Client) GetGuide(ctx context.Context, slug string) (*Guide, error)

GetGuide returns a single guide by slug.

func (*Client) GetTool

func (c *Client) GetTool(ctx context.Context, slug string) (*Tool, error)

GetTool returns a single tool by slug.

func (*Client) ListCategories

func (c *Client) ListCategories(ctx context.Context, opts ...ListOptions) (*PaginatedResponse[Category], error)

ListCategories returns a paginated list of categories.

func (*Client) ListConversions

func (c *Client) ListConversions(ctx context.Context, opts ...ListConversionsOptions) (*PaginatedResponse[Conversion], error)

ListConversions returns a paginated list of conversions.

func (*Client) ListFormats

func (c *Client) ListFormats(ctx context.Context, opts ...ListOptions) (*PaginatedResponse[Format], error)

ListFormats returns a paginated list of file formats.

func (*Client) ListGlossary

func (c *Client) ListGlossary(ctx context.Context, opts ...ListOptions) (*PaginatedResponse[GlossaryTerm], error)

ListGlossary returns a paginated list of glossary terms.

func (*Client) ListGuides

func (c *Client) ListGuides(ctx context.Context, opts ...ListGuidesOptions) (*PaginatedResponse[Guide], error)

ListGuides returns a paginated list of guides.

func (*Client) ListSites

func (c *Client) ListSites(ctx context.Context) (*PaginatedResponse[Site], error)

ListSites returns all Peasy Tools sites.

func (*Client) ListTools

func (c *Client) ListTools(ctx context.Context, opts ...ListOptions) (*PaginatedResponse[Tool], error)

ListTools returns a paginated list of tools.

func (*Client) ListUseCases

func (c *Client) ListUseCases(ctx context.Context, opts ...ListOptions) (*PaginatedResponse[UseCase], error)

ListUseCases returns a paginated list of use cases.

func (*Client) OpenAPISpec

func (c *Client) OpenAPISpec(ctx context.Context) (json.RawMessage, error)

OpenAPISpec returns the raw OpenAPI spec as JSON.

func (*Client) Search

func (c *Client) Search(ctx context.Context, query string, opts ...SearchOptions) (*SearchResult, error)

Search performs a unified search across tools, formats, and glossary.

type Conversion

type Conversion struct {
	Source      string `json:"source"`
	Target      string `json:"target"`
	Description string `json:"description"`
	ToolSlug    string `json:"tool_slug"`
}

Conversion represents a format conversion.

type Format

type Format struct {
	Slug        string `json:"slug"`
	Name        string `json:"name"`
	Extension   string `json:"extension"`
	MimeType    string `json:"mime_type"`
	Category    string `json:"category"`
	Description string `json:"description"`
}

Format represents a file format.

type GlossaryTerm

type GlossaryTerm struct {
	Slug       string `json:"slug"`
	Term       string `json:"term"`
	Definition string `json:"definition"`
	Category   string `json:"category"`
}

GlossaryTerm represents a glossary entry.

type Guide

type Guide struct {
	Slug          string `json:"slug"`
	Title         string `json:"title"`
	Description   string `json:"description"`
	Category      string `json:"category"`
	AudienceLevel string `json:"audience_level"`
	WordCount     int    `json:"word_count"`
}

Guide represents a how-to guide.

type ListConversionsOptions

type ListConversionsOptions struct {
	Page   int
	Limit  int
	Source string
	Target string
}

ListConversionsOptions adds source/target filtering.

type ListGuidesOptions

type ListGuidesOptions struct {
	Page          int
	Limit         int
	Category      string
	AudienceLevel string
	Search        string
}

ListGuidesOptions adds audience level filtering.

type ListOptions

type ListOptions struct {
	Page     int
	Limit    int
	Category string
	Search   string
}

ListOptions are common parameters for paginated list endpoints.

type NotFoundError

type NotFoundError struct {
	Resource   string
	Identifier string
}

NotFoundError is returned when a resource is not found (404).

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

type Option

type Option func(*Client)

Option configures the Client.

func WithBaseURL

func WithBaseURL(u string) Option

WithBaseURL overrides the default base URL.

func WithHTTPClient

func WithHTTPClient(hc *http.Client) Option

WithHTTPClient sets a custom HTTP client.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets the HTTP client timeout.

type PaginatedResponse

type PaginatedResponse[T any] struct {
	Count    int     `json:"count"`
	Next     *string `json:"next"`
	Previous *string `json:"previous"`
	Results  []T     `json:"results"`
}

PaginatedResponse represents a paginated API response.

type PeasyError

type PeasyError struct {
	StatusCode int
	Message    string
}

PeasyError represents an API error response.

func (*PeasyError) Error

func (e *PeasyError) Error() string

type SearchCategories

type SearchCategories struct {
	Tools    []Tool         `json:"tools"`
	Formats  []Format       `json:"formats"`
	Glossary []GlossaryTerm `json:"glossary"`
}

SearchCategories groups search results by type.

type SearchOptions

type SearchOptions struct {
	Limit int
}

SearchOptions for the search endpoint.

type SearchResult

type SearchResult struct {
	Query   string           `json:"query"`
	Results SearchCategories `json:"results"`
}

SearchResult represents unified search results.

type Site

type Site struct {
	Name   string `json:"name"`
	Domain string `json:"domain"`
	URL    string `json:"url"`
}

Site represents a Peasy Tools site.

type Tool

type Tool struct {
	Slug        string `json:"slug"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Category    string `json:"category"`
	URL         string `json:"url"`
}

Tool represents a PDF tool.

type UseCase

type UseCase struct {
	Slug     string `json:"slug"`
	Title    string `json:"title"`
	Industry string `json:"industry"`
}

UseCase represents an industry use case.

Directories

Path Synopsis
examples
demo command
Demo script for peasytext-go — PeasyText API client.
Demo script for peasytext-go — PeasyText API client.

Jump to

Keyboard shortcuts

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