npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hof-behaviour-address-lookup

v2.2.2

Published

A HOF Behaviour for a multi-step postcode lookup

Downloads

22

Readme

hof-behaviour-address-lookup

A HOF Behaviour for controlling a multi-step address lookup.

Usage

// steps.js

const AddressLookup = require('hof-behaviour-address-lookup');

module.exports = {
  '/step-1' {
    behaviours: AddressLookup({
      addressKey: 'address-field'
    })
  }
}

Options

  • addressKey - REQUIRED - the key used to store the formatted address after lookup
  • required - if set to a truthy value then the address is required. By default a user can pass through without entering an address.
  • apiSettings - settings to pass to the Model on init. Default MOJ lookup api expects hostname, authorization, paths.lookup and paths.validate
  • Model - a custom Model which exposes a fetch method (and validate if using api validation). Both fetch and validate are expected to return a Promise
  • validate - a map of validators to pass to the Model's validate method. The default implementation supports allowedCountries which is an Array of accepted countries. - for only English addresses use:
AddressLookup({
  addressKey: 'address',
  validate: {
    allowedCountries: ['England']
  }
});

Custom Model Integration

If you provide a custom model, you should provide a fetch method which returns a Promise and resolves with the data on a successful lookup, and rejects with an Error if the service is unavailable. In the case of the service being unavailable a message is shown and a textarea is shown for the address to be input manually.

When providing a custom validate function, this should also return a Promise which resolves on a success validation, and rejects with an error with status 418 if validation fails.

Locales

The following keys are expected to be defined in your translations file.

  • pages.address-lookup.edit - text to change the postcode once entered. Defaults to 'Change';
  • pages.address-lookup.cantfind - link text for manual entry if you cant find your address in the lookup. Defaults to 'I can\'t find the address in the list'
  • fields.{key}-postcode.label - Label for the postcode field when shown on the lookup and manual steps. Defaults to 'Postcode'
  • pages.address-lookup.postcode-api.not-found - Message to show if postcode not found. Defaults to 'Sorry – we couldn’t find any addresses for that postcode, enter your address manually'
  • pages.address-lookup.postcode-api.cant-connect - Message to show if unable to connect to the lookup service. Defaults to 'Sorry – we couldn’t connect to the postcode lookup service at this time, enter your address manually'
  • buttons.find-address - Postcode submit button text. Required.