helpers

The helpers from this module are globally exported under the namespace helpers for use in your own application

Source:

Methods

(static) followNext(options, previousopt, callback) → {function}

Helper that can follow _links.next.href and returns a single response. The final returned result contains the _self URL of the first call and (if requested) the rateLimit of the last call. Basicly it is a wrapper for the requestApi.get-method.

Parameters:
Name Type Attributes Description
options Object

It is basicly the options-object from higher instances, however it must contain some additional keys as described below

Properties
Name Type Description
url String

The URL that must be requested of the first or next (when repeating) item in the collection

headers Object

Must at least contain the auth header, but can also contain other HTTP-headers that must be send

previous Object <optional>

May contain the previous fetched result from the API to extend

callback function

The callback as defined by the end-user

Since:
  • 1.3.0
Source:
Returns:
  • callback
Type
function

(static) mergeResults(source, destination, callback) → {function}

Helper that is able to merge two results in the _embedded-object from the API together in one single response. It is used within followNext(), however it may be useful in other circumstanses.

Parameters:
Name Type Description
source Object

The response that must be merged with the destination. It is assumed that this object contains a _embedded-object within it (like in the remote API response).

destination Object

The response that must incude the source object.

callback function

A callback that is returned when the merge is finished

Properties
Name Type Description
error Object

Returns an instance of a Error when something went wrong

mergedResult Object

The destination with the source merged in the _embedded-object.

Since:
  • 1.3.0
Source:
Returns:
  • callback
Type
function

(static) validatePostcodeP4(postcode) → {Boolean}

Returns if a postcode is P4-formatted (e.g. 1234)

Parameters:
Name Type Description
postcode String

The postcode that must be checked

Since:
  • 1.0.0
Source:
Returns:
  • True when the postcode is valid
Type
Boolean
Example
const postcodeApi = require('postcode-nl');
console.log(postcodeApi.helpers.validatePostcodeP4('1234')); // Shows 'true' in the console
console.log(postcodeApi.helpers.validatePostcodeP4('1234AB')); // Shows 'false' in the console

(static) validatePostcodeP6(postcode) → {Boolean}

Returns if a postcode is P6-formatted where spaces are not allowed (e.g. 1234AB)

Parameters:
Name Type Description
postcode String

The postcode that must be checked

Since:
  • 1.0.0
Source:
Returns:
  • True when the postcode is valid
Type
Boolean
Example
const postcodeApi = require('postcode-nl');
console.log(postcodeApi.helpers.validatePostcodeP6('1234')); // Shows 'false' in the console
console.log(postcodeApi.helpers.validatePostcodeP6('1234AB')); // Shows 'true' in the console