Skip to content

Commit 539ff6b

Browse files
committed
Merge pull request #8 from cblanc/tighter_outcode_regex
Tighten outcode regex
2 parents 70e358b + dab6ca0 commit 539ff6b

File tree

12 files changed

+347
-6
lines changed

12 files changed

+347
-6
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
language: node_js
22
node_js:
33
- "iojs"
4+
- "5.0"
5+
- "4.0"
46
- "0.12"
57
- "0.11"
68
- "0.10"

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,18 @@ postcode.sector() // => "EC1V 9"
3131
postcode.unit() // => "LB"
3232
```
3333

34-
Misc. Class Methods include
34+
### Method Overview
35+
36+
| Postcode | .outcode() | .incode() | .area() | .district() | .subDistrict() | .sector() | .unit() |
37+
|----------|------------|-----------|---------|-------------|----------------|-----------|---------|
38+
| AA9A 9AA | AA9A | 9AA | AA | AA9 | AA9A | AA9A 9 | AA |
39+
| A9A 9AA | A9A | 9AA | A | A9 | A9A | A9A 9 | AA |
40+
| A9 9AA | A9 | 9AA | A | A9 | null | A9 9 | AA |
41+
| A99 9AA | A99 | 9AA | A | A99 | null | A99 9 | AA |
42+
| AA9 9AA | AA9 | 9AA | AA | AA9 | null | AA9 9 | AA |
43+
| AA99 9AA | AA99 | 9AA | AA | AA99 | null | AA99 9 | AA |
44+
45+
### Misc. Class Methods include
3546

3647
```
3748
Postcode.validOutcode(outcode)
@@ -74,7 +85,7 @@ The postcode sector is made up of the postcode district, the single space, and t
7485

7586
### Unit
7687

77-
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".
88+
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 "NY" (from "SW1W 0NY"), "GZ" (from "PO16 7GZ"), "HF" (from "GU16 7HF"), or "JQ" (from "L1 8JQ").
7889

7990
Sources:
8091

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"use strict";
22

3-
var validationRegex = /^[a-z][a-z\d]{1,3}\s*?\d[a-z]{2}$/i,
3+
var validationRegex = /^[a-z]{1,2}\d[a-z\d]?\s*\d[a-z]{2}$/i,
44
incodeRegex = /\d[a-z]{2}$/i,
5-
validOutcodeRegex = /^[a-z][a-z\d]{1,3}$/i,
5+
validOutcodeRegex = /^[a-z]{1,2}\d[a-z\d]?$/i,
66
areaRegex = /^[a-z]{1,2}/i,
77
districtSplitRegex = /^([a-z]{1,2}\d)([a-z])$/i,
8-
sectorRegex = /^[a-z][a-z\d]{1,3}\s*?\d/i,
8+
sectorRegex = /^[a-z]{1,2}\d[a-z\d]?\s*\d/i,
99
unitRegex = /[a-z]{2}$/i;
1010

1111
function isValidPostcode (postcode) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postcode",
3-
"version": "0.2.4",
3+
"version": "0.2.5",
44
"description": "UK Postcode helper methods",
55
"main": "index.js",
66
"directories": {

tests/data/areas.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,54 @@
4747
{
4848
"base" : "BT358GE",
4949
"expected" : "BT"
50+
},
51+
{
52+
"base": "AA9A 9AA",
53+
"expected": "AA"
54+
},
55+
{
56+
"base": "A9A 9AA",
57+
"expected": "A"
58+
},
59+
{
60+
"base": "A9 9AA",
61+
"expected": "A"
62+
},
63+
{
64+
"base": "A99 9AA",
65+
"expected": "A"
66+
},
67+
{
68+
"base": "AA9 9AA",
69+
"expected": "AA"
70+
},
71+
{
72+
"base": "AA99 9AA",
73+
"expected": "AA"
74+
},
75+
{
76+
"base": "AA9A9AA",
77+
"expected": "AA"
78+
},
79+
{
80+
"base": "A9A9AA",
81+
"expected": "A"
82+
},
83+
{
84+
"base": "A99AA",
85+
"expected": "A"
86+
},
87+
{
88+
"base": "A999AA",
89+
"expected": "A"
90+
},
91+
{
92+
"base": "AA99AA",
93+
"expected": "AA"
94+
},
95+
{
96+
"base": "AA999AA",
97+
"expected": "AA"
5098
}
5199
]
52100
}

tests/data/districts.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,58 @@
6363
{
6464
"base" : "N1C 0AB",
6565
"expected" : "N1"
66+
},
67+
{
68+
"base": "AA9A 9AA",
69+
"expected": "AA9"
70+
},
71+
{
72+
"base": "A9A 9AA",
73+
"expected": "A9"
74+
},
75+
{
76+
"base": "A9 9AA",
77+
"expected": "A9"
78+
},
79+
{
80+
"base": "A99 9AA",
81+
"expected": "A99"
82+
},
83+
{
84+
"base": "AA9 9AA",
85+
"expected": "AA9"
86+
},
87+
{
88+
"base": "AA99 9AA",
89+
"expected": "AA99"
90+
},
91+
{
92+
"base" : "N1C 0AB",
93+
"expected" : "N1"
94+
},
95+
{
96+
"base": "AA9A9AA",
97+
"expected": "AA9"
98+
},
99+
{
100+
"base": "A9A9AA",
101+
"expected": "A9"
102+
},
103+
{
104+
"base": "A99AA",
105+
"expected": "A9"
106+
},
107+
{
108+
"base": "A999AA",
109+
"expected": "A99"
110+
},
111+
{
112+
"base": "AA99AA",
113+
"expected": "AA9"
114+
},
115+
{
116+
"base": "AA999AA",
117+
"expected": "AA99"
66118
}
67119
]
68120
}

