forked from DamonOehlman/addressit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
58 lines (42 loc) · 1.46 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* jshint node: true */
'use strict';
/**
# addressit
AddressIt is a freeform street address parser, that is designed to take a
piece of text and convert that into a structured address that can be
processed in different systems.
The focal point of `addressit` is on the street parsing component, rather
than attempting to appropriately identify various states, counties, towns,
etc, as these vary from country to country fairly dramatically. These
details are instead put into a generic regions array that can be further
parsed based on your application needs.
## Example Usage
The following is a simple example of how address it can be used:
```js
var addressit = require('addressit');
// parse a made up address, with some slightly tricky parts
var address = addressit('Shop 8, 431 St Kilda Rd Melbourne');
```
The `address` object would now contain the following information:
```
{ text: '8/431 ST KILDA RD MELBOURNE',
parts: [],
unit: 8,
country: undefined,
number: 431,
street: 'ST KILDA RD',
regions: [ 'MELBOURNE' ] }
```
For more examples, see the tests.
## Reference
**/
/**
### addressit(input, opts?)
Run the address parser for the given input. Optional `opts` can be
supplied if you want to override the default (EN) parser.
**/
module.exports = function(input, opts) {
var parser = (opts || {}).parser || require('./parsers/en');
// parse the address
return parser(input, opts);
};