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

postcodex-lib

v1.0.2

Published

JS Lib to connect to postcodex api

Downloads

7

Readme

README

This README would normally document whatever steps are necessary to get your application up and running.

What is this repository for?

  • JS Lib project to help integrate postcodex api
  • Version 1.0.1

How do I get set up?

Lib integration

  • add the postcodex-lib package

npm i postcodex-lib

  • include the lib into the app

// app.js
import 'postcodex-lib';

  • create the form (no need to use the form element)

        <div>
            Postcode:<br/>
            <input type="text" name="postcode" id="postcode"/>&nbsp;&nbsp;&nbsp;
            <button type="button" onclick="pcx.postcodeLookup.handle()">Find Address</button><br/>
            <div name="postcode_list_display" id="postcode_list_display">&nbsp;</div><br/>
            Company:<br/>
            <input type="text" name="companyname" id="companyname"/><br/>
            Address:<br/>
            <input type="text" name="address1" id="address1"/><br/>
            <input type="text" name="address2" id="address2"/><br/>
            <input type="text" name="address3" id="address3"/><br/>
            Town:<br/>
            <input type="text" name="town" id="town"/><br/>
        </div>

  • configure the JS with embedded onclick

        var pcx = new PostcodexApi({  
            token: "8UE7DHBU7ZD2X3D5QW5",
            postcodeLookupOptions: {  
                pcx_output             : "postcode_list_display",  
                pcx_input              : "postcode",  
                pcx_organisationname   : "companyname",  
                pcx_addressline1           : "address1",  
                pcx_addressline2           : "address2",  
                pcx_addressline3           : "address3",  
                pcx_posttown           : "town",  
                selector_type          : "id"
            }  
        });

  • configure the JS without embedded onclick

        var pcx = new PostcodexApi({
            token: "8UE7DHBU7ZD2X3D5QW5"
        })
        pcx.postcodeLookup("wire", {
            button: "#pc_lookup"
        })

        var pcx = new PostcodexApi({
            token: "8UE7DHBU7ZD2X3D5QW5"
        })
        pcx.postcodeLookup.wire({
            button: "#pc_lookup"
        })

        var lookupBtn = document.querySelector("#pc_lookup");
        var pcx = new PostcodexApi({
            token: "8UE7DHBU7ZD2X3D5QW5"
        });
        lookupBtn.onclick  = function () {
            pcx.postcodeLookup.handle({
                pcx_output  : "postcode_list_display",  
                pcx_input   : "postcode"
            });
        }

        var pcx = new PostcodexApi({
            token: "8UE7DHBU7ZD2X3D5QW5"
        });
        var lookupBtn = document.querySelector("#pc_lookup");
        lookupBtn.onclick = function () {
            pcx.postcodeLookup.perform({
                pcx_input  : "postcode"
            }, 
            function (r) {
                console.log(r);
            });
        }

  • Options to instantiate the PostcodexApi class

    token

      * Allows to set the token (mandatory - no default value)
        

    postcodeLookupOptions

      * Allows to set the class options
  • Postcode Lookup Options

    lookup_url

    • Allows to override the default lookup url

    selector_type

    • Allow to set the DOM elements selection method id or name (default: id)
      When starting the element selector with # it forces the selection by id

    pcx_output

    • Allows to identify the DOM element where to append the addresses list (selector) or messages

    pcx_input

    • Allows to identify the postcode input to perform the search

    pcx_postcode

    • Element to fill in with selected address field

    pcx_posttown

    • Element to fill in with selected address field

    pcx_dependentlocality

    • Element to fill in with selected address field

    pcx_doubledependentlocality

    • Element to fill in with selected address field

    pcx_thoroughfare

    • Element to fill in with selected address field

    pcx_dependentthoroughfare

    • Element to fill in with selected address field

    pcx_buildingnumber

    • Element to fill in with selected address field

    pcx_buildingname

    • Element to fill in with selected address field

    pcx_subbuildingname

    • Element to fill in with selected address field

    pcx_pobox

    • Element to fill in with selected address field

    pcx_departmentname

    • Element to fill in with selected address field

    pcx_organisationname

    • Element to fill in with selected address field

    pcx_udprn

    • Element to fill in with selected address field

    pcx_postcodetype

    • Element to fill in with selected address field

    pcx_suorganisationidentifier

    • Element to fill in with selected address field

    pcx_deliverypointsuffix

    • Element to fill in with selected address field

    pcx_addressline1

    • Element to fill in with selected address field

    pcx_addressline2

    • Element to fill in with selected address field

    pcx_addressline3

    • Element to fill in with selected address field

    pcx_addressline4

    • Element to fill in with selected address field

    pcx_addressdescription

    • Element to fill in with selected address field

    button

    • Selector to wire the onclick action (only used on the wire method - mandatory)
  • Callback parameter

    The callback function will be executed with the api response.

    The API response respects the following sample:


    [
        {
            "postcode": "NE664HA",
            "postTown": "ALNWICK",
            "dependentLocality": "Powburn",
            "doubleDependentLocality": "",
            "thoroughfare": "Crawley Dene",
            "dependentThoroughfare": "",
            "buildingNumber": "31",
            "buildingName": "",
            "subBuildingName": "",
            "poBox": "",
            "departmentName": "",
            "OrganisationName": "",
            "udprn": "50631590",
            "postcodeType": "S",
            "suOrganisationIdentifier": "",
            "deliveryPointSuffix": "1A",
            "addressLine1": "31 Crawley Dene",
            "addressLine2": "Powburn",
            "addressLine3": "ALNWICK",
            "addressLine4": "",
            "addressDescription": "31 Crawley Dene, Powburn, ALNWICK"
        }
    ]

Who do I talk to?

  • Repo owner or admin
  • Other community or team contact