tests/data/incodes.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,54 @@
4747
{
4848
"base" : "BT358GE",
4949
"expected" : "8GE"
50+
},
51+
{
52+
"base": "AA9A 9AA",
53+
"expected": "9AA"
54+
},
55+
{
56+
"base": "A9A 9AA",
57+
"expected": "9AA"
58+
},
59+
{
60+
"base": "A9 9AA",
61+
"expected": "9AA"
62+
},
63+
{
64+
"base": "A99 9AA",
65+
"expected": "9AA"
66+
},
67+
{
68+
"base": "AA9 9AA",
69+
"expected": "9AA"
70+
},
71+
{
72+
"base": "AA99 9AA",
73+
"expected": "9AA"
74+
},
75+
{
76+
"base": "AA9A9AA",
77+
"expected": "9AA"
78+
},
79+
{
80+
"base": "A9A9AA",
81+
"expected": "9AA"
82+
},
83+
{
84+
"base": "A99AA",
85+
"expected": "9AA"
86+
},
87+
{
88+
"base": "A999AA",
89+
"expected": "9AA"
90+
},
91+
{
92+
"base": "AA99AA",
93+
"expected": "9AA"
94+
},
95+
{
96+
"base": "AA999AA",
97+
"expected": "9AA"
5098
}
5199
]
52100
}

tests/data/outcodes.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,54 @@
4747
{
4848
"base" : "BT358GE",
4949
"expected" : "BT35"
50+
},
51+
{
52+
"base": "AA9A 9AA",
53+
"expected": "AA9A"
54+
},
55+
{
56+
"base": "A9A 9AA",
57+
"expected": "A9A"
58+
},
59+
{
60+
"base": "A9 9AA",
61+
"expected": "A9"
62+
},
63+
{
64+
"base": "A99 9AA",
65+
"expected": "A99"
66+
},
67+
{
68+
"base": "AA9 9AA",
69+
"expected": "AA9"
70+
},
71+
{
72+
"base": "AA99 9AA",
73+
"expected": "AA99"
74+
},
75+
{
76+
"base": "AA9A9AA",
77+
"expected": "AA9A"
78+
},
79+
{
80+
"base": "A9A9AA",
81+
"expected": "A9A"
82+
},
83+
{
84+
"base": "A99AA",
85+
"expected": "A9"
86+
},
87+
{
88+
"base": "A999AA",
89+
"expected": "A99"
90+
},
91+
{
92+
"base": "AA99AA",
93+
"expected": "AA9"
94+
},
95+
{
96+
"base": "AA999AA",
97+
"expected": "AA99"
5098
}
5199
]
52100
}

tests/data/sectors.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,54 @@
4747
{
4848
"base" : "BT358GE",
4949
"expected" : "BT35 8"
50+
},
51+
{
52+
"base": "AA9A 9AA",
53+
"expected": "AA9A 9"
54+
},
55+
{
56+
"base": "A9A 9AA",
57+
"expected": "A9A 9"
58+
},
59+
{
60+
"base": "A9 9AA",
61+
"expected": "A9 9"
62+
},
63+
{
64+
"base": "A99 9AA",
65+
"expected": "A99 9"
66+
},
67+
{
68+
"base": "AA9 9AA",
69+
"expected": "AA9 9"
70+
},
71+
{
72+
"base": "AA99 9AA",
73+
"expected": "AA99 9"
74+
},
75+
{
76+
"base": "AA9A9AA",
77+
"expected": "AA9A 9"
78+
},
79+
{
80+
"base": "A9A9AA",
81+
"expected": "A9A 9"
82+
},
83+
{
84+
"base": "A99AA",
85+
"expected": "A9 9"
86+
},
87+
{
88+
"base": "A999AA",
89+
"expected": "A99 9"
90+
},
91+
{
92+
"base": "AA99AA",
93+
"expected": "AA9 9"
94+
},
95+
{
96+
"base": "AA999AA",
97+
"expected": "AA99 9"
5098
}
5199
]
52100
}

tests/data/sub-districts.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,30 @@
6363
{
6464
"base" : "N1C 0AB",
6565
"expected" : "N1C"
66+
},
67+
{
68+
"base": "AA9A 9AA",
69+
"expected": "AA9A"
70+
},
71+
{
72+
"base": "A9A 9AA",
73+
"expected": "A9A"
74+
},
75+
{
76+
"base": "A9 9AA",
77+
"expected": null
78+
},
79+
{
80+
"base": "A99 9AA",
81+
"expected": null
82+
},
83+
{
84+
"base": "AA9 9AA",
85+
"expected": null
86+
},
87+
{
88+
"base": "AA99 9AA",
89+
"expected": null
6690
}
6791
]
6892
}

0 commit comments

Comments
 (0)