servant-foreign: fix camelCase
Previous behaviour was a bit shouty (and dashes aren't allowed in JS variable names): camelCase ["one", "two", "thirty-three"] => "oneTWOTHIRTY-THREE" New behaviour: camelCase ["one", "two", "thirty-three"] => "oneTwoThirtythree"
This commit is contained in:
parent
aa2b56d08c
commit
f6ee02eb91
1 changed files with 6 additions and 4 deletions
|
@ -47,6 +47,7 @@ module Servant.Foreign
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Lens (makeLenses, (%~), (&), (.~), (<>~))
|
import Control.Lens (makeLenses, (%~), (&), (.~), (<>~))
|
||||||
|
import qualified Data.Char as C
|
||||||
import Data.Proxy
|
import Data.Proxy
|
||||||
import Data.Text
|
import Data.Text
|
||||||
import GHC.Exts (Constraint)
|
import GHC.Exts (Constraint)
|
||||||
|
@ -66,10 +67,11 @@ snakeCase = intercalate "_"
|
||||||
-- | Function name builder using the CamelCase convention.
|
-- | Function name builder using the CamelCase convention.
|
||||||
-- each part begins with an upper case character.
|
-- each part begins with an upper case character.
|
||||||
camelCase :: FunctionName -> Text
|
camelCase :: FunctionName -> Text
|
||||||
camelCase [] = ""
|
camelCase = camelCase' . Prelude.map (replace "-" "")
|
||||||
camelCase (p:ps) = concat $ p : camelCase' ps
|
where camelCase' [] = ""
|
||||||
where camelCase' [] = []
|
camelCase' (p:ps) = concat $ p : Prelude.map capitalize ps
|
||||||
camelCase' (r:rs) = toUpper r : camelCase' rs
|
capitalize "" = ""
|
||||||
|
capitalize name = C.toUpper (Data.Text.head name) `cons` Data.Text.tail name
|
||||||
|
|
||||||
type Arg = Text
|
type Arg = Text
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue