Giter VIP home page Giter VIP logo

ap-style-title-case's Introduction

ap-style-title-case

Build Coverage Downloads Size

Convert a value to AP/APA title case.

Contents

What is this?

This small package turns a sentence into title case.

When should I use this?

You can use this when you have short text of unknown casing and want to display it in a heading or so.

Install

This package is ESM only. In Node.js (version 14.14+, 16.0+), install with npm:

npm install ap-style-title-case

In Deno with esm.sh:

import {apStyleTitleCase} from 'https://esm.sh/ap-style-title-case@2'

In browsers with esm.sh:

<script type="module">
  import {apStyleTitleCase} from 'https://esm.sh/ap-style-title-case@2?bundle'
</script>

Use

import {apStyleTitleCase} from 'ap-style-title-case'

console.log(apStyleTitleCase('why sunless tanning is A hot trend'))
// 'Why Sunless Tanning Is a Hot Trend'

API

apStyleTitleCase(value[, options])

Convert a value (string) to title case (string) using AP/APA style.

options

Configuration (optional).

options.keepSpaces

Keep superfluous whitespace (boolean, default: false). Whitespace is turned into a space by default.

options.stopwords

List of stopwords (Array<string>, default: see below). When a lowercased word is included in this list, it will be used as lowercase. Otherwise words are capitalized.

Algorithm

  • always capitalize the first word, even if it’s a stop word
  • always capitalize the last word, even if it’s a stop word
  • lowercase these words: a, an, and, at, but, by, for, in, nor, of, on, or, so, the, to, up, yet

Many writers make the error of leaving to be verbs in lower case. Even though is, are, was, and be, are all short words, they should still be capitalized in a title because they are verbs.

When you write titles that contain prepositions, your word processor will likely tell you that you should leave words like with, about, and around lowercase. Defiantly look past the squiggly line indicating a potential error, and remember that in AP title case, prepositions with four or more letters should be capitalized.

These rules are the exact same for APA style, the only difference being that AP style does not recommend the use of title case for newspaper headlines, but rather sentence case.

References

Types

This package is fully typed with TypeScript. It exports the additional type Options.

Compatibility

This package is at least compatible with all maintained versions of Node.js. As of now, that is Node.js 14.14+ and 16.0+. It also works in Deno and modern browsers.

Contribute

Yes please! See How to Contribute to Open Source.

Security

This package is safe.

License

MIT © Zeke Sikelianos

ap-style-title-case's People

Contributors

foray1010 avatar retorquere avatar wooorm avatar zeke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

ap-style-title-case's Issues

Build error in the package

ERROR in ./~/ap-style-title-case/index.js
Module build failed: Error
    at new JS_Parse_Error (eval at <anonymous> (/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1547:18)
    at js_error (eval at <anonymous> (/node_modules/uglify-js/tools/node.js:28:1), <anonymous>:1555:11)

I've been trying to build the package in npm and keep getting the following error. Any ideas as to the issue?

Converting `ap-style-title-case` to use ES6 modules

Thank you for your simple but powerful package. It's my go-to JS library when having to work with various unformatted strings.

Can I request that your library is updated to use modern ES6 modules and namespacing? This would make it much nicer to integrate with JavaScript-heavy projects, as one could simply use the same syntax alongside other named imports, e.g. import { titleCase } from ... as opposed to the more cumbersome const titleCase = require(".../") approach.

If you no longer maintain this library - or aren't willing to implement this change - I could submit a PR. Alternatively I could fork the package and publish a new version on NPM. It's a small change but it's beneficial as I use this lib across so many different projects. Let me know if you are OK with my suggestions, and/or which project you would prefer.

Take care :)

AP versus APA: differences in capitalizing the last word of a title

Hi, I noticed that this project indicates that AP style and APA style have identical rules for title capitalization and thus treats the two interchangeably.

However, from this page, I found out that "AP, CMOS, MLA, the New York Times, and Wikipedia have a rule to always capitalize the last word of a title. AMA, APA, and Bluebook do not have such a rule, which means a preposition at the end of a title is lowercased in these styles (Be Careful What You Wish for)."

Could you add an option for us to include a preference on whether to capitalize the last words of titles, please? Thank you for all of your work on this project.

options.keepSpaces has no default value

recently updated to 1.1.1, and that brought the changes from a few months ago
with the way the keepSpaces option is handled.

in index.js, the option is checked:
const keep = options.keepSpaces

but if no value is passed in, then this errors.

seems like you either want
to use the opts object that is created,
const keep = opts.keepSpaces
or
check for undefined explicitly.
const keep = (typeof options.keepSpaces !== 'undefined') ? options.keepSpaces : 0

thoughts?

Doesn't capitalize an uppercase word

I've used this package in a project and noticed uppercase words are ignored, which is not ideal.

This is a bug or is this library not meant to capitalize uppercase words?

Screenshot 2019-04-18 at 11 45 26

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.