lib: add jsonPrettyText helper, depend on aeson-pretty

This commit is contained in:
Simon Michael 2020-06-04 15:12:57 -07:00
parent 00e9e844ac
commit d963944c99
3 changed files with 14 additions and 1 deletions

View File

@ -26,6 +26,7 @@ module Hledger.Utils.Text
stripquotes,
-- isSingleQuoted,
-- isDoubleQuoted,
jsonPrettyText,
-- -- * single-line layout
textstrip,
textlstrip,
@ -59,6 +60,8 @@ module Hledger.Utils.Text
)
where
import Data.Aeson (Value)
import Data.Aeson.Encode.Pretty (encodePrettyToTextBuilder)
-- import Data.Char
import Data.List
#if !(MIN_VERSION_base(4,11,0))
@ -66,6 +69,8 @@ import Data.Monoid
#endif
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.Lazy as TL
import Data.Text.Lazy.Builder (toLazyText)
-- import Text.Parsec
-- import Text.Printf (printf)
@ -78,6 +83,10 @@ import Hledger.Utils.Test
-- lowercase = map toLower
-- uppercase = map toUpper
-- | Pretty-print a JSON value.
jsonPrettyText :: Value -> TL.Text
jsonPrettyText = toLazyText . encodePrettyToTextBuilder
-- | Remove leading and trailing whitespace.
textstrip :: Text -> Text
textstrip = textlstrip . textrstrip

View File

@ -4,7 +4,7 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
-- hash: f5d891a2f435cece44dd66f1ca32e8e55fde986a4129a443d3de60ab6f65b5e3
-- hash: d8c943c6b632e6b0cf34a564809ef96869541c54de93613e7103ec87fadb4e33
name: hledger-lib
version: 1.17.99
@ -111,6 +111,7 @@ library
Decimal >=0.5.1
, Glob >=0.9
, aeson
, aeson-pretty
, ansi-terminal >=0.6.2.3
, array
, base >=4.9 && <4.15
@ -162,6 +163,7 @@ test-suite doctest
Decimal >=0.5.1
, Glob >=0.7
, aeson
, aeson-pretty
, ansi-terminal >=0.6.2.3
, array
, base >=4.9 && <4.15
@ -216,6 +218,7 @@ test-suite unittest
Decimal >=0.5.1
, Glob >=0.9
, aeson
, aeson-pretty
, ansi-terminal >=0.6.2.3
, array
, base >=4.9 && <4.15

View File

@ -47,6 +47,7 @@ dependencies:
- base >=4.9 && <4.15
- base-compat-batteries >=0.10.1 && <0.12
- aeson
- aeson-pretty
- ansi-terminal >=0.6.2.3
- array
- blaze-markup >=0.5.1