jsonapi v0.9.0 JSONAPI.Utils.String View Source
String manipulation helpers.
Link to this section Summary
Functions
Replace underscores between words in value
with dashes
The configured transformation for the API's fields. JSON:API v1 recommends using dashed fields (e.g. "good-dog", versus "good_dog")
Replace dashes between words in value
with underscores
Link to this section Functions
Link to this function
dasherize(value) View Source
Replace underscores between words in value
with dashes
Ignores underscores that are not between letters/numbers
Examples
iex> dasherize("top_posts")
"top-posts"
iex> dasherize("_top_posts")
"_top-posts"
iex> dasherize("_top__posts_")
"_top__posts_"
Link to this function
field_transformation() View Source
The configured transformation for the API's fields. JSON:API v1 recommends using dashed fields (e.g. "good-dog", versus "good_dog").
This library currently supports dashed and underscored fields.
Configuration examples
Dashed fields:
config :jsonapi, field_transformation: :dasherize
Underscored fields:
config :jsonapi, field_transformation: :underscore
Link to this function
underscore(value) View Source
Replace dashes between words in value
with underscores
Ignores dashes that are not between letters/numbers
Examples
iex> underscore("top-posts")
"top_posts"
iex> underscore("-top-posts")
"-top_posts"
iex> underscore("-top--posts-")
"-top--posts-"
iex> underscore(%{"foo-bar" => "baz"})
%{"foo_bar" => "baz"}
iex> underscore({"foo-bar", "dollar-sol"})
{"foo_bar", "dollar-sol"}
iex> underscore({"foo-bar", %{"a-d" => "z-8"}})
{"foo_bar", %{"a_d" => "z-8"}}
iex> underscore(%{"f-b" => %{"a-d" => "z"}, "c-d" => "e"})
%{"f_b" => %{"a_d" => "z"}, "c_d" => "e"}
iex> underscore(:"foo-bar")
:foo_bar
iex> underscore(%{"f-b" => "a-d"})
%{"f_b" => "a-d"}