View Source IgniterJs.Helpers (igniter_js v0.3.0)
A module that contains helper functions for IgniterJs. For example it helps to normalize the output of the NIFs, read and validate the file, and call the NIF function with the given file path or content.
Summary
Functions
Call the NIF function with the given file path or content and return the result. It helps to change the function name as atom based on its caller function.
Normalize the output of the NIFs. It is a macro and returns a tuple with the first element as the output, the second element as the caller function name, and the third element as the status.
Read and validate the file. It returns the file content if the file exists and the
extension is .js
or .ts
, otherwise, it returns an error tuple.
Functions
Call the NIF function with the given file path or content and return the result. It helps to change the function name as atom based on its caller function.
call_nif_fn("/path/to/file.js", __ENV__.function, fn content -> content end, :path)
call_nif_fn("file content", __ENV__.function, fn content -> content end)
call_nif_fn("file content", __ENV__.function, fn content -> content end, :content)
Normalize the output of the NIFs. It is a macro and returns a tuple with the first element as the output, the second element as the caller function name, and the third element as the status.
require IgniterJs.Helpers
normalize_output({:ok, :fun_atom, result}, __ENV__.function)
normalize_output({:error, :fun_atom, result}, __ENV__.function)
Read and validate the file. It returns the file content if the file exists and the
extension is .js
or .ts
, otherwise, it returns an error tuple.
read_and_validate_file("/path/to/file.js")