Skip to content

Commit 50467a0

Browse files
committed
Document new methods
1 parent f0b7316 commit 50467a0

1 file changed

Lines changed: 40 additions & 6 deletions

File tree

README.md

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,28 @@ Install with `npm install postcode`
1313

1414
Create an instance of Postcode to perform utility methods, like so
1515

16-
```
16+
```javascript
1717
var Postcode = require("postcode");
1818

19-
var postcode = new Postcode("id11qd");
19+
var postcode = new Postcode("po167gz");
2020
```
2121

2222
Perform simple validations, parsing and normalisation
2323

24-
```
24+
```javascript
2525
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"
2938
```
3039

3140
Misc. Class Methods include
@@ -34,6 +43,29 @@ Misc. Class Methods include
3443
Postcode.validOutcode(outcode)
3544
```
3645

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".
67+
68+
Source: [Wikipedia](http://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom#Formatting)
3769

3870
## Testing
3971

@@ -43,6 +75,8 @@ Postcode.validOutcode(outcode)
4375

4476
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.
4577

78+
A complete list of Postcodes can be obtained from the ONS Postcode Directory, which is updated every 3 months.
79+
4680
## License
4781

4882
MIT

0 commit comments

Comments
 (0)