New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

tinyaddress

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tinyaddress

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

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
351
increased by29.52%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 28 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc