Skip to content

hachreak/sf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sf (String Formatter)

An OTP library to format a string.

Use

rebar.config

{deps, [
  {sf,
    {git, "https://github.com/hachreak/sf.git", {branch, master}}}
]}.

How to format a binary:

<<"Hello worlds! The answer is: 42">> =
    sf:format(<<"Hello {{name}}! The answer is: {{answer}}">>,
              [{name, <<"worlds">>}, {answer, 42}]).

Or (passing a map):

<<"Hello worlds! The answer is: 42">> =
    sf:format(<<"Hello {{name}}! The answer is: {{answer}}">>,
              #{name => <<"worlds">>, answer => 42}).

How to format a string:

"Hello worlds!" = sf:format(
      <<"Hello {{name}}!">>, [{name, <<"worlds">>}], [string]).

How to format a atom:

'Hello worlds!' = sf:format(
      <<"Hello {{name}}!">>, [{name, <<"worlds">>}], [atom]).

Convert to string:

"test" = sf:to_string(test).
"test" = sf:to_string("test").
"test" = sf:to_string(<<"test">>).
"123" = sf:to_string(123).
"12.3" = sf:to_string(12.3).
"<0.60.0>" = sf:to_string(self()).
"{1,2,3}" = sf:to_string({1,2,3}).

Build
-----

    $ rebar3 compile

Releases

No releases published

Packages

No packages published

Languages