File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11"use strict" ;
22
33var validationRegex = / ^ [ a - z 0 - 9 ] { 1 , 4 } \s ? \d [ a - z ] { 2 } $ / i,
4- incodeRegex = / ^ [ a - z 0 - 9 ] { 1 , 4 } / i,
54 outcodeRegex = / \d [ a - z ] { 2 } $ / i;
65
76function isValidPostcode ( postcode ) {
87 return ! ! postcode . match ( validationRegex ) ;
98}
109
1110function parseIncode ( postcode ) {
12- return postcode . match ( incodeRegex ) [ 0 ] ;
11+ return postcode . replace ( outcodeRegex , "" ) . replace ( / \s / , "" ) ;
1312}
1413
1514function parseOutcode ( postcode ) {
Original file line number Diff line number Diff line change 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" : {
Original file line number Diff line number Diff line change 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}
Original file line number Diff line number Diff line change 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"
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
Original file line number Diff line number Diff line change 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}
You can’t perform that action at this time.
0 commit comments