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

tinyaddress

v1.2.0

Published

A tiny (~1.6KB) universal, zero-dependency localized address formatter for postal addresses

Downloads

1,933

Readme

tinyaddress · License version Check Coverage PRs

A tiny (~1.6KB), universal, zero-dependency localized address formatter for postal addresses.

This package uses address metadata from Google's Address Data Service to format postal addresses from all over the world.

Installation

$ npm install tinyaddress

or using yarn

$ yarn add tinyaddress

Usage

import { formatAddress } from "tinyaddress";

const address = formatAddress({
  name: "Mr John Smith",
  region: "New York",
  city: "Kingston",
  addressLines: ["132, My Street"],
  postalCode: "12401",
  countryCode: "US",
});

/* 
	["Mr John Smith",
	"132, My Street",
	"Kingston, New York 12401"]
*/

formatAddress returns an array of sorted lines which can then be joined to generate a string. This can be done automatically by passing string as options.output:

import { formatAddress } from "tinyaddress";

const address = formatAddress(
  {
    name: "Mr John Smith",
    region: "New York",
    city: "Kingston",
    addressLines: ["132, My Street"],
    postalCode: "12401",
    countryCode: "US",
  },
  { output: "string" }
);

/*
	"Mr John Smith
	132, My Street
	Kingston, New York 12401
*/

Properties

  • countryCode (required): An ISO 3166-2 country code for the given country. Only used to format the address and will not be included in it. Use the country field to add a country in the address.

  • name (optional): The name of the person.

  • organization (optional): The organization, firm, company, or institution at the address. addressLines (optional): A sorted array of address lines.

  • postalCode (optional): The postal code or ZIP code, also known as PIN code in India. city (optional): The city/town portion of the address.

  • country (optional): The country of the address. Will always be the last line in the address.

  • region (optional): The top-level administrative subdivision of the country. For example, this can be a state, a province, an oblast, or a prefecture. Also known as administrativeArea or district.

  • dependentLocality (optional): Dependent locality or sublocality within a city. For example, neighborhoods, boroughs, districts, or UK dependent localities.

  • sortingCode (optional): Sorting code system, such as the CEDEX system used in France.

Options

  • format (optional): local | latin The address format type, can be of type local or latin. Default is local. Some countries have a latin alternative.
  • output (optional): string | array The type of the output, default is a sorted array, but can be changed to string, which joins the array with '/n'.

Inspired by localized-address-format