Humaans.CaseConvert (Humaans v0.6.0)

Copy Markdown View Source

Internal helper that converts snake_case keys to camelCase before sending request bodies to the Humaans API.

Responses come back camelCase and are converted to snake_case by ExConstructor on the resource structs. This module closes the loop on the request side: callers can write %{first_name: "Jane"} instead of %{firstName: "Jane"} and have the value reach the wire correctly.

Already-camelCase keys are passed through with their case preserved (atom keys still become strings, see below).

Atom and string keys are normalized to strings

Input atom and string keys are emitted as string keys in the output. This avoids creating new atoms at runtime — atoms are not garbage-collected and untrusted, high-cardinality keys could otherwise exhaust the atom table. The same guidance applies in Humaans.Query. Req JSON-encodes string-keyed maps transparently, so callers don't need to do anything different.

Keys that are neither atoms nor strings (e.g. integer keys) are passed through unchanged — they aren't camelCase candidates and don't pose an atom-table risk.

Keyword list inputs are converted to string-keyed maps for the same reason and because keyword lists structurally require atom keys.

Collisions

When two distinct input keys normalize to the same camelCase string (e.g. %{first_name: 1, firstName: 2}), ArgumentError is raised rather than silently dropping a field.

Summary

Functions

Converts top-level keys of a map or keyword list from snake_case to camelCase. Atom and string keys are normalized to strings; other key types pass through unchanged (see module doc). Non-map, non-list values are returned unchanged.

Functions

to_camel_case_keys(map)

@spec to_camel_case_keys(any()) :: any()

Converts top-level keys of a map or keyword list from snake_case to camelCase. Atom and string keys are normalized to strings; other key types pass through unchanged (see module doc). Non-map, non-list values are returned unchanged.

Raises ArgumentError when two distinct atom/string input keys normalize to the same camelCase string.