Skip to content

lupodevelop/str

Repository files navigation

str logo

str

Unicode-aware string utilities for Gleam

Package Version Hex Docs CI License: MIT

Production-ready Gleam library for Unicode-aware string operations. All operations work at grapheme cluster boundaries, correct behaviour for emoji, ZWJ sequences, combining marks, and flags.


Features

Category Highlights
Grapheme-Aware take, drop, length, reverse, chunk β€” all grapheme-correct
Case Conversions snake_case, camelCase, kebab-case, PascalCase, Title Case
Slug Generation slugify with token limits, custom separators, Unicode preservation
Search & Replace index_of, last_index_of, replace_first/last, contains_any/all
Validation is_uppercase/lowercase/title_case, is_ascii/hex/numeric/alpha
Escaping escape_html, unescape_html, escape_regex
Similarity Levenshtein distance, normalized similarity, hamming_distance
Splitting splitn, partition, rpartition, chunk, lines, words
Padding pad_left, pad_right, center, fill
Minimal deps No OTP requirement β€” works on Erlang and JavaScript targets

Installation

gleam add str

Quick Start

import str

// Grapheme-safe truncation preserves emoji sequences
str.truncate("Hello πŸ‘©β€πŸ‘©β€πŸ‘§β€πŸ‘¦ World", 10, "...")
// β†’ "Hello πŸ‘©β€πŸ‘©β€πŸ‘§β€πŸ‘¦..."

// ASCII transliteration and URL-friendly slugs
str.slugify("Crème Brûlée — Recipe 2025!")
// β†’ "creme-brulee-recipe-2025"

// Case conversions
str.to_camel_case("hello world")  // β†’ "helloWorld"
str.to_snake_case("Hello World")  // β†’ "hello_world"

// Grapheme-aware search β€” counts clusters, not bytes
str.index_of("πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦ family test", "family")
// β†’ Ok(2)

// Normalized Levenshtein similarity
str.similarity("hello", "hallo")
// β†’ 0.8

Documentation

Document Description
API Reference Complete function reference with examples
Examples Integration snippets and patterns

| OTP Integration | NFC/NFD normalization via Erlang | | Core internals | Grapheme-aware core operations | | Extra internals | ASCII folding and slug generation | | Tokenizer | Pure-Gleam grapheme tokenizer reference |


Module Guide

Module Use when Import
str Everything β€” recommended entry point import str
str/advanced Explicit KMP algorithm control, map caching import str/advanced
str/config Tune search heuristic thresholds import str/config
str/
β”œβ”€β”€ str.gleam       # Main module β€” complete public API
β”œβ”€β”€ advanced.gleam  # Low-level search algorithms
β”œβ”€β”€ config.gleam    # Search heuristic configuration
└── internal/       # Implementation details (not part of public API)

Development

gleam test                               # run test suite (Erlang target)
gleam test --target javascript           # run on JavaScript target
python3 scripts/generate_character_tables.py  # regenerate transliteration tables

Contributing

Contributions welcome. See CONTRIBUTING.md. Run gleam test before submitting PRs.


License

MIT β€” see LICENSE.


Links

About

Gleam library providing Unicode-aware string operations

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors