From cff2ffa2950bdb9b565cc39c7bbbd168c647e4b4 Mon Sep 17 00:00:00 2001 From: alisdair sullivan Date: Sun, 25 Mar 2012 13:09:55 -0700 Subject: [PATCH] better specs for to_term/x, thanks to michael truog --- src/jsx.erl | 20 ++++++++++++++++---- src/jsx_to_term.erl | 10 ++++++++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/jsx.erl b/src/jsx.erl index b903261..9820070 100644 --- a/src/jsx.erl +++ b/src/jsx.erl @@ -60,10 +60,22 @@ format(Source) -> format(Source, []). format(Source, Opts) -> jsx_to_json:format(Source, Opts). --spec to_term(Source::binary()) -> - list({binary(), any()}). --spec to_term(Source::binary(), Opts::jsx_to_term:opts()) -> - list({binary(), any()}). +-spec to_term(Source::binary()) -> list({binary(), any()}) + | list(any()) + | true + | false + | null + | integer() + | float() + | binary(). +-spec to_term(Source::binary(), Opts::jsx_to_term:opts()) -> list({binary(), any()}) + | list(any()) + | true + | false + | null + | integer() + | float() + | binary(). to_term(Source) -> to_term(Source, []). diff --git a/src/jsx_to_term.erl b/src/jsx_to_term.erl index 582a9af..b5c3b44 100644 --- a/src/jsx_to_term.erl +++ b/src/jsx_to_term.erl @@ -34,8 +34,14 @@ -type opts() :: list(). --spec to_term(Source::(binary() | list()), Opts::opts()) -> - list({binary(), any()}). +-spec to_term(Source::binary(), Opts::opts()) -> list({binary(), any()}) + | list(any()) + | true + | false + | null + | integer() + | float() + | binary(). to_term(Source, Opts) when is_list(Opts) -> (jsx:decoder(?MODULE, Opts, jsx_utils:extract_opts(Opts)))(Source).