View Source Bonfire.Common.Types (bonfire_umbrella v0.9.6-classic-beta.12)
Summary
Functions
Outputs the names all object types, for the purpose of adding to the localisation strings, as long as the output is piped through to localise_strings/1 at compile time.
Takes an object or module name and checks if it defines a struct
Takes a value and returns true if it's a number or can be converted to a float
Takes a string and returns true if it is a valid ULID (Universally Unique Lexicographically Sortable Identifier)
Takes a string and returns true if it is a valid UUID (Universally Unique Identifier)
Takes a map or list of maps, and if the value of a key in the map is a ULID, it replaces it with the corresponding Crockford Base32 encoded string.
Takes a string and returns an atom if it can be converted to one, else returns the input itself
Takes a string or an atom and returns an atom if it is one or can be converted to one, else returns nil.
Converts a value to a floating-point number if possible. If the value cannot be converted to a float, it returns a fallback value (which defaults to 0 if not provided)
Converts a value to an integer if possible. If the value is not an integer, it attempts to convert it to a float and then rounds it to the nearest integer. Otherwise it returns a fallback value (which defaults to 0 if not provided).
Takes a string and returns the corresponding Elixir module if it exists and is not disabled in the app.
Takes a string as input, converts it to snake_case, and converts it to an atom if such an atom exists, otherwise returns nil.
Handles multiple cases where the input value is of a different type (atom, list, tuple, etc.) and returns a string representation of it.
Takes a module name (as a string or an atom) and converts it to a human-readable string. It removes the Elixir.
prefix (if it exists) and any other prefixes (eg. Bonfire.Common.
) and converts the final part of the module name to a string in title case (eg. Types
).
Takes a module atom and converts it to a string, or a string and removes the Elixir.
prefix if it exists.
Takes an object, module name, or string, and returns the type of the object. The function uses various patterns to match different object types (such as associations, Pointables, edges/verbs, etc.). If none of the patterns match, the function returns nil.
Used for mapping schema types to user-friendly names.
Given a schema module, returns its table ID (i.e. Pointable ULID).
Given an object or module name, returns its respective table table ID (i.e. Pointable ULID).
Given a list of schema types, returns a list of their respective table types. Filters out any empty values.
Takes an object and returns its data type as a module name or atom
Takes an object or list of objects and returns the ULID (Universally Unique Lexicographically Sortable Identifier) ID(s) if present in the object.
Takes an object and returns the ULID (Universally Unique Lexicographically Sortable Identifier) ID if present in the object. Throws an error if the ULID ID is not present.
Functions
Outputs the names all object types, for the purpose of adding to the localisation strings, as long as the output is piped through to localise_strings/1 at compile time.
Takes an object or module name and checks if it defines a struct
Takes a value and returns true if it's a number or can be converted to a float
Takes a string and returns true if it is a valid ULID (Universally Unique Lexicographically Sortable Identifier)
Takes a string and returns true if it is a valid UUID (Universally Unique Identifier)
Takes a map or list of maps, and if the value of a key in the map is a ULID, it replaces it with the corresponding Crockford Base32 encoded string.
Takes a string and returns an atom if it can be converted to one, else returns the input itself
Takes a string or an atom and returns an atom if it is one or can be converted to one, else returns nil.
Converts a value to a floating-point number if possible. If the value cannot be converted to a float, it returns a fallback value (which defaults to 0 if not provided)
Converts a value to an integer if possible. If the value is not an integer, it attempts to convert it to a float and then rounds it to the nearest integer. Otherwise it returns a fallback value (which defaults to 0 if not provided).
Takes a string and returns the corresponding Elixir module if it exists and is not disabled in the app.
Takes a string as input, converts it to snake_case, and converts it to an atom if such an atom exists, otherwise returns nil.
Handles multiple cases where the input value is of a different type (atom, list, tuple, etc.) and returns a string representation of it.
Takes a module name (as a string or an atom) and converts it to a human-readable string. It removes the Elixir.
prefix (if it exists) and any other prefixes (eg. Bonfire.Common.
) and converts the final part of the module name to a string in title case (eg. Types
).
Takes a module atom and converts it to a string, or a string and removes the Elixir.
prefix if it exists.
Takes an object, module name, or string, and returns the type of the object. The function uses various patterns to match different object types (such as associations, Pointables, edges/verbs, etc.). If none of the patterns match, the function returns nil.
Used for mapping schema types to user-friendly names.
Given a string representing a schema type name, returns a sanitised version of it, or nil for object types (or mixins) that shouldn't be displayed.
Examples
iex> sanitise_name("Apactivity") "Federated Object"
Given a schema module, returns its table ID (i.e. Pointable ULID).
Examples
iex> table_id(Bonfire.Data.Social.APActivity) "30NF1REAPACTTAB1ENVMBER0NE"
Given an object or module name, returns its respective table table ID (i.e. Pointable ULID).
Examples
iex> table_type(%Bonfire.Data.Social.APActivity{}) "30NF1REAPACTTAB1ENVMBER0NE"
iex> table_type(%Pointers.Pointer{table_id: "30NF1REAPACTTAB1ENVMBER0NE"}) "30NF1REAPACTTAB1ENVMBER0NE"
iex> table_type(Bonfire.Data.Social.APActivity) "30NF1REAPACTTAB1ENVMBER0NE"
Given a list of schema types, returns a list of their respective table types. Filters out any empty values.
Examples
iex> table_types([:activity, :person]) ["activities", "people"]
Given a single schema type, returns its respective table type.
Examples
iex> table_types(:activity) "activities"
Takes an object and returns its data type as a module name or atom
Takes an object or list of objects and returns the ULID (Universally Unique Lexicographically Sortable Identifier) ID(s) if present in the object.
Takes an object and returns the ULID (Universally Unique Lexicographically Sortable Identifier) ID if present in the object. Throws an error if the ULID ID is not present.