packages feed

aeson-typescript 0.1.3.0 → 0.2.0.0

raw patch · 3 files changed

+19/−7 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Data.Aeson.TypeScript.TH: [interfaceNameModifier] :: FormattingOptions -> String -> String
+ Data.Aeson.TypeScript.TH: [typeNameModifier] :: FormattingOptions -> String -> String
- Data.Aeson.TypeScript.TH: FormattingOptions :: Int -> FormattingOptions
+ Data.Aeson.TypeScript.TH: FormattingOptions :: Int -> (String -> String) -> (String -> String) -> FormattingOptions

Files

aeson-typescript.cabal view
@@ -4,10 +4,10 @@ -- -- 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
src/Data/Aeson/TypeScript/Formatting.hs view
@@ -13,11 +13,15 @@  -- | 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
src/Data/Aeson/TypeScript/Types.hs view
@@ -69,12 +69,20 @@  -- * 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