Skip to the content

address-plusアドレスプラス

Parse, validate, format and compare addresses locally, add country modules and mount an optional native form field.

address-plus extends the parse-address style with typed results, validation, formatting and country modules. About the name

Contents

Reference · /in

parseIndianAddressfunction

Parses an address in India into the parts India Post lays out: who it is care of (careOf, from C/o, S/o, D/o, W/o), a building's name (building), the flat or shop (secUnitType and secUnitNum: Flat 4B), the floor, the house number (number: 12, 12/3, 12-A) and the street as written (street: MG Road), a landmark (place: Near City Mall), the area in locality, the city in city, the PIN code in zip (560038, with no space) and the state's code in state (KA), as written or from the PIN code. The state and the city stand before the PIN code.

Import it

import { parseIndianAddress } from "@johnmorrisdotca/address-plus/in";

Definition

function parseIndianAddress(text: string, options?: ParseOptions): ParsedAddress | null

Parameters

NameTypeDescription
textstring

The address as one string; commas and line breaks both separate its parts.

options (optional)ParseOptions

useSnakeCase gives snake_case keys; the other options are not used.

Returns

ParsedAddress | null

The parts found, with country IN, or null when the text is empty or holds nothing that makes it an address.

Examples

import { parseIndianAddress } from "@johnmorrisdotca/address-plus/in";

console.log(parseIndianAddress("12 MG Road, Indiranagar, Bengaluru, Karnataka 560038"));
// → {"number":"12","street":"MG Road","locality":"Indiranagar","city":"Bengaluru","state":"KA","zip":"560038","zipValid":true,"country":"IN"}
{
  number: '12',
  street: 'MG Road',
  locality: 'Indiranagar',
  city: 'Bengaluru',
  state: 'KA',
  zip: '560038',
  zipValid: true,
  country: 'IN'
}

What it prints (run when this page was built)

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/address-plus 1.10.2.