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

formattr

v1.0.11

Published

A module to intelligently format names and US addresses

Downloads

10

Readme

formattr

A small node module to intelligently format names and addresses.

It's here to help out with annoying formatting issues like:

  • automatically handling Irish and Scottish names (like O'Brien and MacDonald)
  • deciding whether something is a name or an abbreviation (formatting both Jo and JJ correctly)
  • turning a non-formatted address into one that's nice to look at

Installation

node.js

Install using npm:

$ npm install formattr

Examples

First, make sure you have formattr installed and imported:

var formattr = require("formattr");

formatName

formatName( formatString, last, first, middle )

formatName allows you to specify a formatString (like '{last}, {first} {middle}') when passing the name arguments to define how you'd like the string returned. Use the full words (first, middle, last) to request the full name back. Use the first letter of the word (f, m, l) to request the initial of that name back along with a period.

formattr.formatName('{last}, {first} {m}', 'rambo', 'john', 'james')   // 'Rambo, John J.'

formattr.formatName('{first} {last}', 'mcclane', 'john')               // 'John McClane'

formattr.formatName('{f} {last}', 'plissken', 'snake')                 // 'S. Plissken'

formattr.formatName('{last}. {first} {last}.', 'bond', 'james')        // 'Bond. James Bond.'

formattr.formatName('I am {last}.', 'spartacus')                       // 'I am Spartacus.'

formatNamePart

formatNamePart( input )

formatNamePart is for when you're dealing with just a single part of a name (like a last name). It'll apply casing logic to the input string and return it.

formattr.formatNamePart('ty')       // 'Ty'

formattr.formatNamePart('jj')       // 'JJ'

formattr.formatNamePart('jAmEs')    // 'James'

formatAddress

formatAddress( input )

formatAddress will format an address string and properly case cardinal/ordinal directions (like N and NW) and all US state abbreviations.

formattr.formatAddress('5567 sw nakatomi plaza las angeles, ca 90064')  
                    // '5567 SW Nakatomi Plaza Las Angeles, CA 90064'

formattr.formatAddress('123 N fake ST springfield, il 62701')
                    // '123 N Fake St Springfield, IL 62701'

titleCase

titleCase( input )

titleCase will format an address string in title case without applying any additional logic.

formattr.titleCase('this is a string')  // 'This Is A String'

Tests

To run the included tests, execute this from the root of the repository:

npm test

Disclaimer

This is still early code and is subject to bugs and changes. Please thoroughly test it before relying too heavily on it.

Issues

If you have a feature request or bug, please feel free to submit it as an issue

Contributing

If you feel like contributing to formattr, please do!