### Install Dependencies (Shell)
Source: https://github.com/ldwonday/zh-address-parse/blob/master/README.md
Command to install the project's dependencies using npm. This is a prerequisite for running development commands or building the project.
```shell
$ npm install
```
--------------------------------
### Initialize and Use AddressParse with Options (JavaScript)
Source: https://github.com/ldwonday/zh-address-parse/blob/master/README.md
Shows how to import AddressParse from a local file and instantiate it with various options. This example details the available configuration parameters like 'type', 'textFilter', 'nameMaxLength', and 'extraGovData', and explains the structure of the expected parse result.
```javascript
import AddressParse from './dist/zh-address-parse.min.js'
// options为可选参数,不传默认使用正则查找
const options = {
type: 0, // 哪种方式解析,0:正则,1:树查找
textFilter: [], // 预清洗的字段
nameMaxLength: 4, // 查找最大的中文名字长度
extraGovData: { city: [{ name: 'name', code: 'code', provinceCode: 'provinceCode' }], province: [{ name: 'name', code: 'code' }], area: [{ name: 'name', code: 'code', provinceCode: 'provinceCode', cityCode: 'cityCode' }] }
}
// type参数0表示使用正则解析,1表示采用树查找, textFilter地址预清洗过滤字段。
const parseResult = AddressParse('your address', options)
// The parseResult is an object contain { province: '', name: '', city: '', area: '', detail: '', phone: '', postalCode: '' }
```
--------------------------------
### Install and Import AddressParse (JavaScript)
Source: https://github.com/ldwonday/zh-address-parse/blob/master/README.md
Demonstrates how to install the 'zh-address-parse' package using npm and import the AddressParse class in a JavaScript project. This is the standard way to integrate the library into your application.
```bash
npm i zh-address-parse -s
```
```javascript
import AddressParse from 'zh-address-parse'
```
--------------------------------
### Start Development Server (Shell)
Source: https://github.com/ldwonday/zh-address-parse/blob/master/README.md
Command to start the local webpack development server. This enables live reloading and autocompilation for a faster development workflow.
```shell
$ npm run dev
```
--------------------------------
### Using AddressParse via Script Tag (HTML/JavaScript)
Source: https://github.com/ldwonday/zh-address-parse/blob/master/README.md
Illustrates how to include the AddressParse library using a script tag in an HTML file and then use the global `window.ZhAddressParse` function. This example demonstrates event handling for input fields to trigger address parsing and logging the results to the console, as well as updating the DOM.
```html
```
--------------------------------
### Browser UMD Usage with zh-address-parse
Source: https://context7.com/ldwonday/zh-address-parse/llms.txt
Demonstrates how to use the zh-address-parse library directly in browsers via a script tag, utilizing the UMD format which exposes a global `ZhAddressParse` function. This example includes UI elements for input and displaying results.
```html
Address Parse Demo
```
--------------------------------
### TypeScript Address Parsing and Integration
Source: https://context7.com/ldwonday/zh-address-parse/llms.txt
Shows how to integrate the zh-address-parse library into TypeScript projects, leveraging type definitions for enhanced development experience and type safety. Includes examples of basic parsing, using typed options, custom type guards, generic functions for processing lists of items, and type-safe custom government data.
```typescript
import AddressParse from 'zh-address-parse'
// Type definitions are automatically imported from index.d.ts
// Basic usage with type inference
const result = AddressParse('广东省深圳市福田区华强北路188号 李明 13111111111')
// result type is automatically inferred as ParseResult
console.log(result.province) // string
console.log(result.city) // string
console.log(result.area) // string
console.log(result.detail) // string
console.log(result.name) // string
console.log(result.phone) // string
console.log(result.postalCode) // string
// Using typed options
const options: typeof AddressParse extends (addr: string, opts?: infer O) => any ? O : never = {
type: 0, // 0 | 1
textFilter: ['电话', '收货人'],
nameMaxLength: 4,
extraGovData: {
area: [{
code: '440305',
name: '前海新区',
cityCode: '440300',
provinceCode: '440000'
}]
}
}
const result2 = AddressParse('深圳市前海新区 李明 13800000000', options)
// Custom type guards
interface Order {
id: number
rawAddress: string
parsedAddress?: ReturnType
}
function parseOrder(order: Order): Order {
return {
...order,
parsedAddress: AddressParse(order.rawAddress)
}
}
// Generic parsing function
function parseAddressList(
items: T[]
): (T & { parsed: ReturnType })[] {
return items.map(item => ({
...item,
parsed: AddressParse(item.address)
}))
}
const orders = [
{ id: 1, address: '广东省深圳市福田区华强北路188号 李明 13111111111' },
{ id: 2, address: '北京市朝阳区建国路88号 张先生 15912345678' }
]
const parsedOrders = parseAddressList(orders)
parsedOrders.forEach(order => {
console.log(`Order ${order.id}:`, order.parsed.province, order.parsed.city)
})
// Type-safe extra government data
interface CustomGovData {
code: string
provinceCode?: string
cityCode?: string
name: string
}
const customAreas: CustomGovData[] = [
{
code: '440305',
name: '前海新区',
cityCode: '440300',
provinceCode: '440000'
}
]
const result3 = AddressParse('深圳市前海新区 李明 13800000000', {
extraGovData: { area: customAreas }
})
```
--------------------------------
### Build Application (Shell)
Source: https://github.com/ldwonday/zh-address-parse/blob/master/README.md
Command to build the project for deployment. This typically bundles and optimizes the code for production use.
```shell
$ npm run build
```
--------------------------------
### Node.js CommonJS Address Parsing
Source: https://context7.com/ldwonday/zh-address-parse/llms.txt
Demonstrates how to import and use the zh-address-parse library in Node.js applications using CommonJS require syntax. It covers basic parsing, setting up an Express.js API endpoint for address parsing, batch processing multiple addresses, and integrating with a MySQL database to normalize addresses.
```javascript
// CommonJS require
const AddressParse = require('zh-address-parse')
// Parse address in Node.js
const result = AddressParse('广东省深圳市福田区华强北路188号 李明 13111111111')
console.log(result)
// {
// province: '广东省',
// city: '深圳市',
// area: '福田区',
// detail: '华强北路188号',
// name: '李明',
// phone: '13111111111',
// postalCode: ''
// }
// Express.js API endpoint
const express = require('express')
const app = express()
app.use(express.json())
app.post('/api/parse-address', (req, res) => {
const { address, options } = req.body
try {
const result = AddressParse(address, options)
res.json({
success: true,
data: result
})
} catch (error) {
res.status(400).json({
success: false,
error: error.message
})
}
})
app.listen(3000, () => {
console.log('Address parsing API running on port 3000')
})
// Batch processing
const addresses = [
'广东省深圳市福田区华强北路188号 李明 13111111111',
'北京市朝阳区建国路88号 张先生 15912345678',
'上海市浦东新区陆家嘴环路1000号 王小姐 13800000000'
]
const results = addresses.map(addr => AddressParse(addr))
console.log('Batch results:', results)
// Database integration example
const mysql = require('mysql2/promise')
async function normalizeAddresses() {
const connection = await mysql.createConnection({
host: 'localhost',
user: 'root',
database: 'ecommerce'
})
const [rows] = await connection.execute(
'SELECT id, raw_address FROM orders WHERE address_parsed = 0'
)
for (const row of rows) {
const parsed = AddressParse(row.raw_address)
await connection.execute(
`UPDATE orders SET
province = ?, city = ?, area = ?,
detail = ?, recipient_name = ?,
phone = ?, postal_code = ?,
address_parsed = 1
WHERE id = ?`,
[
parsed.province, parsed.city, parsed.area,
parsed.detail, parsed.name,
parsed.phone, parsed.postalCode,
row.id
]
)
}
await connection.end()
console.log(`Normalized ${rows.length} addresses`)
}
```
--------------------------------
### Express.js API Endpoint
Source: https://context7.com/ldwonday/zh-address-parse/llms.txt
This section details how to set up a POST endpoint using Express.js to parse addresses. The endpoint expects an address string in the request body and returns the parsed address components.
```APIDOC
## POST /api/parse-address
### Description
This endpoint accepts an address string in the request body and returns a JSON object containing the parsed address components.
### Method
POST
### Endpoint
/api/parse-address
### Parameters
#### Request Body
- **address** (string) - Required - The address string to parse.
- **options** (object) - Optional - Options for the address parsing process.
### Request Example
```json
{
"address": "广东省深圳市福田区华强北路188号 李明 13111111111",
"options": {
"type": 0,
"textFilter": ["电话", "收货人"],
"nameMaxLength": 4
}
}
```
### Response
#### Success Response (200)
- **success** (boolean) - Indicates if the parsing was successful.
- **data** (object) - Contains the parsed address components if successful.
#### Response Example
```json
{
"success": true,
"data": {
"province": "广东省",
"city": "深圳市",
"area": "福田区",
"detail": "华强北路188号",
"name": "李明",
"phone": "13111111111",
"postalCode": ""
}
}
```
#### Error Response (400)
- **success** (boolean) - Indicates if the parsing failed.
- **error** (string) - Contains the error message if parsing failed.
#### Error Response Example
```json
{
"success": false,
"error": "Invalid address format"
}
```
```
--------------------------------
### Extending Government Data with zh-address-parse
Source: https://context7.com/ldwonday/zh-address-parse/llms.txt
Extends the built-in administrative region database with custom province, city, or area data. This is useful for special zones, development areas, or updated regions not in the official dataset, provided via the `extraGovData` option.
```javascript
import AddressParse from 'zh-address-parse'
// Add custom development zone
const result1 = AddressParse(
'深圳市前海新区桂湾片区 李明 13800000000',
{
extraGovData: {
area: [{
code: '440305',
name: '前海新区',
cityCode: '440300',
provinceCode: '440000'
}]
}
}
)
console.log(result1)
// {
// province: '广东省',
// city: '深圳市',
// area: '前海新区',
// detail: '桂湾片区',
// areaCode: '440305'
// }
// Add multiple custom areas
const result2 = AddressParse(
'北京市亦庄经济开发区科创十街 张三 15900000000',
{
extraGovData: {
area: [
{
code: '110302',
name: '亦庄经济开发区',
cityCode: '110000',
provinceCode: '110000'
}
]
}
}
)
// Add custom city (rare but possible)
const result3 = AddressParse(
'新疆生产建设兵团第一师阿拉尔市 王五 13700000000',
{
extraGovData: {
city: [{
code: '659001',
name: '阿拉尔市',
provinceCode: '650000'
}],
area: [{
code: '659001001',
name: '第一师',
cityCode: '659001',
provinceCode: '650000'
}]
}
}
)
// Complete custom hierarchy
const customData = {
extraGovData: {
province: [{
code: '990000',
name: '测试省'
}],
city: [{
code: '990100',
name: '测试市',
provinceCode: '990000'
}],
area: [{
code: '990101',
name: '测试区',
cityCode: '990100',
provinceCode: '990000'
}]
}
}
const result4 = AddressParse('测试省测试市测试区测试路100号 刘工 13900000000', customData)
console.log(result4)
```
--------------------------------
### AddressParse - Main parsing function
Source: https://context7.com/ldwonday/zh-address-parse/llms.txt
Parses an unstructured Chinese address string into structured components including province, city, area, phone number, postal code, recipient name, and detailed address. It supports different parsing types and custom configurations.
```APIDOC
## AddressParse - Main parsing function
### Description
Parses an unstructured Chinese address string into structured components including province, city, area, phone number, postal code, recipient name, and detailed address. It supports different parsing types and custom configurations.
### Method
Function Call
### Endpoint
N/A (JavaScript Library)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
- **addressString** (string) - Required - The unstructured Chinese address string to parse.
- **options** (object) - Optional - Configuration options for parsing:
- **type** (number) - Optional - Parsing algorithm type. `0` for regex (default), `1` for tree traversal.
- **textFilter** (array of strings) - Optional - Strings to filter out from the address.
- **nameMaxLength** (number) - Optional - Maximum length for the extracted name.
- **extraGovData** (object) - Optional - Additional government data for custom regions.
- **area** (array of objects) - Optional - Custom area data. Each object should have `code`, `name`, `cityCode`, and `provinceCode`.
### Request Example
```javascript
// Basic usage - regex parsing (default)
const result1 = AddressParse('广东省深圳市福田区华强北路188号 李明 13111111111')
// Using tree traversal algorithm
const result2 = AddressParse('北京市朝阳区建国路88号 SOHO现代城 张先生 15912345678', { type: 1 })
// Custom text filtering and name length
const result3 = AddressParse(
'電話: 13900000000 收货人:王小姐 地址:上海市浦东新区陆家嘴环路1000号 郵編:200120',
{
type: 0,
textFilter: ['電話', '郵編'],
nameMaxLength: 5
}
)
// Adding extra government data
const result4 = AddressParse('新区开发区工业园A区88号 刘工 18600000000', {
extraGovData: {
area: [{
code: '999999',
name: '开发区',
cityCode: '440300',
provinceCode: '440000'
}]
}
})
```
### Response
#### Success Response (Object)
- **province** (string) - The extracted province.
- **city** (string) - The extracted city.
- **area** (string) - The extracted district or area.
- **detail** (string) - The detailed address.
- **name** (string) - The extracted recipient name.
- **phone** (string) - The extracted phone number.
- **postalCode** (string) - The extracted postal code.
- **provinceCode** (string) - The administrative code for the province.
- **cityCode** (string) - The administrative code for the city.
- **areaCode** (string) - The administrative code for the area.
#### Response Example
```json
{
"province": "广东省",
"city": "深圳市",
"area": "福田区",
"detail": "华强北路188号",
"name": "李明",
"phone": "13111111111",
"postalCode": "",
"provinceCode": "440000",
"cityCode": "440300",
"areaCode": "440304"
}
```
```
--------------------------------
### Regex-Based Chinese Address Parsing (type: 0)
Source: https://context7.com/ldwonday/zh-address-parse/llms.txt
This snippet shows the default regex-based parsing algorithm for Chinese addresses. It incrementally matches province-city-area sequences and is suitable for most use cases requiring speed and good accuracy. It can handle incomplete addresses and Chinese municipalities.
```javascript
import AddressParse from 'zh-address-parse'
// Explicit regex mode (default)
const result1 = AddressParse('广东省深圳市福田区华强北路188号 李明 13111111111', {
type: 0
})
console.log(result1)
// {
// province: '广东省',
// city: '深圳市',
// area: '福田区',
// detail: '华强北路188号',
// name: '李明',
// phone: '13111111111'
// }
// Handles incomplete addresses - fills in parent regions
const result2 = AddressParse('福田区华强北路188号 李明 13111111111', { type: 0 })
console.log(result2)
// {
// province: '广东省', // Auto-filled
// city: '深圳市', // Auto-filled
// area: '福田区',
// detail: '华强北路188号',
// name: '李明',
// phone: '13111111111'
// }
// Handles Chinese municipalities (直辖市)
const result3 = AddressParse('北京市朝阳区建国路88号 张三 15900000000', { type: 0 })
console.log(result3)
// {
// province: '北京市',
// city: '北京市', // Same as province for municipalities
// area: '朝阳区',
// detail: '建国路88号'
// }
// Handles messy spacing and ordering
const result4 = AddressParse('13800000000 王五 科技园 南山区 深圳市 广东省', {
type: 0
})
console.log(result4)
// {
// province: '广东省',
// city: '深圳市',
// area: '南山区',
// detail: '科技园',
// name: '王五',
// phone: '13800000000'
// }
```
--------------------------------
### Tree Traversal Chinese Address Parsing (type: 1)
Source: https://context7.com/ldwonday/zh-address-parse/llms.txt
This snippet demonstrates the tree traversal parsing algorithm for Chinese addresses. It is an alternative to regex parsing that traverses hierarchical province-city-area relationships, offering better accuracy for ambiguous addresses at a slight performance cost. It can also handle partial province/city names.
```javascript
import AddressParse from 'zh-address-parse'
// Tree traversal mode
const result1 = AddressParse('江苏省南京市玄武区中山路1号 李明 13800000000', {
type: 1
})
console.log(result1)
// {
// province: '江苏省',
// city: '南京市',
// area: '玄武区',
// detail: '中山路1号',
// name: '李明',
// phone: '13800000000'
// }
// Better at handling ambiguous district names
const result2 = AddressParse('朝阳区建国路88号 张三 15900000000', { type: 1 })
console.log(result2)
// Correctly identifies this could be Beijing Chaoyang or other cities with 朝阳区
// Uses hierarchical lookup for disambiguation
// Handles partial province/city names
const result3 = AddressParse('浙江杭州西湖区文三路 王五 13700000000', { type: 1 })
console.log(result3)
// {
// province: '浙江省', // Expands '浙江' to '浙江省'
// city: '杭州市', // Expands '杭州' to '杭州市'
// area: '西湖区',
// detail: '文三路'
// }
// Comparison: regex vs tree for ambiguous addresses
const address = '开发区工业路100号 刘工 13900000000'
const regexResult = AddressParse(address, { type: 0 })
const treeResult = AddressParse(address, { type: 1 })
console.log('Regex:', regexResult)
console.log('Tree:', treeResult)
// Tree mode may provide better results for ambiguous development zones
```
--------------------------------
### TypeScript Definition for GovData
Source: https://github.com/ldwonday/zh-address-parse/blob/master/README.md
Defines the structure of the `GovData` type used for providing extra province, city, or area data to the AddressParse library. This interface specifies the required and optional properties for each geographical data object.
```typescript
type GovData = {
code: string;
provinceCode?: string;
cityCode?: string;
name: string;
}
```
--------------------------------
### Custom Text Filtering with zh-address-parse
Source: https://context7.com/ldwonday/zh-address-parse/llms.txt
Pre-processes address strings to remove custom keywords and labels before parsing. This is useful for handling region-specific or platform-specific address formats by providing an array of strings to the `textFilter` option.
```javascript
import AddressParse from 'zh-address-parse'
// Remove common traditional Chinese labels
const result1 = AddressParse(
'電話:13800000000 收件人:李明 地址:广东省深圳市福田区华强北路188号',
{
textFilter: ['電話', '收件人']
}
)
console.log(result1)
// Labels are removed before parsing
// {
// province: '广东省',
// city: '深圳市',
// area: '福田区',
// detail: '华强北路188号',
// name: '李明',
// phone: '13800000000'
// }
// Remove platform-specific labels
const result2 = AddressParse(
'【收货地址】上海市浦东新区陆家嘴环路1000号 【联系人】张三 【联系方式】15900000000',
{
textFilter: ['【收货地址】', '【联系人】', '【联系方式】']
}
)
console.log(result2.detail) // '陆家嘴环路1000号'
// Remove company-specific fields
const result3 = AddressParse(
'Customer Name: 王五 Delivery Address: 北京市朝阳区建国路88号 Contact: 13700000000',
{
textFilter: ['Customer Name:', 'Delivery Address:', 'Contact:']
}
)
// Combine multiple filters
const result4 = AddressParse(
'備註:办公室 電話:13900000000 郵編:518000 深圳市南山区科技园',
{
textFilter: ['備註', '電話', '郵編', '办公室']
}
)
console.log(result4)
// All custom labels removed
```
--------------------------------
### Postal Code Extraction
Source: https://context7.com/ldwonday/zh-address-parse/llms.txt
Extracts 6-digit Chinese postal codes from address strings and removes them from the remaining address components.
```APIDOC
## Postal Code Extraction
### Description
Extracts 6-digit Chinese postal codes from address strings and removes them from the remaining address components. This functionality is integrated within the main `AddressParse` function.
### Method
Function Call within `AddressParse`
### Endpoint
N/A (JavaScript Library)
### Parameters
See `AddressParse` main function parameters.
### Request Example
```javascript
const r1 = AddressParse('100000 北京市东城区长安街1号 天安门 李明 13800000000')
console.log(r1.postalCode) // '100000'
console.log(r1.detail) // '长安街1号天安门'
const r2 = AddressParse('上海市浦东新区世纪大道1000号 200120 张三 15900000000')
console.log(r2.postalCode) // '200120'
console.log(r2.detail) // '世纪大道1000号'
// Without postal code
const r3 = AddressParse('深圳市福田区福华路 王五 13900000000')
console.log(r3.postalCode) // ''
// Multiple numbers - only valid 6-digit postal codes extracted
const r4 = AddressParse('518000 深圳市南山区科苑路15号科兴科学园 13800000000')
console.log(r4.postalCode) // '518000'
console.log(r4.detail) // '科苑路15号科兴科学园'
```
### Response
#### Success Response (Object)
- **postalCode** (string) - The extracted 6-digit postal code. Returns an empty string if no valid postal code is found.
- **detail** (string) - The detailed address string with the postal code removed.
```
--------------------------------
### Phone Number Extraction
Source: https://context7.com/ldwonday/zh-address-parse/llms.txt
Automatically detects and normalizes Chinese mobile phone numbers in various formats, supporting country codes, dashes, and spaces.
```APIDOC
## Phone Number Extraction
### Description
Automatically detects and normalizes Chinese mobile phone numbers in various formats, supporting country codes, dashes, and spaces. This functionality is integrated within the main `AddressParse` function.
### Method
Function Call within `AddressParse`
### Endpoint
N/A (JavaScript Library)
### Parameters
See `AddressParse` main function parameters.
### Request Example
```javascript
// Standard 11-digit mobile
const r1 = AddressParse('广东省广州市天河区 张三 13812345678 天河路100号')
console.log(r1.phone) // '13812345678'
// Phone with dashes
const r2 = AddressParse('深圳市南山区科技园 138-1234-5678 李四')
console.log(r2.phone) // '13812345678'
// Phone with spaces
const r3 = AddressParse('北京市 138 1234 5678 王五 朝阳区建国路')
console.log(r3.phone) // '13812345678'
// Phone with country code
const r4 = AddressParse('+86-13812345678 上海市徐汇区 赵六 漕溪北路88号')
console.log(r4.phone) // '13812345678'
// Phone with 86 prefix
const r5 = AddressParse('86-13812345678 杭州市西湖区文三路 钱七')
console.log(r5.phone) // '13812345678'
// All valid mobile prefixes (13x, 14x, 15x, 16x, 17x, 18x, 19x)
const r6 = AddressParse('19912345678 成都市武侯区 孙八 科华北路')
console.log(r6.phone) // '19912345678'
```
### Response
#### Success Response (string)
- **phone** (string) - The extracted and normalized phone number. Returns an empty string if no valid phone number is found.
```
--------------------------------
### Parse Chinese Address String - JavaScript
Source: https://context7.com/ldwonday/zh-address-parse/llms.txt
Parses an unstructured Chinese address string into structured components. Supports regex (default) or tree traversal parsing, with options for text filtering and custom government data. It extracts province, city, area, detail, name, phone, and postal code.
```javascript
import AddressParse from 'zh-address-parse'
// Basic usage - regex parsing (default)
const result1 = AddressParse('广东省深圳市福田区华强北路188号 李明 13111111111')
console.log(result1)
// {
// province: '广东省',
// city: '深圳市',
// area: '福田区',
// detail: '华强北路188号',
// name: '李明',
// phone: '13111111111',
// postalCode: '',
// provinceCode: '440000',
// cityCode: '440300',
// areaCode: '440304'
// }
// Using tree traversal algorithm for better accuracy
const result2 = AddressParse('北京市朝阳区建国路88号 SOHO现代城 张先生 15912345678', { type: 1 })
console.log(result2)
// {
// province: '北京市',
// city: '北京市',
// area: '朝阳区',
// detail: 'SOHO现代城建国路88号',
// name: '张先生',
// phone: '15912345678',
// postalCode: ''
// }
// Custom text filtering and name length
const result3 = AddressParse(
'電話: 13900000000 收货人:王小姐 地址:上海市浦东新区陆家嘴环路1000号 郵編:200120',
{
type: 0,
textFilter: ['電話', '郵編'], // Remove traditional Chinese labels
nameMaxLength: 5
}
)
console.log(result3)
// {
// province: '上海市',
// city: '上海市',
// area: '浦东新区',
// detail: '陆家嘴环路1000号',
// name: '王小姐',
// phone: '13900000000',
// postalCode: '200120'
// }
// Adding extra government data for custom regions
const result4 = AddressParse('新区开发区工业园A区88号 刘工 18600000000', {
extraGovData: {
area: [{
code: '999999',
name: '开发区',
cityCode: '440300',
provinceCode: '440000'
}]
}
})
```
--------------------------------
### Detect Chinese Recipient Names with zh-address-parse
Source: https://context7.com/ldwonday/zh-address-parse/llms.txt
This snippet demonstrates how to detect Chinese recipient names from addresses using a surname database and common titles. It automatically distinguishes names from street addresses and administrative divisions. Options can be provided to customize name length detection.
```javascript
const r1 = AddressParse('广东省深圳市福田区华强北路 李先生 13800000000')
console.log(r1.name) // '李先生'
const r2 = AddressParse('北京市朝阳区建国路 王小姐 15900000000')
console.log(r2.name) // '王小姐'
// Names matching Chinese surnames (百家姓)
const r3 = AddressParse('上海市黄浦区南京东路 张三 13700000000')
console.log(r3.name) // '张三'
const r4 = AddressParse('杭州市西湖区文三路 欧阳峰 18600000000')
console.log(r4.name) // '欧阳峰'
// Custom name length limit
const r5 = AddressParse('成都市武侯区科华北路 司马相如 13900000000', {
nameMaxLength: 6 // Allow longer names (default is 4)
})
console.log(r5.name) // '司马相如'
// Names with family titles
const r6 = AddressParse('广州市天河区天河路 李妈妈 13800000000')
console.log(r6.name) // '李妈妈'
const r7 = AddressParse('深圳市南山区 刘哥哥 15900000000 科技园')
console.log(r7.name) // '刘哥哥'
// Filters out false positives (streets, townships)
const r8 = AddressParse('北京市昌平区 回龙观街道 王五 13700000000')
console.log(r8.name) // '王五' (not '回龙观街道')
```
--------------------------------
### Extract Phone Number from Chinese Address - JavaScript
Source: https://context7.com/ldwonday/zh-address-parse/llms.txt
Automatically detects and normalizes Chinese mobile phone numbers in various formats, including those with country codes, dashes, and spaces. This functionality is integrated within the main AddressParse function.
```javascript
// The phone extraction is built into AddressParse
// It handles various phone formats automatically
// Standard 11-digit mobile
const r1 = AddressParse('广东省广州市天河区 张三 13812345678 天河路100号')
console.log(r1.phone) // '13812345678'
// Phone with dashes
const r2 = AddressParse('深圳市南山区科技园 138-1234-5678 李四')
console.log(r2.phone) // '13812345678'
// Phone with spaces
const r3 = AddressParse('北京市 138 1234 5678 王五 朝阳区建国路')
console.log(r3.phone) // '13812345678'
// Phone with country code
const r4 = AddressParse('+86-13812345678 上海市徐汇区 赵六 漕溪北路88号')
console.log(r4.phone) // '13812345678'
// Phone with 86 prefix
const r5 = AddressParse('86-13812345678 杭州市西湖区文三路 钱七')
console.log(r5.phone) // '13812345678'
// All valid mobile prefixes (13x, 14x, 15x, 16x, 17x, 18x, 19x)
const r6 = AddressParse('19912345678 成都市武侯区 孙八 科华北路')
console.log(r6.phone) // '19912345678'
```
--------------------------------
### Extract Postal Code from Chinese Address - JavaScript
Source: https://context7.com/ldwonday/zh-address-parse/llms.txt
Extracts 6-digit Chinese postal codes from address strings and automatically removes them from the detailed address component. This is handled by the AddressParse function.
```javascript
// Postal codes are automatically extracted and removed from detail
const r1 = AddressParse('100000 北京市东城区长安街1号 天安门 李明 13800000000')
console.log(r1.postalCode) // '100000'
console.log(r1.detail) // '长安街1号天安门'
const r2 = AddressParse('上海市浦东新区世纪大道1000号 200120 张三 15900000000')
console.log(r2.postalCode) // '200120'
console.log(r2.detail) // '世纪大道1000号'
// Without postal code
const r3 = AddressParse('深圳市福田区福华路 王五 13900000000')
console.log(r3.postalCode) // ''
// Multiple numbers - only valid 6-digit postal codes extracted
const r4 = AddressParse('518000 深圳市南山区科苑路15号科兴科学园 13800000000')
console.log(r4.postalCode) // '518000'
console.log(r4.detail) // '科苑路15号科兴科学园'
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.