11"use strict" ;
22
33var validationRegex = / ^ [ a - z 0 - 9 ] { 1 , 4 } \s * ?\d [ a - z ] { 2 } $ / i,
4- outcodeRegex = / \d [ a - z ] { 2 } $ / i;
4+ incodeRegex = / \d [ a - z ] { 2 } $ / i;
55
66function isValidPostcode ( postcode ) {
77 return ! ! postcode . match ( validationRegex ) ;
88}
99
10- function parseIncode ( postcode ) {
11- return postcode . replace ( outcodeRegex , "" ) . replace ( / \s + / , "" ) ;
10+ function parseOutcode ( postcode ) {
11+ return postcode . replace ( incodeRegex , "" ) . replace ( / \s + / , "" ) ;
1212}
1313
14- function parseOutcode ( postcode ) {
15- return postcode . match ( outcodeRegex ) [ 0 ] ;
14+ function parseIncode ( postcode ) {
15+ return postcode . match ( incodeRegex ) [ 0 ] ;
1616}
1717
1818function Postcode ( rawPostcode ) {
@@ -45,7 +45,7 @@ Postcode.prototype.outcode = function () {
4545Postcode . prototype . normalise = function ( ) {
4646 if ( ! this . _valid ) return null ;
4747 if ( this . postcode ) return this . postcode ;
48- return [ this . incode ( ) , " " , this . outcode ( ) ] . join ( "" ) ;
48+ return [ this . outcode ( ) , " " , this . incode ( ) ] . join ( "" ) ;
4949}
5050
5151module . exports = Postcode ;
0 commit comments