Skip to content

dewey92/purescript-symbol-case

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

purescript-symbol-case

Functions for manipulating type level strings (symbols).

Overview

I'm not even sure if this library is useful but imagine you have an external endpoint with undesirable label format (e.g in snake case) and you'd like to have'em in camel case.

import Record (rename)

type MovieResponse =
  { id :: MovieId
  , title :: String
  , poster_path :: Maybe String
  , adult :: Boolean
  , overview :: String
  , release_date :: String
  , popularity :: Number
  , vote_count :: Number
  , vote_average :: Number
  }

response :: MovieResponse

camelCaseKeys = rename (SProxy :: _ "poster_path") (SProxy :: _ "posterPath")
  >>> rename (SProxy :: _ "release_date") (SProxy :: _ "releaseDate")
  >>> rename (SProxy :: _ "vote_count") (SProxy :: _ "voteCount")
  >>> rename (SProxy :: _ "vote_average") (SProxy :: _ "voteAverage")

desired = camelCaseKeys response

Instead of converting them manually by hand, you can make use of this library to automatically convert them for you.

import Record.Case (toCamelRecord)

desired = toCamelRecord response

Examples

You could navigate to test/Main.purs for more examples.

⚠️ Limitation

Currently it supports only the ISO Latin Basic Alphabet (English letters). Suggestions and/or PRs are welcomed 🙂

About

Functions for manipulating type level strings (symbols)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published