Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hachreak/sf
An OTP library to format a string.
https://github.com/hachreak/sf
erlang erlang-libraries erlang-library string-formatter
Last synced: 3 months ago
JSON representation
An OTP library to format a string.
- Host: GitHub
- URL: https://github.com/hachreak/sf
- Owner: hachreak
- License: other
- Created: 2017-11-06T16:31:56.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-07-21T09:21:44.000Z (over 2 years ago)
- Last Synced: 2023-03-11T12:47:57.823Z (almost 2 years ago)
- Topics: erlang, erlang-libraries, erlang-library, string-formatter
- Language: Erlang
- Size: 12.7 KB
- Stars: 2
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
sf (String Formatter)
=====================An OTP library to format a string.
Use
---rebar.config
```erlang
{deps, [
{sf,
{git, "https://github.com/hachreak/sf.git", {branch, master}}}
]}.
```How to format a binary:
```erlang
<<"Hello worlds! The answer is: 42">> =
sf:format(<<"Hello {{name}}! The answer is: {{answer}}">>,
[{name, <<"worlds">>}, {answer, 42}]).
```Or (passing a map):
```erlang
<<"Hello worlds! The answer is: 42">> =
sf:format(<<"Hello {{name}}! The answer is: {{answer}}">>,
#{name => <<"worlds">>, answer => 42}).
```How to format a string:
```erlang
"Hello worlds!" = sf:format(
<<"Hello {{name}}!">>, [{name, <<"worlds">>}], [string]).
```How to format a atom:
```erlang
'Hello worlds!' = sf:format(
<<"Hello {{name}}!">>, [{name, <<"worlds">>}], [atom]).
```Convert to string:
```erlang
"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