You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+40-6Lines changed: 40 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,19 +13,28 @@ Install with `npm install postcode`
13
13
14
14
Create an instance of Postcode to perform utility methods, like so
15
15
16
-
```
16
+
```javascript
17
17
var Postcode =require("postcode");
18
18
19
-
var postcode = new Postcode("id11qd");
19
+
var postcode =newPostcode("po167gz");
20
20
```
21
21
22
22
Perform simple validations, parsing and normalisation
23
23
24
-
```
24
+
```javascript
25
25
postcode.valid() // => True
26
-
postcode.outcode() // => "ID1"
27
-
postcode.incode() // => "1QD"
28
-
postcode.normalise() // => "ID1 1QD"
26
+
27
+
postcode.normalise() // => "PO16 7GZ"
28
+
29
+
postcode.outcode() // => "PO16"
30
+
31
+
postcode.incode() // => "7GZ"
32
+
33
+
postcode.area() // => "PO"
34
+
35
+
postcode.sector() // => "PO16 7"
36
+
37
+
postcode.unit() // => "GZ"
29
38
```
30
39
31
40
Misc. Class Methods include
@@ -34,6 +43,29 @@ Misc. Class Methods include
34
43
Postcode.validOutcode(outcode)
35
44
```
36
45
46
+
## Definitions
47
+
48
+
### Outcode (#outcode)
49
+
50
+
The outward code is the part of the postcode before the single space in the middle. It is between two and four characters long. A few outward codes are non-geographic, not divulging where mail is to be sent. Examples of outward codes include "L1", "W1A", "RH1", "RH10" or "SE1P".
51
+
52
+
### Inward Code (#inward)
53
+
54
+
The inward part is the part of the postcode after the single space in the middle. It is three characters long. The inward code assists in the delivery of post within a postal district. Examples of inward codes include "0NY", "7GZ", "7HF", or "8JQ".
55
+
56
+
### Postcode Area (#area)
57
+
58
+
The postcode area is part of the outward code. The postcode area is between one and two characters long and is all letters. Examples of postcode areas include "L" for Liverpool, "RH" for Redhill and "EH" Edinburgh. A postal area may cover a wide area, for example "RH" covers north Sussex, (which has little to do with Redhill historically apart from the railway links), and "BT" (Belfast) covers the whole of Northern Ireland.
59
+
60
+
### Postcode Sector (#sector)
61
+
62
+
The postcode sector is made up of the postcode district, the single space, and the first character of the inward code. It is between four and six characters long (including the single space). Examples of postcode sectors include "SW1W 0", "PO16 7", "GU16 7", or "L1 8", "CV1 4".
63
+
64
+
### Postcode Unit (#unit)
65
+
66
+
The postcode unit is two characters added to the end of the postcode sector. Each postcode unit generally represents a street, part of a street, a single address, a group of properties, a single property, a sub-section of the property, an individual organisation or (for instance Driver and Vehicle Licensing Agency) a subsection of the organisation. The level of discrimination is often based on the amount of mail received by the premises or business. Examples of postcode units include "SW1W 0NY", "PO16 7GZ", "GU16 7HF", or "L1 8JQ".
Postcodes cannot be validated just with a regular expression. Proper postcode validation requires having a full list of postcodes to check against. Relying on a regex will produce false postives/negatives.
45
77
78
+
A complete list of Postcodes can be obtained from the ONS Postcode Directory, which is updated every 3 months.
0 commit comments