npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

smart-capitalize

v0.0.4

Published

A simple library to capitalize only words/strings without existing capital letters

Downloads

9

Readme

npm version

smart-capitalize

Every time PayPal sends me an email, they start off by addressing me in the following way:

Hi Gerard O'neill,

Obviously, this is not how I type my name. My last name is spelled O'Neill with a capital N. However, PayPal doesn't trust me to spell my own name correctly, so it runs a rudimentary capitalization function on my name, which results in it being spelled incorrectly.

This is why I made smart-capitalize.

Examples

It's a simple library with two functions:

  • capitalize()
  • capitalizeAll()

capitalize is meant to be used for only a single word, while capitalizeAll is for use with multiple words, such as with a name or a sentence/title.

The internal logic isn't super simple, but in practice, these functions will capitalize strings where there doesn't already exist an uppercase letter. Some examples:

capitalize('hello') === 'Hello' // capitalized
capitalize('this is a sentence.') === 'This is a sentence.' // capitalized first word only
capitalize("O'Neill") === "O'Neill" // no change

capitalizeAll('hello, how are you?') === 'Hello, How Are You?' // all words capitalized
capitalizeAll("that guy looks like leonardo da vinci lol") === "That Guy Looks Like Leonardo Da Vinci Lol" // all words capitalized, though technically still not correct
capitalizeAll("my name is Gerard O'Neill") === "my name is Gerard O'Neill" // no change

Installation

Using yarn:

yarn add smart-capitalize

Using npm:

npm i -S smart-capitalize

Usage

import { capitalize, capitalizeAll } from 'smart-capitalize'

console.log(capitalize('this is cool')) // 'This is cool'
console.log(capitalizeAll('this is cool too')) // 'This Is Cool Too'

I18n

The functions also do their best to work with non-English/non-Latin alphabets. Some sacrifices were made because of JavaScript's lack of Unicode property escapes, but it should work fairly well.

Disclaimer

It's worth stating that these are not perfect functions. It's impossible to know what should be capitalized and what shouldn't be, algorithmically-speaking. I would prefer that you never try to capitalize anything like somebody's name, but if you absolutely must, then this will give you something fairly sane for people who couldn't bothered to use the Shift key while leaving the rest of our names alone.