Copyright © 2006 Serge Aleynikov
Authors: Serge Aleynikov (saleyn@gmail.com).
ccy_sym() = binary() | string()
decimals() = 0..253
see types for erlang:float_to_binary/2
format_number_opts() = #{thousands => binary() | string(), decimal_point => binary() | string(), ccy_sym => ccy_sym(), ccy_pos => left | right, ccy_sep => binary() | string(), return => binary | list}
formatted_number() = binary()
precision() = integer()
pretty_print_opts() = #{number_pad => char(), out_header => boolean(), out_sep => boolean(), th_dir => both | leading | trailing, td_dir => both | leading | trailing, td_start => integer(), td_exclude => list(), td_sep => string(), tr_sep => string(), tr_sep_td => string(), prefix => string(), thousands => string() | binary(), translate => fun((term()) -> term()), footer_rows => integer(), td_formats => tuple() | fun((ColVal :: term()) -> {string, string()} | {number, string() | number()} | {number, Decimals :: integer(), ColVal :: number()} | {ccy, number()}), thousands => string() | binary(), ccy_sym => string() | binary(), ccy_sep => string() | binary(), ccy_pos => left | right}
align_rows/1 | |
align_rows/2 | Align rows of terms by stringifying them to uniform column width. |
aligned_format/2 | |
aligned_format/3 | |
batch_split/2 | Split a list into batches of N items. |
binary_join/2 | |
format_integer/1 | |
format_integer/2 | |
format_number/3 | The same as uef_format:format_number/4 with #{} as the forth argument. |
format_number/4 | Formats Number by adding thousands separator between each set of 3 digits to the left of the decimal point, substituting Decimals for the decimal point, and rounding to the specified Precision. |
format_price/1 | Formats Number in price-like style. |
format_price/2 | Formats Number in price-like style. |
format_price/3 | Formats Number in price-like style. |
parse_csv/1 | Parse a given CSV file. |
parse_csv/2 | Parse a given CSV file. |
pretty_print_table/1 | |
pretty_print_table/2 | |
pretty_print_table/3 | |
pretty_table/1 | Pretty print list of maps to list. |
pretty_table/2 | Pretty print table of lists/tuples/maps to list. |
pretty_table/3 | Pretty print table of lists/tuples/maps to list. |
round_number/2 | Rounds the number to the specified precision. |
round_price/1 | Rounds the number to the precision of 2. |
titlecase/1 | Convert words in a string to capitalize first letter of each word. |
wordwrap/2 | Wrap words words in a string. |
align_rows(Rows) -> any()
align_rows(Rows :: [tuple() | binary() | list()], Options :: [{pad, Dir :: [trailing | leading | both | {Pos :: integer() | last, trailing | leading | both | none}]} | {exclude, Cols :: [integer()]} | {return, Ret :: tuple | list} | {prefix, string()} | {ignore_empty, boolean()}]) -> [AlignedRow :: tuple() | list()]
Align rows of terms by stringifying them to uniform column width.
If some row doesn't need to be aligned, pass its value as a binary.
Options
can be:
aligned_format(Fmt, Rows) -> any()
aligned_format(Fmt, Rows, Directions) -> any()
batch_split(N :: integer(), L :: list()) -> [list()]
Split a list into batches of N items
binary_join(Tail, Sep) -> any()
format_integer(Integer :: integer()) -> formatted_number()
format_integer(Integer :: integer(), Opts :: format_number_opts()) -> formatted_number()
format_number(N :: number(), Precision :: precision(), Decimals :: decimals()) -> formatted_number()
The same as uef_format:format_number/4 with #{} as the forth argument.
See also: format_number/4.
format_number(Number :: number(), Precision :: precision(), Decimals :: decimals(), Opts :: format_number_opts()) -> formatted_number()
Formats Number by adding thousands separator between each set of 3 digits to the left of the decimal point, substituting Decimals for the decimal point, and rounding to the specified Precision. Returns a binary value.
format_price(Number :: number()) -> FormattedPrice :: formatted_number()
Formats Number in price-like style. Returns a binary containing FormattedPrice formatted with a precision of 2 and decimal digits of 2. The same as format_price/2 with a precision of 2 as the second argument. See uef_format:format_price/2 docs.
format_price(Number :: number(), Precision :: precision()) -> formatted_number()
Formats Number in price-like style. Returns a binary containing FormattedPrice formatted with a specified precision as the second argument and decimal digits of 2. The same as uef_format:format_price/3 with #{} as the third argument.
See also: format_price/3.
format_price(Number :: number(), Precision :: precision(), CcySymbol_OR_Options :: format_number_opts() | ccy_sym()) -> FormattedPrice :: formatted_number()
Formats Number in price-like style. Returns a binary containing FormattedPrice formatted with a specified precision as the second argument, decimal digits of 2, and with ccy symbol (or options) as the third argument. If CcySymbol_OR_Options is a map the functions works as format_number/4 with decimal digits of 2 as the third argument and with options as the forth one. If CcySymbol_OR_Options is a binary or a string, the corresponding ccy symbol is added to the left.
parse_csv(File :: string()) -> [[string()]]
Parse a given CSV file.
parse_csv(File :: string(), Opts :: [fix_lengths | {open, Opts :: list()}]) -> [[string()]]
Parse a given CSV file.
pretty_print_table(LofMaps0) -> any()
pretty_print_table(HeaderRowKeys, Rows) -> any()
pretty_print_table(HeaderRowKeys, Rows, Opts) -> any()
pretty_table(LofMaps0 :: [map()]) -> list()
Pretty print list of maps to list.
See also: pretty_table/3.
pretty_table(HeaderRowKeys :: [string()], Rows :: [Row :: tuple() | list() | map()]) -> list()
Pretty print table of lists/tuples/maps to list.
See also: pretty_table/3.
pretty_table(HeaderRowKeys :: [string()], Rows :: [Row :: tuple() | list() | map()], Opts :: map()) -> list()
Pretty print table of lists/tuples/maps to list. The following options control formatting behavior:
" | "
)"-"
)"+"`)</dd>
<dt>prefix</dt>
<dd>Prepend each row with this string</dd>
<dt>td_formats</dt>
<dd>A tuple containing column formats. Each value is either
a format string passed to `io_lib:format/2
or a function taking
either one argument
fun(Value) -> {number|string, FormattedValue::string()}
or three arguments
fun(Key,Value,Row::tuple()|map()) -> {number|string, FormattedValue::string()}
.
This three argument function can perform calculation of the field
value based on values of other fields in the Row
.
1> stringx:pretty_print_table( {a,b,c,d}, [{a, 10, ccc}, {bxxx, 200.00123, 'Done'}, {abc, 100.0, xx}], #opts{td_dir=both, td_exclude=[d], td_formats= {undefined, fun(V) when is_integer(V) -> {number, integer_to_list(V)}; (V) when is_float(V) -> {number, float_to_list(V, [{decimals, 5}])} end, "~w"}}). a | b | c -----+-----------+------- a | 10 | ccc bxxx | 200.00123 | 'Done' -----+-----------+-------
round_number(Number :: number(), Precision :: integer()) -> float()
Rounds the number to the specified precision.
round_price(Number :: number()) -> float()
Rounds the number to the precision of 2.
titlecase(S :: string()) -> string()
Convert words in a string to capitalize first letter of each word.
wordwrap(S :: string(), Margin :: integer()) -> string()
Wrap words words in a string
Generated by EDoc