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

@firstclasspostcodes/plugin

v1.0.4

Published

[//]: # "Comment"

Downloads

8

Readme

Firstclasspostcodes

Build, test and release

Our browser plugin is compatible with all modern browsers and IE9+ (polyfills required).

This simple to use plugin helps you to get started quickly, allowing you to add postcode lookup to any address form in minutes.

Documentation

See @firstclasspostcodes/plugin for detailed usage, guides and examples.

Installation

Add the plugin directly into your HTML with:

<script src="https://js.firstclasspostcodes.com/plugin/v1.0.4.js"></script>

Note on older browsers: You will need to use a polyfill service, the following example covers all of the required language features:

<script src="https://polyfill.io/v3/polyfill.min.js?features=Promise%2Cfetch%2CObject.assign%2Cdefault"></script>

Add the client library

We do not bundle the client library with the plugin, so you will need to add a separate script tag to require the JS client:

<script src="https://js.firstclasspostcodes.com/v1.5.1.js"></script>

All JS library versions are available on the @firstclasspostcodes/js releases page.

Security

Where the libary is loaded on pages including sensitive information, we recommend using the Subresource Integrity security feature.

Every version of the library is accompanied by an SRI hash file, the hash can be accessed directly using:

$ curl https://js.firstclasspostcodes.com/plugin/v1.0.4.sri.txt # => "sha256-45tfd... sha384-43567ytr..."

You can then update the above <script> tag, adding the integrity attribute:

<script src="https://js.firstclasspostcodes.com/plugin/v1.0.4.js"
        integrity="sha256-45tfd... sha384-43567ytr..."
        crossorigin="anonymous"></script>

Usage

You need to configure the plugin to use your API Key which is available on your dashboard. Below is a minimal working setup, you can see more guides on how to better customise the plugin by viewing the documentation.

<div id="postcode-lookup-form"></div>
<form>
  <div>
    <label for="address-line-1">Address Line 1</label>
    <input name="address-line-1" type="text" data-address-line1 />
  </div>
  <div>
    <label for="address-line-2">Address Line 2</label>
    <input name="address-line-2" type="text" data-address-line2 />
  </div>
  <div>
    <label for="county">County</label>
    <input name="county" type="text" data-address-locality />
  </div>
  <div>
    <label for="city">City</label>
    <input name="city" type="text" data-address-county />
  </div>
  <div>
    <label for="postcode">Postcode</label>
    <input name="postcode" type="text" data-address-postcode />
  </div>
</form>

<script>
  FirstclasspostcodesPlugin(
    document.getElementById('postcode-lookup-form'), 
    {
      apiKey: '111111111111',
    },
  );  
</script>

Configuration

The plugin can be initialized with the same configuration overrides that you can supply for the @firstclasspostcodes/js library using the apiOverrides property (an example of its usage is below).

If you're running the mock service docker container. You can configure the plugin to talk to it using the example below:

<script>
  FirstclasspostcodesPlugin(
    document.getElementById('postcode-lookup-form'), 
    {
      apiKey: '111111111111', 
      apiOverrides: {
        endpoint: 'http://localhost:2345',
      }
    }
  );  
</script>

Events

Whilst not necessarily required, if you need to listen to events happening we support attaching event handlers for the following:

| Event Name | Description | |:-------|:--------| | address | Fired when an address is selected from the drop down. Contains the address detail. |

Events are fired using the CustomEvent class. Event properties are included inside the .detail property.

Event handlers can be attached using the following:

<script>
  var plugin = FirstclasspostcodesPlugin(...);
  
  plugin.$on('address', (event) => {
    console.log(event.detail);
  });
</script>

Plugin

Our plugin is built using Svelte and an instantiated component is returned from the FirstclasspostcodesPlugin() function. Therefore, the returned object is compatible with the documented Client-side component API.