Skip to content

Commit 5c47737

Browse files
committed
Fixed incodes and outcodes
1 parent 9cb507f commit 5c47737

4 files changed

Lines changed: 8 additions & 8 deletions

File tree

index.js

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

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

66
function 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

1818
function Postcode (rawPostcode) {
@@ -45,7 +45,7 @@ Postcode.prototype.outcode = function () {
4545
Postcode.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

5151
module.exports = Postcode;

tests/unit.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe("Postcode normalisation", function () {
4343

4444
describe("Incode parsing", function () {
4545
before(function (done) {
46-
testData = fs.readFile(path.join(dataDir, "incode.json"), function (error, data) {
46+
testData = fs.readFile(path.join(dataDir, "incodes.json"), function (error, data) {
4747
if (error) throw error;
4848
testData = JSON.parse(data);
4949
done();
@@ -63,7 +63,7 @@ describe("Incode parsing", function () {
6363

6464
describe("Outcode parsing", function () {
6565
before(function (done) {
66-
testData = fs.readFile(path.join(dataDir, "outcode.json"), function (error, data) {
66+
testData = fs.readFile(path.join(dataDir, "outcodes.json"), function (error, data) {
6767
if (error) throw error;
6868
testData = JSON.parse(data);
6969
done();

0 commit comments

Comments
 (0)