summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthomasjm <>2019-06-12 03:25:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2019-06-12 03:25:00 (GMT)
commitff10e53146c703743cebb9d8e4c3ee65c510a9d2 (patch)
tree90df53b7585689f4e20adf21d39e92a99bfe4e0d
parent75ee65b2f2335dca55ac32f92e5da53045c36b85 (diff)
version 0.2.0.0HEAD0.2.0.0master
-rw-r--r--aeson-typescript.cabal4
-rw-r--r--src/Data/Aeson/TypeScript/Formatting.hs8
-rw-r--r--src/Data/Aeson/TypeScript/Types.hs14
3 files changed, 19 insertions, 7 deletions
diff --git a/aeson-typescript.cabal b/aeson-typescript.cabal
index bf4fbb9..5ee5ecc 100644
--- a/aeson-typescript.cabal
+++ b/aeson-typescript.cabal
@@ -4,10 +4,10 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
--- hash: c6fb058c83889fc039a860d05177c52295c974f6ccb536cad58fdd015c161359
+-- hash: 74aae5bd5d3353838039530c9ce854fa79c1a282fa2d73d232a7d5677ad341e2
name: aeson-typescript
-version: 0.1.3.0
+version: 0.2.0.0
synopsis: Generate TypeScript definition files from your ADTs
description: Please see the README on Github at <https://github.com/codedownio/aeson-typescript#readme>
category: Text, Web, JSON
diff --git a/src/Data/Aeson/TypeScript/Formatting.hs b/src/Data/Aeson/TypeScript/Formatting.hs
index 4827295..d824cd1 100644
--- a/src/Data/Aeson/TypeScript/Formatting.hs
+++ b/src/Data/Aeson/TypeScript/Formatting.hs
@@ -13,11 +13,15 @@ formatTSDeclarations = formatTSDeclarations' defaultFormattingOptions
-- | Format a single TypeScript declaration. This version accepts a FormattingOptions object in case you want more control over the output.
formatTSDeclaration :: FormattingOptions -> TSDeclaration -> String
-formatTSDeclaration (FormattingOptions {numIndentSpaces}) (TSTypeAlternatives name genericVariables names) = [i|type #{name}#{getGenericBrackets genericVariables} = #{alternatives};|]
+formatTSDeclaration (FormattingOptions {..}) (TSTypeAlternatives name genericVariables names) =
+ [i|type #{typeNameModifier name}#{getGenericBrackets genericVariables} = #{alternatives};|]
where alternatives = T.intercalate " | " (fmap T.pack names)
-formatTSDeclaration (FormattingOptions {numIndentSpaces}) (TSInterfaceDeclaration interfaceName genericVariables members) = [i|interface #{interfaceName}#{getGenericBrackets genericVariables} {
+
+formatTSDeclaration (FormattingOptions {..}) (TSInterfaceDeclaration interfaceName genericVariables members) =
+ [i|interface #{modifiedInterfaceName}#{getGenericBrackets genericVariables} {
#{lines}
}|] where lines = T.intercalate "\n" $ fmap T.pack [(replicate numIndentSpaces ' ') <> formatTSField member <> ";"| member <- members]
+ modifiedInterfaceName = (\(i, name) -> i <> interfaceNameModifier name) . splitAt 1 $ interfaceName
-- | Format a list of TypeScript declarations into a string, suitable for putting directly into a @.d.ts@ file.
formatTSDeclarations' :: FormattingOptions -> [TSDeclaration] -> String
diff --git a/src/Data/Aeson/TypeScript/Types.hs b/src/Data/Aeson/TypeScript/Types.hs
index 4f95e65..e13951d 100644
--- a/src/Data/Aeson/TypeScript/Types.hs
+++ b/src/Data/Aeson/TypeScript/Types.hs
@@ -69,12 +69,20 @@ instance IsString (TSString a) where
-- * Formatting options
-data FormattingOptions = FormattingOptions {
- numIndentSpaces :: Int
+data FormattingOptions = FormattingOptions
+ { numIndentSpaces :: Int
-- ^ How many spaces to indent TypeScript blocks
+ , interfaceNameModifier :: String -> String
+ -- ^ Function applied to generated interface names
+ , typeNameModifier :: String -> String
+ -- ^ Function applied to generated type names
}
-defaultFormattingOptions = FormattingOptions 2
+defaultFormattingOptions = FormattingOptions
+ { numIndentSpaces = 2
+ , interfaceNameModifier = id
+ , typeNameModifier = id
+ }
-- | Convenience typeclass class you can use to "attach" a set of Aeson encoding options to a type.
class HasJSONOptions a where