https://github.com/ersync/string-magic
A Ruby gem to supercharge string with enhanced formatting and utilities.
https://github.com/ersync/string-magic
gem ruby string
Last synced: 10 days ago
JSON representation
A Ruby gem to supercharge string with enhanced formatting and utilities.
- Host: GitHub
- URL: https://github.com/ersync/string-magic
- Owner: ersync
- License: mit
- Created: 2024-07-29T03:44:26.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2025-08-14T07:33:19.000Z (11 months ago)
- Last Synced: 2026-02-26T05:12:13.355Z (4 months ago)
- Topics: gem, ruby, string
- Language: Ruby
- Homepage: https://rubygems.org/gems/string_magic
- Size: 51.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# StringMagic - v0.5.0
[](https://badge.fury.io/rb/string_magic)
[](https://dl.circleci.com/status-badge/redirect/circleci/8MamMcAVAVNWTcUqkjQk7R/Sh2DQkMWqqCv4MFvAmYWDL/tree/main)
[](LICENSE)
**StringMagic** super-charges Ruby's `String` with batteries-included helpers for formatting, validation, analysis, transformation, and security all in one tidy gem.
## Why StringMagic?
- Zero dependencies – pure Ruby
- Non-destructive: original strings are never mutated
- Thread-safe & fully tested (160+ RSpec examples, ~98% coverage)
- Drop-in: optionally auto-mixes into String, or use module methods (`StringMagic.to_slug(...)`)
## Quickstart Cheatsheet
```ruby
# Formatting
"Hello world".truncate_words(1) # => "Hello..."
"user@domain.com".mask_emails # => "u********@domain.com"
"Ruby on Rails".highlight('Ruby') # => "Ruby on Rails"
# Validation
"test@example.com".email? # => true
"4111111111111111".credit_card? # => true
"racecar".palindrome? # => true
# Transformation
"CamelCase".to_snake_case # => "camel_case"
"user input".to_filename_safe # => "user_input"
"second".ordinalize # => "2nd"
# Analysis
"Visit https://example.com".extract_urls # => ["https://example.com"]
"Great product!".sentiment_indicators # => {:positive=>1.0, :negative=>0.0, :neutral=>0}
```
## Installation
```bash
gem install string_magic
```
Or add to your Gemfile:
```ruby
gem 'string_magic'
```
## Full Documentation
### Core Operations
- **Case conversion**: `to_snake_case`, `to_kebab_case`, `to_camel_case`, `to_pascal_case`, `to_title_case`
- **Text manipulation**: `reverse_words`, `alternating_case`, `remove_duplicate_chars`, `remove_duplicate_words`
- **HTML handling**: `remove_html_tags`, `escape_html`
### Validation
- Format checks: `email?`, `url?`, `phone?`, `credit_card?`
- Text relations: `palindrome?`, `anagram_of?`
- Password strength: `strong_password?`
### Analysis
- **Entity extraction**: `extract_emails`, `extract_urls`, `extract_phones`, `extract_dates`
- **Text metrics**: `readability_score`, `word_frequency`, `sentiment_indicators`
### Formatting
- **Truncation**: `truncate_words`, `truncate_sentences`, `truncate_characters`, `smart_truncate`
- **Highlighting**: `highlight`, `remove_highlights`, `highlight_urls`
### Security
- **Data masking**: `mask_sensitive_data`, `mask_credit_cards`, `mask_emails`, `mask_phones`
- **Detection**: `contains_sensitive_data?`
### Utilities
- **Inflection**: `to_plural`, `to_singular`, `ordinalize`, `humanize`
- **Slug generation**: `to_slug`, `to_url_slug`, `to_filename_safe`
## Contributing
1. Fork → `git checkout -b feature/awesome`
2. Add specs for your change
3. `bundle exec rspec`
4. PR ✉️ – we love improvements!
## License
MIT - See [LICENSE](LICENSE) for details.