Zenify
Zenify is a tiny Ruby utility gem that normalizes whitespace in strings.
It is especially useful when dealing with Japanese text, as it converts full-width spaces (全角スペース) into normal spaces and collapses consecutive whitespace into a single space.
Requirements
- Ruby 3.2 or later
Compatibility
Zenify is continuously tested against the following Ruby versions via CI:
- Ruby 3.2
- Ruby 3.3
- Ruby 3.4
- Ruby 4.0
- This project is tested on Ruby 3.2–4.0 using GitHub Actions.
Installation
Add this line to your application's Gemfile:
gem "zenify"
And then execute:
bundle install
Or install it yourself as:
gem install zenify
Usage
require "zenify"
Zenify.normalize_spaces(" a b ")
# => "a b"
Zenify.normalize_spaces(" こんにちは 世界 ")
# => "こんにちは 世界"
CLI
You can also use Zenify from the command line:
zenify " a b "
# => a b
echo " a b " | zenify
# => a b
# trailing spaces preserved
zenify --no-strip " a b "
# => a b
zenify --help
zenify --version
Development
After checking out the repo, run:
bin/setup
Then run the tests:
bundle exec rake test
You can also experiment in an interactive console:
bin/console
To install this gem onto your local machine:
bundle exec rake install
Contributing
Bug reports and pull requests are welcome on GitHub:
License
The gem is available as open source under the terms of the MIT License.