Repository navigation
Strings
The Laravex.Support.Str module provides a collection of string manipulation helpers modelled after Laravel's Str facade. Access it directly or via the str() Helpers.
alias Laravex.Support.Str
# Or via the helper
import Laravex.Support.Helpers
str().slug("Hello World")Str.lower("Hello World")
# => "hello world"
Str.upper("Hello World")
# => "HELLO WORLD"
Str.title("hello world")
# => "Hello World"
Str.camel("hello_world")
# => "HelloWorld"
Str.studly("hello_world")
# => "HelloWorld" (alias for camel/1)
Str.snake("HelloWorld")
# => "hello_world"
Str.kebab("hello_world")
# => "hello-world"camel/1 and studly/1 delegate to Macro.camelize/1. snake/1 delegates to Macro.underscore/1. kebab/1 applies snake/1 then replaces underscores with hyphens.
Str.contains?("Hello World", "World")
# => true
# Check for any of several needles
Str.contains?("Hello World", ["foo", "World"])
# => true
Str.starts_with?("Hello World", "Hello")
# => true
Str.ends_with?("Hello World", "World")
# => trueStr.limit("The quick brown fox", 10)
# => "The quick ..."
Str.limit("The quick brown fox", 10, " →")
# => "The quick →"
Str.squish(" Hello World ")
# => "Hello World"limit/3 truncates to max characters and appends ending (default "..."). If the string is already within the limit, it is returned unchanged.
squish/1 collapses all runs of whitespace (including leading/trailing) into single spaces.
Str.before("user@example.com", "@")
# => "user"
Str.after_value("user@example.com", "@")
# => "example.com"Str.finish("https://example.com", "/")
# => "https://example.com/"
Str.finish("https://example.com/", "/")
# => "https://example.com/" (already ends with "/")Str.slug("Hello World!")
# => "hello-world"
Str.slug("Hello World!", "_")
# => "hello_world"slug/2 lowercases the string, replaces all non-alphanumeric runs with the separator, then trims the separator from both ends.
Str.replace("Hello World", "World", "Elixir")
# => "Hello Elixir"
# Mask characters starting at index 0
Str.mask("secret", "*")
# => "******"
# Mask starting at a specific index
Str.mask("1234567890", "*", 4)
# => "1234******"
# Mask a specific number of characters
Str.mask("hello@example.com", "*", 5, 9)
# => "hello*********com"mask/4 replaces length characters starting at index with the given character. Index is zero-based. Both index and length are clamped to the string boundaries.
Str.length("Hello")
# => 5Uses String.length/1, so it counts Unicode graphemes correctly.
Str.random() # 16-character URL-safe random string
Str.random(32) # 32-character URL-safe random stringGenerated via :crypto.strong_rand_bytes/1 encoded with Base.url_encode64/2 (no padding). The result is always URL-safe.
Str.uuid()
# => "550e8400-e29b-41d4-a716-446655440000"Generates a version 4 UUID from :crypto.strong_rand_bytes(16). The variant and version bits are set according to RFC 4122.
Str.ulid()
# => "01ARZ3NDEKTSV4RRFFQ69G5FAV"Generates a Crockford Base32 ULID (Universally Unique Lexicographically Sortable Identifier). Time-sortable and URL-safe.
# 32-character password with letters, numbers, and symbols (default)
Str.password()
Str.password(16)
# Customise character classes
Str.password(24, numbers: true, symbols: false)Extract a snippet of text around a search phrase (Laravel Str::excerpt):
Str.excerpt("Buy Adobe Acrobat Reader DC", "Acrobat", radius: 5)
# => "...Adobe Acrobat Reader..."
Str.excerpt(text, "phrase", radius: 100, omission: "…")radius controls how many characters are shown on each side of the phrase. When phrase is "", the string is simply truncated to radius characters.
Str.is_uuid?("550e8400-e29b-41d4-a716-446655440000") # => true
Str.is_ulid?("01ARZ3NDEKTSV4RRFFQ69G5FAV") # => true
Str.is_url?("https://example.com") # => true
Str.is_json?("{\"name\":\"Alice\"}") # => true
Str.is_ascii?("hello") # => true
Str.is_ip?("192.168.1.1") # => true
Str.is_ipv4?("10.0.0.1") # => true
Str.is_ipv6?("::1") # => true
Str.is_mac_address?("AA:BB:CC:DD:EE:FF") # => true-
Helpers —
str()shortcut andstr_random/1 -
Collections —
Laravex.Support.Collection
Laravex — Laravel-faithful application skeleton & runtime for Elixir.
GitHub
·
Docs
·
Limitations
·
Laravel Docs
Not affiliated with Laravel LLC or the Elixir core team. Built to feel like Laravel on the BEAM.
- Home
- Installation
- Configuration
- Directory-Structure
- Request-Lifecycle
- Service-Container
- Service-Providers
- Deployment
- Routing
- Middleware
- CSRF-Protection
- Controllers
- Requests
- Responses
- Views
- Blade-Templates
- Asset-Bundling
- Session
- Validation
- Error-Handling
- Logging
- Artisan-Console
- Broadcasting
- Cache
- Collections
- Events
- File-Storage
- Helpers
- HTTP-Client
- Localization
- Notifications
- Pipeline
- Queues
- Rate-Limiting
- Strings
- Task-Scheduling