wordsmith

Handles pluralization, ordinalizing words, etc
0.3.0 released

Wordsmith

API Documentation Website

Wordsmith is a library for pluralizing, ordinalizing, singularizing and doing other fun and useful things with words.

Installation

Add this to your application's shard.yml:

dependencies:
  wordsmith:
    github: luckyframework/wordsmith

Usage

require "wordsmith"

Wordsmith::Inflector.pluralize("word") # "words"
Wordsmith::Inflector.singularize("categories") # "category"
Wordsmith::Inflector.camelize("application_controller") # "ApplicationController"
Wordsmith::Inflector.underscore("CheeseBurger") # "cheese_burger"
Wordsmith::Inflector.humanize("employee_id") # "Employee"
Wordsmith::Inflector.titleize("amazon web services") # "Amazon Web Services"
Wordsmith::Inflector.tableize("User") # "users"
Wordsmith::Inflector.classify("users") # "User"
Wordsmith::Inflector.dasherize("post_office") # "post-office"
Wordsmith::Inflector.ordinalize(4) # "4th"
Wordsmith::Inflector.demodulize("Helpers::Mixins::User") # "User"
Wordsmith::Inflector.deconstantize("User::FREE_TIER_COMMENTS") # "User"
Wordsmith::Inflector.foreign_key("Person") # "person_id"
Wordsmith::Inflector.parameterize("Admin/product") # "admin-product"

Custom inflections

If something isn't pluralizing correctly, it's easy to customize.

# Place this in a config file like `config/inflectors.cr`
require "wordsmith"

# To pluralize a single string in a specific way
Wordsmith::Inflector.inflections.irregular("human", "humans")

# To stop Wordsmith from pluralizing a word altogether
Wordsmith::Inflector.inflections.uncountable("equipment")

Contributing

  1. Fork it ( https://github.com/luckyframework/wordsmith/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Make your changes
  4. Run ./bin/test to run the specs, build shards, and check formatting
  5. Commit your changes (git commit -am 'Add some feature')
  6. Push to the branch (git push origin my-new-feature)
  7. Create a new Pull Request

Testing

To run the tests:

  • Run the tests with ./bin/test

Contributors

Thanks & attributions

  • Inflector is based on Rails. Thank you to the Rails team!
wordsmith:
  github: luckyframework/wordsmith
  version: ~> 0.3.0
License MIT
Crystal >= 1.0.0

Authors

Dependencies 0

Development Dependencies 1

  • ameba ~> 0.14.2
    {'github' => 'crystal-ameba/ameba', 'version' => '~> 0.14.2'}

Dependents 12

Show all 12 dependents
Last synced .
search fire star recently