titlecase 0.1.0.1 → 0.1.0.2
raw patch · 7 files changed
+89/−27 lines, 7 filesdep ~basenew-component:exe:titlecase
Dependency ranges changed: base
Files
- Main.hs +10/−0
- README.md +10/−0
- shell.nix +34/−18
- src/Data/Text/Titlecase/Internal.hs +17/−7
- stack.yaml +5/−0
- tests/Test/Unit.hs +1/−1
- titlecase.cabal +12/−1
+ Main.hs view
@@ -0,0 +1,10 @@+module Main ( main ) where++import Data.Text ( pack )+import Data.Text.Titlecase+import System.Environment+import Text.Blaze+import Text.Blaze.Renderer.Pretty++main :: IO ()+main = getArgs >>= putStr . renderMarkup . toMarkup . titlecase . pack . unwords
+ README.md view
@@ -0,0 +1,10 @@+# Titlecase Library for Haskell++This library basically offers a rough but mostly working function `titlecase` to+take any Text string and capitalize it according to English Title Case. While the+Data.Text function `toTitle` simply capitalizes the first letter of every word,+this Data.Text.Titlecase `titlecase` function uses the list of common words to+not capitalize. It then respects the rule of capitalizing the first and last+words regardless.++On Hackage at <https://hackage.haskell.org/package/titlecase>.
shell.nix view
@@ -1,19 +1,35 @@-with (import <nixpkgs> {}).pkgs;-let pkg = haskellngPackages.callPackage- ({ mkDerivation, base, blaze-markup, cabal-install, git, semigroups- , stdenv, text, tasty, tasty-hunit, tasty-quickcheck }:- mkDerivation {- pname = "titlecase";- version = "0.1.0.1";- src = ./.;- buildDepends = [ base blaze-markup semigroups text ];- testDepends = [- base semigroups tasty tasty-hunit tasty-quickcheck text- ];- buildTools = [ cabal-install git ];- homepage = "https://github.com/nkaretnikov/titlecase";- description = "Convert English words to title case";- license = stdenv.lib.licenses.bsd3;- }) {};+{ nixpkgs ? import <nixpkgs> {}, compiler ? "default" }:++let++ inherit (nixpkgs) pkgs;++ f = { mkDerivation, base, blaze-markup, cabal-install, semigroups+ , stdenv, tasty , tasty-hunit, tasty-quickcheck, text+ }:+ mkDerivation {+ pname = "titlecase";+ version = "0.1.0.2";+ src = ./.;+ isLibrary = true;+ isExecutable = true;+ libraryHaskellDepends = [ base blaze-markup semigroups text ];+ executableHaskellDepends = [ base blaze-markup text ];+ testHaskellDepends = [+ base semigroups tasty tasty-hunit tasty-quickcheck text+ ];+ buildTools = [ cabal-install ];+ homepage = "https://github.com/nkaretnikov/titlecase";+ description = "Convert English words to title case";+ license = stdenv.lib.licenses.bsd3;+ };++ haskellPackages = if compiler == "default"+ then pkgs.haskellPackages+ else pkgs.haskell.packages.${compiler};++ drv = haskellPackages.callPackage f {};+ in- pkg.env++ if pkgs.lib.inNixShell then drv.env else drv
src/Data/Text/Titlecase/Internal.hs view
@@ -97,13 +97,18 @@ <> threeWordPrepositions <> fourWordPrepositions +-- | The words to not capitalize come from+-- <https://en.wikipedia.org/wiki/List_of_English_prepositions Wikipedia primarily>,+-- but removing+-- <https://en.wikipedia.org/wiki/Conjunction_%28grammar%29#Subordinating_conjunctions subordinating conjunctions>+-- generally. oneWordPrepositions :: NonEmpty Preposition oneWordPrepositions = OneWordPreposition <$> fromList [ "a", "abaft", "abeam", "aboard", "about", "above", "absent", "across"- , "afore", "after", "against", "along", "alongside", "amid", "amidst"- , "among", "amongst", "an", "anenst", "apropos", "apud", "around", "as"+ , "afore", "against", "along", "alongside", "amid", "amidst"+ , "among", "amongst", "an", "anenst", "apropos", "apud", "around" , "aside", "astride", "at", "athwart", "atop"- , "barring", "before", "behind", "below", "beneath", "beside", "besides"+ , "barring", "behind", "below", "beneath", "beside", "besides" , "between", "beyond", "but", "by" , "chez", "circa", "concerning", "considering" , "despite", "down", "during"@@ -117,7 +122,12 @@ , "pace", "past", "per", "plus", "pro" , "qua" , "regarding", "round"- , "sans", "save", "since", "than", "through"+ , "sans", "save", "through"+ , "throughout", "till", "times"+ , "to", "toward", "towards", "under", "underneath"+ , "unlike", "unto", "up", "upon", "versus", "vs.", "vs", "v."+ , "via", "vice", "vis-à-vis", "w/", "within", "w/in", "w/i", "without"+ , "w/o", "worth" ] twoWordPrepositions :: NonEmpty Preposition@@ -125,7 +135,7 @@ [ ("according", "to"), ("ahead", "of"), ("apart", "from"), ("as", "for") , ("as", "of"), ("as", "per"), ("as", "regards"), ("aside", "from") , ("astern", "of")- , ("back", "to"), ("because", "of")+ , ("back", "to") , ("close", "to") , ("due", "to") , ("except", "for")@@ -144,8 +154,8 @@ threeWordPrepositions :: NonEmpty Preposition threeWordPrepositions = uncurry3 ThreeWordPreposition <$> fromList- [ ("as", "far", "as"), ("as", "long", "as"), ("as", "opposed", "to")- , ("as", "soon", "as"), ("as", "well", "as")+ [ ("as", "opposed", "to")+ , ("as", "well", "as") , ("by", "means", "of"), ("by", "virtue", "of") , ("in", "accordance", "with"), ("in", "addition", "to") , ("in", "case", "of"), ("in", "front", "of"), ("in", "lieu", "of")
+ stack.yaml view
@@ -0,0 +1,5 @@+flags: {}+packages:+- '.'+extra-deps: []+resolver: lts-3.6
tests/Test/Unit.hs view
@@ -41,7 +41,7 @@ testFirst t = testTitlecase $ toTitleFirst t <#> "Is First, so It Is Capitalized" testLast t = testTitlecase $ "This Sentence Capitalizes" <#> toTitleLast t-testIgnored t = testTitlecase $ "This Sentence Keeps" <#> t <#> "as Is"+testIgnored t = testTitlecase $ "This Sentence Keeps" <#> t <#> "As Is" articleFirst, articleLast, articleIgnored :: TestTree articleFirst = testCase "article is first" $ mapM_ (testFirst . unArticle) Titlecase.articles
titlecase.cabal view
@@ -1,5 +1,5 @@ name: titlecase-version: 0.1.0.1+version: 0.1.0.2 license: BSD3 license-file: LICENSE author: Nikita Karetnikov@@ -19,7 +19,9 @@ extra-source-files: .gitignore+ README.md shell.nix+ stack.yaml source-repository head type: git@@ -35,6 +37,15 @@ , blaze-markup , semigroups , text++executable titlecase+ default-language: Haskell2010+ main-is: Main.hs+ ghc-options: -Wall+ build-depends: base < 5+ , blaze-markup+ , text+ , titlecase test-suite test default-language: Haskell2010