slugger alternatives and similar packages
Based on the "Text and Numbers" category.
Alternatively, view slugger alternatives based on common mentions on social networks and blogs.
-
money
Elixir library for working with Money safer, easier, and fun... Is an interpretation of the Fowler's Money pattern in fun.prog. -
nanoid
Elixir port of NanoID, a secure and URL-friendly unique ID generator. https://hex.pm/packages/nanoid -
secure_random
Convenience library for random base64 strings modeled after my love for Ruby's SecureRandom -
abacus
Parses and evaluates mathematical expressions in Elixir. Inspired by math.js -
chinese_translation
An elixir module to translate simplified Chinese to traditional Chinese, and vice versa, based on wikipedia data -
veritaserum
Sentiment analysis based on afinn-165, emojis and some enhancements. -
inet_cidr
CIDR library for Elixir that is compatible with Erlang's :inet and supports both IPv4 and IPv6 -
haikunator
Generate Heroku-like memorable random names to use in your apps or anywhere else. -
Ex_Cldr_Units
Unit formatting (volume, area, length, ...) functions for the Common Locale Data Repository (CLDR) -
mt940
MT940 (standard structured SWIFT Customer Statement message) parser for Elixir. -
convertat
An Elixir library for converting from and to arbitrary bases.
Tired of breaking your main and manually rebasing outdated pull requests?
Do you think we are missing an alternative of slugger or a related project?
Popular Comparisons
README
Slugger
This package provides a library and a protocol to create slugs for given strings.
By default, a slug will be containing only chars A-Za-z0-9
and the default seperator -
.
Want to use this library with Ecto? Have a look at sobolevn/ecto_autoslug_field.
Installation
Add slugger
to your list of dependencies in mix.exs
:
def deps do
[
{:slugger, "~> 0.3"},
]
end
Configuration
The following options can be set in your config.exs
and will be used at next compile!
# Char used as separator between words.
config :slugger, separator_char: ?-
# Path to the file containing replacements.
config :slugger, replacement_file: "lib/replacements.exs"
Library
Using the library is straightforward, check out a few examples:
iex(1)> Slugger.slugify " A b C "
"A-b-C"
iex(2)> Slugger.slugify_downcase " A b C "
"a-b-c"
iex(3)> Slugger.slugify "A cool title of a blog post"
"A-cool-title-of-a-blog-post"
iex(4)> Slugger.slugify_downcase("Kluski Śląskie @ Jalapeño Bilingüe")
"kluski-slaskie-at-jalapeno-bilinguee"
iex(5)> Slugger.slugify "Wikipedia Style", ?_
"Wikipedia_Style"
iex(6)> Slugger.truncate_slug "A-to-long-slug-that-should-be-truncated", 16
"A-to-long-slug"
Protocol
Next to the library, a protocol is provided to ease creating slugs for own data structures.
By default, the protocol will try to run Slugger.slugify(Kernel.to_string(your_data))
, so if your_data
implements String.Chars
, the returned string will be slugified.
If you want to provide your own way to create a slug, check out the following example:
iex(10)> defmodule User do
...(10)> defstruct name: "Julius Beckmann"
...(10)> end
iex(11)> defimpl Slugify, for: User do
...(11)> def slugify(user), do: Slugger.slugify(user.name)
...(11)> end
iex(12)> Slugify.slugify %User{}
"Julius-Beckmann"
Replacements
Special chars like äöüéáÁÉ
will be replaced by rules given in the file [lib/replacements.exs](lib/replacements.exs).
Copy that file if you need have own replacement rules, change the config value and recompile.