Skip to content

Commit f820968

Browse files
committed
Fixed outcode identification
Bump version Added more tests Added more tests Added more tests
1 parent bb3911d commit f820968

5 files changed

Lines changed: 82 additions & 3 deletions

File tree

index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
"use strict";
22

33
var validationRegex = /^[a-z0-9]{1,4}\s?\d[a-z]{2}$/i,
4-
incodeRegex = /^[a-z0-9]{1,4}/i,
54
outcodeRegex = /\d[a-z]{2}$/i;
65

76
function isValidPostcode (postcode) {
87
return !!postcode.match(validationRegex);
98
}
109

1110
function parseIncode (postcode) {
12-
return postcode.match(incodeRegex)[0];
11+
return postcode.replace(outcodeRegex, "").replace(/\s/, "");
1312
}
1413

1514
function parseOutcode (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.1.1",
3+
"version": "0.1.2",
44
"description": "UK Postcode helper methods",
55
"main": "index.js",
66
"directories": {

tests/data/incode.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,30 @@
2323
{
2424
"base" : "BT35 8GE",
2525
"expected" : "BT35"
26+
},
27+
{
28+
"base" : "L278XY",
29+
"expected" : "L27"
30+
},
31+
{
32+
"base" : "NR103EZ",
33+
"expected" : "NR10"
34+
},
35+
{
36+
"base" : "RG45AY",
37+
"expected" : "RG4"
38+
},
39+
{
40+
"base" : "NE697AW",
41+
"expected" : "NE69"
42+
},
43+
{
44+
"base" : "SE232NF",
45+
"expected" : "SE23"
46+
},
47+
{
48+
"base" : "BT358GE",
49+
"expected" : "BT35"
2650
}
2751
]
2852
}

tests/data/normalisation.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
"base" : "NR10 3EZ",
99
"expected" : "NR10 3EZ"
1010
},
11+
{
12+
"base" : "NR10 3EZ",
13+
"expected" : "NR10 3EZ"
14+
},
15+
{
16+
"base" : "ZE1 0AA",
17+
"expected" : "ZE1 0AA"
18+
},
1119
{
1220
"base" : "NE69 7AW",
1321
"expected" : "NE69 7AW"
@@ -16,6 +24,30 @@
1624
"base" : "SE23 2NF",
1725
"expected" : "SE23 2NF"
1826
},
27+
{
28+
"base" : "L278XY",
29+
"expected" : "L27 8XY"
30+
},
31+
{
32+
"base" : "NR103EZ",
33+
"expected" : "NR10 3EZ"
34+
},
35+
{
36+
"base" : "NR103EZ",
37+
"expected" : "NR10 3EZ"
38+
},
39+
{
40+
"base" : "ZE10AA",
41+
"expected" : "ZE1 0AA"
42+
},
43+
{
44+
"base" : "NE697AW",
45+
"expected" : "NE69 7AW"
46+
},
47+
{
48+
"base" : "SE232NF",
49+
"expected" : "SE23 2NF"
50+
},
1951
{
2052
"base" : "Definitely wrong",
2153
"expected" : null

tests/data/outcode.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,30 @@
2323
{
2424
"base" : "BT35 8GE",
2525
"expected" : "8GE"
26+
},
27+
{
28+
"base" : "L278XY",
29+
"expected" : "8XY"
30+
},
31+
{
32+
"base" : "NR103EZ",
33+
"expected" : "3EZ"
34+
},
35+
{
36+
"base" : "RG45AY",
37+
"expected" : "5AY"
38+
},
39+
{
40+
"base" : "NE697AW",
41+
"expected" : "7AW"
42+
},
43+
{
44+
"base" : "SE232NF",
45+
"expected" : "2NF"
46+
},
47+
{
48+
"base" : "BT358GE",
49+
"expected" : "8GE"
2650
}
2751
]
2852
}

0 commit comments

Comments
 (0)