Skip to content

Repository files navigation

str logo

str

Unicode-aware string utilities for Gleam

Package VersionHex DocsCILicense: 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

CategoryHighlights
Grapheme-Awaretake, drop, length, reverse, chunk — all grapheme-correct
Case Conversionssnake_case, camelCase, kebab-case, PascalCase, Title Case
Slug Generationslugify with token limits, custom separators, Unicode preservation
Search & Replaceindex_of, last_index_of, replace_first/last, contains_any/all
Validationis_uppercase/lowercase/title_case, is_ascii/hex/numeric/alpha
Escapingescape_html, unescape_html, escape_regex
SimilarityLevenshtein distance, normalized similarity, hamming_distance
Splittingsplitn, partition, rpartition, chunk, lines, words
Paddingpad_left, pad_right, center, fill
Minimal depsNo OTP requirement — works on Erlang and JavaScript targets

Installation

gleam add str

Quick Start

importstr// Grapheme-safe truncation preserves emoji sequencesstr.truncate("Hello 👩‍👩‍👧‍👦 World",10,"...")// → "Hello 👩‍👩‍👧‍👦..."// ASCII transliteration and URL-friendly slugsstr.slugify("Crème Brûlée — Recipe 2025!")// → "creme-brulee-recipe-2025"// Case conversionsstr.to_camel_case("hello world")// → "helloWorld"str.to_snake_case("Hello World")// → "hello_world"// Grapheme-aware search — counts clusters, not bytesstr.index_of("👨‍👩‍👧‍👦 family test","family")// → Ok(2)// Normalized Levenshtein similaritystr.similarity("hello","hallo")// → 0.8

Documentation

DocumentDescription
API ReferenceComplete function reference with examples
ExamplesIntegration 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

ModuleUse whenImport
strEverything — recommended entry pointimport str
str/advancedExplicit KMP algorithm control, map cachingimport str/advanced
str/configTune search heuristic thresholdsimport 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

Contributing

Stars

11 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages