Simple tool providing midpoint postcode for an array of postcodes. Endpoints and methods provided by https://postcodes.io/
$ npm install midpoint-postcode-ukconst MidpointPostcode = require("midpoint-postcode-uk");
const myMidpointPostcode = new MidpointPostcode();
let postcodesArr = ["RG109NY", "SW40NH"];
myMidpointPostcode
.bringMidPointPostcode(postcodesArr)
.then(postcode => console.log(postcode));Method validates a postcode.
console.log(myMidpointPostcode.validate("RG109NY")); //true
console.log(myMidpointPostcode.validate("XXYYZZT")); //falseMethod returns midpoint postcode for the input postcode(s) array. Method ignores invalid postcodes and returns the midpoint postcode for the valid postcodes only. Postcode validation recommended prior to calling the function. Please see validation method above.
let postcodesArr = ["RG109NY", "SW40NH"];
myMidpointPostcode
.bringMidPointPostcode(postcodesArr)
.then(postcode => console.log(postcode)); //SL30BQFirst, install development dependencies:
$ npm install midpoint-postcode-ukThen, run the tests:
$ npm testPlease open an issue on this repo
Basri Dogan https://basridogan.com/
MIT licensed - see LICENSE file