Util (fnord v0.8.13)
View SourceSummary
Functions
Filters an enumerable asynchronously using the provided function. The
function should return true
for items to keep and false
for items to
discard. The result is a stream of items that passed the filter.
Convenience wrapper for Task.async_stream/3
with the default options for
concurrency and timeout set to Application.get_env(:fnord, :workers)
and
:infinity
, respectively.
Compares two files using the diff
command and returns the output.
If the files are identical, it returns {:ok, "No changes detected."}
.
If there are differences, it returns {:ok, output}
with the diff output.
If an error occurs, it returns {:error, output}
with the error message.
Expands a given path to its absolute form, expanding .
and ..
. If a root
directory is provided, it will expand the path relative to that root. If no
root is provided, it will expand the path relative to the current working
directory. The root directory is expanded first, if provided (see
Path.expand/2
).
Shortcut for find_file_within_root(path, <cwd>)
. Returns {:error, :enoent}
if the current working directory cannot be determined.
Finds a file within the specified root directory. It resolves symlinks for
both the file path and the root directory. If the resolved file path is
within the root directory, it returns {:ok, resolved_path}
, otherwise
{:error, :enoent}
.
Converts a value to an integer, raising an ArgumentError
if the value
cannot be parsed as an integer. Accepts both binary strings and integers.
Adds line numbers to each line of the input text, separated by a specified
separator (default is "|"). The numbering starts from 1, or start_index
, if
set.
Parses a binary string into an integer, returning {:ok, int}
if successful,
or {:error, :invalid_integer}
if the string cannot be parsed as an integer.
Accepts both binary strings and integers.
Returns true
if the given path is within the specified root directory,
false
otherwise. Expands both the path and the root to their absolute
forms, resolving symlinks, before performing the check.
Resolves a symlink to its final target. If the path is relative, it will
first be expanded relative to the given root. If root is not provided, it
will expand relative to the current working directory. If a circular symlink
is detected, it returns {:error, :circular_symlink}
. Otherwise, it returns
the absolute, resolved path or the error tuple originating from
File.lstat/1
.
Converts all string keys in a map to atoms, recursively.
Capitalizes the first letter of each word in the input string.
Types
Functions
Filters an enumerable asynchronously using the provided function. The
function should return true
for items to keep and false
for items to
discard. The result is a stream of items that passed the filter.
@spec async_stream(Enumerable.t(), async_cb(), Keyword.t()) :: Enumerable.t()
Convenience wrapper for Task.async_stream/3
with the default options for
concurrency and timeout set to Application.get_env(:fnord, :workers)
and
:infinity
, respectively.
Compares two files using the diff
command and returns the output.
If the files are identical, it returns {:ok, "No changes detected."}
.
If there are differences, it returns {:ok, output}
with the diff output.
If an error occurs, it returns {:error, output}
with the error message.
Expands a given path to its absolute form, expanding .
and ..
. If a root
directory is provided, it will expand the path relative to that root. If no
root is provided, it will expand the path relative to the current working
directory. The root directory is expanded first, if provided (see
Path.expand/2
).
Shortcut for find_file_within_root(path, <cwd>)
. Returns {:error, :enoent}
if the current working directory cannot be determined.
Finds a file within the specified root directory. It resolves symlinks for
both the file path and the root directory. If the resolved file path is
within the root directory, it returns {:ok, resolved_path}
, otherwise
{:error, :enoent}
.
Converts a value to an integer, raising an ArgumentError
if the value
cannot be parsed as an integer. Accepts both binary strings and integers.
Adds line numbers to each line of the input text, separated by a specified
separator (default is "|"). The numbering starts from 1, or start_index
, if
set.
Parses a binary string into an integer, returning {:ok, int}
if successful,
or {:error, :invalid_integer}
if the string cannot be parsed as an integer.
Accepts both binary strings and integers.
Returns true
if the given path is within the specified root directory,
false
otherwise. Expands both the path and the root to their absolute
forms, resolving symlinks, before performing the check.
@spec resolve_symlink(binary(), binary() | nil) :: {:ok, binary()} | {:error, :circular_symlink} | {:error, File.posix()}
Resolves a symlink to its final target. If the path is relative, it will
first be expanded relative to the given root. If root is not provided, it
will expand relative to the current working directory. If a circular symlink
is detected, it returns {:error, :circular_symlink}
. Otherwise, it returns
the absolute, resolved path or the error tuple originating from
File.lstat/1
.
Converts all string keys in a map to atoms, recursively.
Capitalizes the first letter of each word in the input string.