Pārlūkot izejas kodu

Add Dialyzer types and specs

Thanks to @joedevivo for the contribution.

Fixes #85
return-trailer
Paul J. Davis pirms 9 gadiem
vecāks
revīzija
e371ec1075
1 mainītis faili ar 34 papildinājumiem un 0 dzēšanām
  1. +34
    -0
      src/jiffy.erl

+ 34
- 0
src/jiffy.erl Parādīt failu

@ -8,10 +8,42 @@
-on_load(init/0).
-type json_value() :: null
| true
| false
| json_string()
| json_number()
| json_object()
| json_array().
-type json_array() :: [json_value()].
-type json_string() :: binary().
-type json_number() :: integer() | float().
-type json_object() :: {[{json_string(),json_value()}]}.
-type decode_option() :: return_maps
| use_nil
| {null_term, any()}
| {bytes_per_iter, non_neg_integer()}.
-type encode_option() :: uescape
| pretty
| force_utf8
| escape_forward_slashes
| {bytes_per_iter, non_neg_integer()}.
-type decode_options() :: [decode_option()].
-type encode_options() :: [encode_option()].
-export_type([json_value/0]).
-spec decode(iolist() | binary()) -> json_value().
decode(Data) ->
decode(Data, []).
-spec decode(iolist() | binary(), decode_options()) -> json_value().
decode(Data, Opts) when is_binary(Data), is_list(Opts) ->
case nif_decode_init(Data, Opts) of
{error, _} = Error ->
@ -27,10 +59,12 @@ decode(Data, Opts) when is_list(Data) ->
decode(iolist_to_binary(Data), Opts).
-spec encode(json_value()) -> iolist().
encode(Data) ->
encode(Data, []).
-spec encode(json_value(), encode_options()) -> iolist().
encode(Data, Options) ->
ForceUTF8 = lists:member(force_utf8, Options),
case nif_encode_init(Data, Options) of

Notiek ielāde…
Atcelt
Saglabāt