titlecase

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2021 License: MIT Imports: 2 Imported by: 1

README

titlecase GoDoc

🔡 Title case converter, supports multiple styles (AMA, AP, New York Times, Wikipedia etc).

Usage

View full documentation

package main

import (
	"log"

	"github.com/revett/titlecase"
)

func main() {
	s, err := titlecase.Convert("the lord of the rings")
	if err != nil {
		log.Fatal(err)
	}

	log.Println(s) // 2021/04/25 21:09:50 The Lord of the Rings
}

Further reading: What Is Title Case?

Dependencies

Documentation

Overview

titlecase is a package for converting strings to title case format, which is a style traditionally used for the titles of books, movies, songs and plays. The style is also often used for headlines in newspapers, essays, and blogs.

Rules

Generally, all words are capitalised apart from:

  • Articles (a, an, the)
  • Conjunctions (and, or, but)
  • Prepositions (in, on, for, up)

However the specifics of the rules depend on the chosen style as the title case format is not an agreed universal standard.

Styles

There are a number of different styles to choose from, each with their own ruleset:

  • AMA
  • AP
  • APA
  • Bluebook
  • Chicago
  • MLA
  • New York Times
  • Wikipedia

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert

func Convert(s string) (string, error)

Convert returns the provided string to title case, where all major words are capitalised and all minor words all lowercased.

Example (Book)
package main

import (
	"fmt"

	"github.com/revett/titlecase"
)

func main() {
	s, _ := titlecase.Convert("the catcher in the rye")
	fmt.Println(s)
}
Output:
The Catcher in the Rye
Example (Film)
package main

import (
	"fmt"

	"github.com/revett/titlecase"
)

func main() {
	s, _ := titlecase.Convert("the lord of the rings")
	fmt.Println(s)
}
Output:
The Lord of the Rings
Example (Play)
package main

import (
	"fmt"

	"github.com/revett/titlecase"
)

func main() {
	s, _ := titlecase.Convert("much ado about nothing")
	fmt.Println(s)
}
Output:
Much Ado About Nothing

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL