Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ideal-postcodes/jsutil

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ideal-postcodes/jsutil - npm Package Compare versions

Comparing version 4.3.4 to 4.3.5

7

CHANGELOG.md

@@ -0,1 +1,8 @@

## [4.3.5](https://github.com/ideal-postcodes/jsutil/compare/4.3.4...4.3.5) (2021-03-08)
### Bug Fixes
* **Compress:** Compress output files ([06f6aac](https://github.com/ideal-postcodes/jsutil/commit/06f6aacf6698c5280bc540b22aafe5312b781653))
## [4.3.4](https://github.com/ideal-postcodes/jsutil/compare/4.3.3...4.3.4) (2021-03-05)

@@ -2,0 +9,0 @@

37

dist/address.d.ts
import { Address } from "@ideal-postcodes/api-typings";
import { Targets, OutputFields, LineCount, Config } from "./types";
/**
* Updates address line fields given result and number of available target lines
*
* @deprecated
*/
export declare const updateAddressLines: (targets: Targets, address: Address) => void;
/**
* @deprecated
*/
interface Options {

@@ -16,21 +8,7 @@ targets: Targets;

}
/**
* @deprecated
*/
interface AddressRetrieval {
(options: Options): (a: Address) => void;
}
/**
* Populate an address based on selector targets
*
* @deprecated
*/
export declare const addressRetrieval: AddressRetrieval;
/**
* Returns number of lines
*/
export declare const numberOfLines: (targets: Targets) => LineCount;
/**
* Removes empty fields and joins
*/
export declare const join: (list: unknown[]) => string;

@@ -51,21 +29,6 @@ export declare const toAddressLines: (n: LineCount, address: Address) => [string, string, string];

}
/**
* Get address property value
*/
export declare const extract: (a: Address, attr: keyof Address) => string;
/**
* Check if address values exists
*/
export declare const notInAddress: (o: Address, attr: keyof Address) => boolean;
/**
* Insert address values into output fields
*/
export declare const populateAddress: PopulateAddress;
/**
* Mutates an address object to remove an organisation name from address
* line and shift up other lines as necessary
*
* - Ignores if only premise identifier is the organisation name
*/
export declare const removeOrganisation: (address: Address) => Address;
export {};

@@ -9,7 +9,2 @@ "use strict";

const string_1 = require("./string");
/**
* Updates address line fields given result and number of available target lines
*
* @deprecated
*/
const updateAddressLines = (targets, address) => {

@@ -22,7 +17,2 @@ const [line_1, line_2, line_3] = exports.toAddressLines(exports.numberOfLines(targets), address);

exports.updateAddressLines = updateAddressLines;
/**
* Populate an address based on selector targets
*
* @deprecated
*/
const addressRetrieval = ({ targets, config }) => (address) => {

@@ -39,5 +29,2 @@ exports.updateAddressLines(targets, address);

exports.addressRetrieval = addressRetrieval;
/**
* Returns number of lines
*/
const numberOfLines = (targets) => {

@@ -52,5 +39,2 @@ const { line_2, line_3 } = targets;

exports.numberOfLines = numberOfLines;
/**
* Removes empty fields and joins
*/
const join = (list) => list

@@ -73,5 +57,2 @@ .filter((e) => {

exports.toAddressLines = toAddressLines;
/**
* Get address property value
*/
const extract = (a, attr) => {

@@ -86,12 +67,4 @@ const result = a[attr];

exports.extract = extract;
/**
* Check if address values exists
*/
const notInAddress = (o, attr) => o[attr] === undefined;
exports.notInAddress = notInAddress;
/**
* Update address lines
*
* @private
*/
const updateLines = (fields, address, scope) => {

@@ -103,5 +76,2 @@ const [line_1, line_2, line_3] = exports.toAddressLines(exports.numberOfLines(fields), address);

};
/**
* Insert address values into output fields
*/
const populateAddress = (options) => {

@@ -111,3 +81,2 @@ const { outputFields, config } = options;

const { scope, titleizePostTown } = config;
// Apply initial address transforms
if (config.removeOrganisation)

@@ -117,3 +86,2 @@ exports.removeOrganisation(address);

address.post_town = capitalise_post_town_1.capitalisePostTown(address.post_town);
// Populate address lines and remove from address
updateLines(outputFields, address, scope);

@@ -123,6 +91,4 @@ delete address.line_1;

delete address.line_3;
// Populate country from address
country_1.updateCountry(dom_1.toElem(outputFields.country || null, scope), address);
delete address.country;
// Populate all other address fields
let e;

@@ -141,8 +107,2 @@ for (e in outputFields) {

exports.populateAddress = populateAddress;
/**
* Mutates an address object to remove an organisation name from address
* line and shift up other lines as necessary
*
* - Ignores if only premise identifier is the organisation name
*/
const removeOrganisation = (address) => {

@@ -154,3 +114,2 @@ if (address.organisation_name.length === 0)

if (address.line_1 === address.organisation_name) {
// Shift addresses up
address.line_1 = address.line_2;

@@ -157,0 +116,0 @@ address.line_2 = address.line_3;

@@ -8,26 +8,7 @@ declare global {

import { LoadState, Config } from "./types";
/**
* Load Autocomplete CSS
*/
export declare const downloadAutocompleteStyle: (d?: Document | undefined) => HTMLStyleElement;
/**
* Returns true if autocomplete library present
*/
export declare const autocompletePresent: (w: Window) => boolean;
/**
* Retrieves remote autocomplete script and CSS
*/
export declare const loadAutocomplete: (config: Config) => LoadState;
/**
* Returns true if jQuery present
*/
export declare const jQueryPresent: (w: Window) => boolean;
/**
* Return true if postcode lookup plugin present
*/
export declare const postcodeLookupPresent: (w: Window) => boolean;
/**
* Retrieves remote postcode lookup script. Can be repeatedly called in a loop
* and assets will only be requested once
*/
export declare const loadPostcodeLookup: (config: Config) => LoadState;

@@ -38,25 +19,7 @@ export declare const clearCache: () => void;

}
/**
* Script downloader factory. Caches script reference, only downloads once
*/
export declare const downloadScript: (url: string, integrity: string) => Downloader;
/**
* Download jQuery 3.5.1
*/
export declare const downloadJQuery: Downloader;
/**
* Download postcode lookup plugin 3.0.8
*/
export declare const downloadPostcodeLookup: Downloader;
/**
* Download autocomplete 0.2.1
*/
export declare const downloadAutocomplete: Downloader;
/**
* Inject CSS stylesheet
*/
export declare const loadStyle: (href: string, document: Document) => HTMLLinkElement;
/**
* Inject script tag
*/
export declare const loadScript: (src: string, integrity: string, document: Document) => HTMLScriptElement;

@@ -70,12 +33,4 @@ interface AssetsOptions {

}
/**
* Returns true if all necessary assets are available
*
* If false, asset retrieval will be trigered
*/
export declare const readyAssets: ReadyAssets;
/**
* Injects styke element to page
*/
export declare const injectStyle: (css: string, document: Document) => HTMLStyleElement;
export {};

@@ -5,5 +5,2 @@ "use strict";

let autocompleteLink;
/**
* Load Autocomplete CSS
*/
const downloadAutocompleteStyle = (d) => {

@@ -18,5 +15,2 @@ if (autocompleteLink !== undefined)

exports.downloadAutocompleteStyle = downloadAutocompleteStyle;
/**
* Returns true if autocomplete library present
*/
const autocompletePresent = (w) => {

@@ -32,7 +26,3 @@ if (w.IdealPostcodes === undefined)

exports.autocompletePresent = autocompletePresent;
/**
* Retrieves remote autocomplete script and CSS
*/
const loadAutocomplete = (config) => {
// Exit if not available
if (config.autocomplete !== true)

@@ -47,10 +37,4 @@ return "complete";

exports.loadAutocomplete = loadAutocomplete;
/**
* Returns true if jQuery present
*/
const jQueryPresent = (w) => w.jQuery !== undefined;
exports.jQueryPresent = jQueryPresent;
/**
* Return true if postcode lookup plugin present
*/
const postcodeLookupPresent = (w) => {

@@ -62,6 +46,2 @@ if (exports.jQueryPresent(w) === false)

exports.postcodeLookupPresent = postcodeLookupPresent;
/**
* Retrieves remote postcode lookup script. Can be repeatedly called in a loop
* and assets will only be requested once
*/
const loadPostcodeLookup = (config) => {

@@ -86,5 +66,2 @@ if (config.postcodeLookup !== true)

exports.clearCache = clearCache;
/**
* Script downloader factory. Caches script reference, only downloads once
*/
const downloadScript = (url, integrity) => (d) => {

@@ -100,17 +77,5 @@ if (cache[url])

exports.downloadScript = downloadScript;
/**
* Download jQuery 3.5.1
*/
exports.downloadJQuery = exports.downloadScript("https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js", "sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=");
/**
* Download postcode lookup plugin 3.0.8
*/
exports.downloadPostcodeLookup = exports.downloadScript("https://cdn.jsdelivr.net/npm/jquery-postcodes@3.0.8/dist/postcodes.min.js", "sha256-JZSN3ZEXOFlpSMFjQkHjbKnjHlsFVf8N7p1SbCI0XHI=");
/**
* Download autocomplete 0.2.1
*/
exports.downloadAutocomplete = exports.downloadScript("https://cdn.jsdelivr.net/npm/ideal-postcodes-autocomplete@0.2.1/dist/ideal-postcodes-autocomplete.min.js", "sha256-lZPaPHBx7V2Gj9iAc8QfVcW02KlWB2gbrqXpGfiEGgo=");
/**
* Inject CSS stylesheet
*/
const loadStyle = (href, document) => {

@@ -124,5 +89,2 @@ const link = document.createElement("link");

exports.loadStyle = loadStyle;
/**
* Inject script tag
*/
const loadScript = (src, integrity, document) => {

@@ -137,10 +99,4 @@ const script = document.createElement("script");

exports.loadScript = loadScript;
/**
* Returns true if all necessary assets are available
*
* If false, asset retrieval will be trigered
*/
const readyAssets = ({ config, window }) => {
let ready = true;
// Retrieve assets
if (config.autocomplete) {

@@ -159,5 +115,2 @@ exports.loadAutocomplete(config);

exports.readyAssets = readyAssets;
/**
* Injects styke element to page
*/
const injectStyle = (css, document) => {

@@ -164,0 +117,0 @@ const style = document.createElement("style");

import { Country, ChannelIslandIso, CountryIso } from "./types";
import { Address } from "@ideal-postcodes/api-typings";
/**
* Converts Channel Island Country to Channel Island ISO code
*/
export declare const toCiIso: (address: Address) => ChannelIslandIso | null;
/**
* Converts a country to its ISO code
*
* Returns null if no match
*/
export declare const toIso: (address: Address) => CountryIso | null;
/**
* Maps UkCountry to Country
*
* Returns null if no match
*/
export declare const toCountry: (address: Address) => Country | null;
/**
* Updates country in BC country field given address selected
*/
export declare const updateCountry: (select: HTMLElement | null, address: Address) => void;

@@ -5,5 +5,2 @@ "use strict";

const input_1 = require("./input");
/**
* Converts Channel Island Country to Channel Island ISO code
*/
const toCiIso = (address) => {

@@ -24,7 +21,2 @@ if (/^GY/.test(address.postcode))

const CI = "Channel Islands";
/**
* Converts a country to its ISO code
*
* Returns null if no match
*/
const toIso = (address) => {

@@ -47,7 +39,2 @@ const country = address.country;

exports.toIso = toIso;
/**
* Maps UkCountry to Country
*
* Returns null if no match
*/
const toCountry = (address) => {

@@ -75,5 +62,2 @@ const country = address.country;

exports.toCountry = toCountry;
/**
* Updates country in BC country field given address selected
*/
const updateCountry = (select, address) => {

@@ -80,0 +64,0 @@ if (!select)

import { ParentTest, SelectorNode } from "./types";
/**
* Convert a NodeList to array
*/
export declare const toArray: <T = HTMLElement>(nodeList: NodeList) => T[];
/**
* Returns true if initialised
*/
export declare const loaded: (elem: HTMLElement) => boolean;
/**
* Marks HTML as loaded. i.e. Address validation plugin has been bound to this element
*/
export declare const markLoaded: (elem: HTMLElement) => void;
/**
* Retrives a parent by tag name
*
* Accepts node as a possible candidate for parent
*
* Executes an additional test if specified
*/
export declare const getParent: (node: HTMLElement, entity: string, test?: ParentTest) => HTMLElement | null;
/**
* Queries `parent` for a specific `selector`. Returns null if no selector
*/
export declare const toHtmlElem: (parent: HTMLElement, selector?: string | undefined) => HTMLElement | null;
/**
* Retrieves an anchor defined by a query selector
*
* Checks if anchor has been loaded, if not, marks it as loaded
*/
export declare const getAnchors: (selector: string, d?: Document | undefined) => HTMLElement[];

@@ -39,43 +15,12 @@ interface InsertBeforeOptions {

}
/**
* Inserts element before `target` element
*/
export declare const insertBefore: InsertBefore;
/**
* Scoped retrieval of a HTML element given a querystring or the element itself
*
* @hidden
*/
export declare const toElem: (elem: SelectorNode | null, context: HTMLElement | Document) => HTMLElement | null;
/**
* Outputs scope of controller
* - If null, return window.document
* - If string, resolve with query selector
* - Otherwise returns the HTMLElement or Document
*/
export declare const getScope: (scope: null | string | HTMLElement | Document) => HTMLElement | Document;
/**
* Retrieves document instance of HTML Element or Document
*
* Defaults to window.document
*/
export declare const getDocument: (scope: HTMLElement | Document) => Document;
export declare type CSSStyle = Partial<Record<keyof CSSStyleDeclaration, string>>;
/**
* Applies style object to HTML Element and returns the previous style in `string` format
*/
export declare const setStyle: (element: HTMLElement, style: CSSStyle) => string | null;
export declare const restoreStyle: (element: HTMLElement, style: string | null) => void;
/**
* Hide HTML Element
*/
export declare const hide: <T extends HTMLElement = HTMLElement>(e: T) => T;
/**
* Show HTML Element
*/
export declare const show: <T extends HTMLElement = HTMLElement>(e: T) => T;
/**
* Remove node from DOM
*/
export declare const remove: (elem: HTMLElement | null) => void;
export {};

@@ -5,25 +5,9 @@ "use strict";

const string_1 = require("./string");
/**
* Convert a NodeList to array
*/
const toArray = (nodeList) => Array.prototype.slice.call(nodeList);
exports.toArray = toArray;
/**
* Returns true if initialised
*/
const loaded = (elem) => elem.getAttribute("idpc") === "true";
exports.loaded = loaded;
/**
* Marks HTML as loaded. i.e. Address validation plugin has been bound to this element
*/
const markLoaded = (elem) => elem.setAttribute("idpc", "true");
exports.markLoaded = markLoaded;
const isTrue = () => true;
/**
* Retrives a parent by tag name
*
* Accepts node as a possible candidate for parent
*
* Executes an additional test if specified
*/
const getParent = (node, entity, test = isTrue) => {

@@ -42,12 +26,4 @@ let parent = node;

exports.getParent = getParent;
/**
* Queries `parent` for a specific `selector`. Returns null if no selector
*/
const toHtmlElem = (parent, selector) => (selector ? parent.querySelector(selector) : null);
exports.toHtmlElem = toHtmlElem;
/**
* Retrieves an anchor defined by a query selector
*
* Checks if anchor has been loaded, if not, marks it as loaded
*/
const getAnchors = (selector, d) => {

@@ -62,5 +38,2 @@ const matches = (d || window.document).querySelectorAll(selector);

exports.getAnchors = getAnchors;
/**
* Inserts element before `target` element
*/
const insertBefore = ({ elem, target }) => {

@@ -74,7 +47,2 @@ const parent = target.parentNode;

exports.insertBefore = insertBefore;
/**
* Scoped retrieval of a HTML element given a querystring or the element itself
*
* @hidden
*/
const toElem = (elem, context) => {

@@ -86,12 +54,3 @@ if (string_1.isString(elem))

exports.toElem = toElem;
/**
* @hidden
*/
const d = window.document;
/**
* Outputs scope of controller
* - If null, return window.document
* - If string, resolve with query selector
* - Otherwise returns the HTMLElement or Document
*/
const getScope = (scope) => {

@@ -105,7 +64,2 @@ if (string_1.isString(scope))

exports.getScope = getScope;
/**
* Retrieves document instance of HTML Element or Document
*
* Defaults to window.document
*/
const getDocument = (scope) => {

@@ -119,5 +73,2 @@ if (scope instanceof Document)

exports.getDocument = getDocument;
/**
* Applies style object to HTML Element and returns the previous style in `string` format
*/
const setStyle = (element, style) => {

@@ -133,5 +84,2 @@ const currentRules = element.getAttribute("style");

exports.restoreStyle = restoreStyle;
/**
* Hide HTML Element
*/
const hide = (e) => {

@@ -142,5 +90,2 @@ e.style.display = "none";

exports.hide = hide;
/**
* Show HTML Element
*/
const show = (e) => {

@@ -151,5 +96,2 @@ e.style.display = "";

exports.show = show;
/**
* Remove node from DOM
*/
const remove = (elem) => {

@@ -156,0 +98,0 @@ if (elem === null || elem.parentNode === null)

@@ -9,16 +9,5 @@ interface EventOptions {

}
/**
* Generates `Event` instance
*
* Includes polyfill where window.Event not available
*/
export declare const newEvent: NewEvent;
/**
* Input events we support
*/
export declare type Events = "change" | "input" | "select";
/**
* Dispatch custom event on element
*/
export declare const trigger: (e: HTMLElement, event: Events) => boolean;
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.trigger = exports.newEvent = void 0;
/**
* Generates `Event` instance
*
* Includes polyfill where window.Event not available
*/
const newEvent = ({ event, bubbles = true, cancelable = true, }) => {
// if Event available
if (typeof window.Event === "function")
return new window.Event(event, { bubbles, cancelable });
// Fallback if Event not available (e.g. IE11)
const e = document.createEvent("Event");

@@ -19,6 +12,3 @@ e.initEvent(event, bubbles, cancelable);

exports.newEvent = newEvent;
/**
* Dispatch custom event on element
*/
const trigger = (e, event) => e.dispatchEvent(exports.newEvent({ event }));
exports.trigger = trigger;

3

dist/id.d.ts
export interface IdGen {
(): string;
}
/**
* Generates a globally unique ID
*/
export declare const idGen: (prefix?: string) => IdGen;

@@ -5,5 +5,2 @@ "use strict";

const store_1 = require("./store");
/**
* Generates a globally unique ID
*/
const idGen = (prefix = "idpc_") => () => {

@@ -10,0 +7,0 @@ const g = store_1.idpcState();

@@ -1,16 +0,4 @@

/**
* Returns true if element is select
*/
export declare const isSelect: (e: HTMLElement | null) => e is HTMLSelectElement;
/**
* Returns true if Element is <input>
*/
export declare const isInput: (e: HTMLElement | null) => e is HTMLInputElement;
/**
* Updates input value and dispatches change envet
*/
export declare const update: (input: HTMLElement | null | undefined, value: string, skipTrigger?: boolean) => void;
/**
* Returns true if HTMLElement has matching value
*/
export declare const hasValue: (select: HTMLElement, value: string | null) => boolean;

@@ -21,12 +9,3 @@ declare type InputElement = HTMLSelectElement | HTMLInputElement;

}
/**
* Assigns value using native property method
*
* If assignment fails, resort to using the setter found in prototype chain
*/
export declare const setValue: SetValue;
/**
* Sets the value of an Element using the setter for value found on the
* protype chain
*/
export declare const forceSetValue: SetValue;

@@ -41,8 +20,3 @@ interface Change {

}
/**
* Updates value of input or select field and triggers an update event
*
* https://github.com/facebook/react/issues/11488#issuecomment-558874287
*/
export declare const change: Change;
export {};

@@ -5,5 +5,2 @@ "use strict";

const event_1 = require("./event");
/**
* Returns true if element is select
*/
const isSelect = (e) => {

@@ -15,5 +12,2 @@ if (e === null)

exports.isSelect = isSelect;
/**
* Returns true if Element is <input>
*/
const isInput = (e) => {

@@ -25,5 +19,2 @@ if (e === null)

exports.isInput = isInput;
/**
* Updates input value and dispatches change envet
*/
const update = (input, value, skipTrigger = false) => {

@@ -37,5 +28,2 @@ if (!input)

exports.update = update;
/**
* Returns true if HTMLElement has matching value
*/
const hasValue = (select, value) => {

@@ -47,5 +35,2 @@ if (value === null)

exports.hasValue = hasValue;
/**
* Updates value property of HTMLSelectElement
*/
const updateSelect = ({ e, value, skipTrigger }) => {

@@ -61,7 +46,2 @@ if (value === null)

};
/**
* Assigns value using native property method
*
* If assignment fails, resort to using the setter found in prototype chain
*/
const setValue = (e, value) => {

@@ -73,6 +53,2 @@ e.value = value;

exports.setValue = setValue;
/**
* Sets the value of an Element using the setter for value found on the
* protype chain
*/
const forceSetValue = (e, value) => {

@@ -88,5 +64,2 @@ const descriptor = Object.getOwnPropertyDescriptor(e.constructor.prototype, "value");

exports.forceSetValue = forceSetValue;
/**
* Updates value property of HTMLInputElement
*/
const updateInput = ({ e, value, skipTrigger }) => {

@@ -102,7 +75,2 @@ if (value === null)

};
/**
* Updates value of input or select field and triggers an update event
*
* https://github.com/facebook/react/issues/11488#issuecomment-558874287
*/
const change = (options) => {

@@ -109,0 +77,0 @@ if (options.value === null)

@@ -6,5 +6,2 @@ declare global {

}
/**
* Global store. Aimed at ensuring multiple copies of our JS libs can have some shared state if required
*/
export interface IdpcGlobal {

@@ -14,5 +11,2 @@ idGen?: Record<string, number>;

export declare const idpcState: () => IdpcGlobal;
/**
* Resets global store
*/
export declare const reset: () => void;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.reset = exports.idpcState = void 0;
/**
* @hidden
*/
let g = {};
if (window) {
if (window.idpcGlobal) {
// Adopt idpcGlobal from window if it exists
g = window.idpcGlobal;
}
else {
// Assign idpcGlobal to window if not exists
window.idpcGlobal = g;

@@ -20,6 +15,3 @@ }

exports.idpcState = idpcState;
/**
* Resets global store
*/
const reset = () => Object.getOwnPropertyNames(g).forEach((p) => delete g[p]);
exports.reset = reset;
export declare const isString: (input: unknown) => input is string;
/**
* Returns true if substring match
*/
export declare const includes: (haystack: string, needle: string) => boolean;

@@ -6,6 +6,3 @@ "use strict";

exports.isString = isString;
/**
* Returns true if substring match
*/
const includes = (haystack, needle) => haystack.indexOf(needle) !== -1;
exports.includes = includes;
import { Address } from "@ideal-postcodes/api-typings";
export interface Binding {
/**
* Verify if can be launched
*/
pageTest: PageTest;
/**
* Binds to page
*/
bind: Bind;

@@ -35,60 +29,13 @@ }

export interface Config {
/**
* Enable / disable the integration altogether
*/
enabled: boolean;
/**
* A string of characters. Typically begins `ak_`
*
* The API Key is required to verify your account for address validation. View your API Keys from your [account dashboard](https://ideal-postcodes.co.uk/tokens).
*
* See our [API Key guide](https://ideal-postcodes.co.uk/guides/api-key) to find out more.
*/
apiKey: string;
/**
* Addresses with an organisation will overwrite the value of the company name field.
*/
populateOrganisation: boolean;
/**
* Populate the county field of an address. County data is optional for premise identification.
*
* We recommend avoid using county data altogether. Find out more from our [UK county data guide](https://ideal-postcodes.co.uk/guides/county-data).
*/
populateCounty: boolean;
/**
* Setting this to `true` will enable autocomplete integration on your address forms.
*
* See our [Address Finder Demo](https://ideal-postcodes.co.uk/address-finder) to try it out.
*/
autocomplete: boolean;
/**
* *Advanced.* Override the autocompletion plugin configuration.
*
* Pass in a [valid configuration object](https://ideal-postcodes.co.uk/documentation/ideal-postcodes-autocomplete#config) to override specific autocomplete configuration attributes.
*/
autocompleteOverride: AutocompleteConfig;
/**
* Setting this to `true` will enable postcode lookup integration on your address forms.
*
* See our [Postcode Finder Demo](https://ideal-postcodes.co.uk/postcode-finder) to try it out.
*/
postcodeLookup: boolean;
/**
* *Advanced.* Override the postcode lookup plugin configuration.
*
* Pass in a [valid configuration object](https://ideal-postcodes.co.uk/documentation/jquery-plugin) to override specific postcode lookup configuration settings.
*/
postcodeLookupOverride: PostcodeLookupConfig;
/**
* Setting this to `true` will detach our Address Validation tools from the page if an unsupported terrority is selected
*/
watchCountry?: boolean;
/**
* Setting this to `true` will attempt to deploy the Address Finder on an input away from line_1
*/
separateFinder?: boolean;
}
/**
* A map of HTML elements to be populated with address data
*/
export interface Targets {

@@ -104,45 +51,14 @@ line_1: HTMLElement | null;

}
/**
* Placeholder
*/
export declare type AutocompleteConfig = any;
export declare type PostcodeLookupConfig = any;
/**
* Countries returned by API. Splits "United Kingdom" into constitutent country
*/
export declare type UkCountry = "England" | "Wales" | "Northern Ireland" | "Scotland" | "Channel Islands" | "Isle of Man";
/**
* Channel Island ISO Codes
*/
export declare type ChannelIslandIso = "JE" | "GG";
/**
* ISO Country codes
*/
export declare type CountryIso = "GB" | "IM" | ChannelIslandIso;
/**
* Country
*/
export declare type Country = "United Kingdom" | "Jersey" | "Guernsey" | "Isle of Man";
export declare type LineCount = 1 | 2 | 3;
/**
* Describes availability of specific on page assets
* complete - Asset is either not required or loaded
* loading - Asset being retrieved or parsed
*/
export declare type LoadState = "complete" | "loading";
/**
* Method used to test whether a DOM element qualifies as parent
*/
export interface ParentTest {
(e: HTMLElement): boolean;
}
/**
* OutputFields can be identified by the address attributes supported by the API
*
* Typings for the API Address object can be found at [@ideal-postcodes/api-typings](https://api-typings.ideal-postcodes.dev/interfaces/address.html)
*/
export declare type OutputFields = Partial<Record<keyof Address, SelectorNode>>;
/**
* Represents either a HTMLInputelement or a selector pointing to one
*/
export declare type SelectorNode = string | HTMLInputElement | HTMLTextAreaElement;
import { Bind, Start, ParentTest, Stop, PageTest, Config, Selectors, Targets, Binding } from "./types";
/**
* Returns an object of attributes mapped to HTMLInputElement
*
* Returns null if any critical elements are not present (line 1, post_town, postcode)
*
* @deprecated
*/
export declare const getTargets: (parent: HTMLElement, selectors: Selectors) => Targets | null;
/**
* Given a list of bindings, return true if any are relevant to current pae
*/
export declare const relevantPage: (bindings: Binding[]) => boolean;
/**
* Setup defaults
*/
export declare const defaults: Config;

@@ -44,23 +31,8 @@ export declare const config: () => Config | undefined;

}
/**
* Deploys address search tools on page using predefined bindings
*/
export declare const setup: Setup;
interface SetupBindOptions {
selectors: Selectors;
/**
* Query selector that defines anchor. Defaults to selectors.line_1
*/
anchorSelector?: string;
/**
* Restricts subsequent selector scope once anchor is found. Defaults to `form`
*/
parentScope?: string;
/**
* Allow search in specific document
*/
doc?: Document;
/**
* Optional test to select for parent/scope
*/
parentTest?: ParentTest;

@@ -67,0 +39,0 @@ }

@@ -5,9 +5,2 @@ "use strict";

const dom_1 = require("./dom");
/**
* Returns an object of attributes mapped to HTMLInputElement
*
* Returns null if any critical elements are not present (line 1, post_town, postcode)
*
* @deprecated
*/
const getTargets = (parent, selectors) => {

@@ -40,10 +33,4 @@ const line_1 = dom_1.toHtmlElem(parent, selectors.line_1);

exports.getTargets = getTargets;
/**
* Given a list of bindings, return true if any are relevant to current pae
*/
const relevantPage = (bindings) => bindings.some((b) => b.pageTest());
exports.relevantPage = relevantPage;
/**
* Setup defaults
*/
exports.defaults = {

@@ -54,6 +41,4 @@ enabled: true,

populateCounty: false,
// Autocomplete config
autocomplete: true,
autocompleteOverride: {},
// Postcode lookup config
postcodeLookup: true,

@@ -79,5 +64,3 @@ postcodeLookupOverride: {},

catch (e) {
// Terminate timer if some exception is raised
stop();
/* eslint no-console: ["error", { allow: ["log"] }] */
console.log(e);

@@ -98,5 +81,2 @@ }

const NOOP = () => { };
/**
* Deploys address search tools on page using predefined bindings
*/
const setup = ({ bindings, callback = NOOP }) => {

@@ -103,0 +83,0 @@ const c = exports.config();

import { Address } from "@ideal-postcodes/api-typings";
import { Targets, OutputFields, LineCount, Config } from "./types";
/**
* Updates address line fields given result and number of available target lines
*
* @deprecated
*/
export declare const updateAddressLines: (targets: Targets, address: Address) => void;
/**
* @deprecated
*/
interface Options {

@@ -16,21 +8,7 @@ targets: Targets;

}
/**
* @deprecated
*/
interface AddressRetrieval {
(options: Options): (a: Address) => void;
}
/**
* Populate an address based on selector targets
*
* @deprecated
*/
export declare const addressRetrieval: AddressRetrieval;
/**
* Returns number of lines
*/
export declare const numberOfLines: (targets: Targets) => LineCount;
/**
* Removes empty fields and joins
*/
export declare const join: (list: unknown[]) => string;

@@ -51,21 +29,6 @@ export declare const toAddressLines: (n: LineCount, address: Address) => [string, string, string];

}
/**
* Get address property value
*/
export declare const extract: (a: Address, attr: keyof Address) => string;
/**
* Check if address values exists
*/
export declare const notInAddress: (o: Address, attr: keyof Address) => boolean;
/**
* Insert address values into output fields
*/
export declare const populateAddress: PopulateAddress;
/**
* Mutates an address object to remove an organisation name from address
* line and shift up other lines as necessary
*
* - Ignores if only premise identifier is the organisation name
*/
export declare const removeOrganisation: (address: Address) => Address;
export {};

@@ -6,7 +6,2 @@ import { capitalisePostTown } from "capitalise-post-town";

import { isString } from "./string";
/**
* Updates address line fields given result and number of available target lines
*
* @deprecated
*/
export const updateAddressLines = (targets, address) => {

@@ -18,7 +13,2 @@ const [line_1, line_2, line_3] = toAddressLines(numberOfLines(targets), address);

};
/**
* Populate an address based on selector targets
*
* @deprecated
*/
export const addressRetrieval = ({ targets, config }) => (address) => {

@@ -34,5 +24,2 @@ updateAddressLines(targets, address);

};
/**
* Returns number of lines
*/
export const numberOfLines = (targets) => {

@@ -46,5 +33,2 @@ const { line_2, line_3 } = targets;

};
/**
* Removes empty fields and joins
*/
export const join = (list) => list

@@ -65,5 +49,2 @@ .filter((e) => {

};
/**
* Get address property value
*/
export const extract = (a, attr) => {

@@ -77,11 +58,3 @@ const result = a[attr];

};
/**
* Check if address values exists
*/
export const notInAddress = (o, attr) => o[attr] === undefined;
/**
* Update address lines
*
* @private
*/
const updateLines = (fields, address, scope) => {

@@ -93,5 +66,2 @@ const [line_1, line_2, line_3] = toAddressLines(numberOfLines(fields), address);

};
/**
* Insert address values into output fields
*/
export const populateAddress = (options) => {

@@ -101,3 +71,2 @@ const { outputFields, config } = options;

const { scope, titleizePostTown } = config;
// Apply initial address transforms
if (config.removeOrganisation)

@@ -107,3 +76,2 @@ removeOrganisation(address);

address.post_town = capitalisePostTown(address.post_town);
// Populate address lines and remove from address
updateLines(outputFields, address, scope);

@@ -113,6 +81,4 @@ delete address.line_1;

delete address.line_3;
// Populate country from address
updateCountry(toElem(outputFields.country || null, scope), address);
delete address.country;
// Populate all other address fields
let e;

@@ -130,8 +96,2 @@ for (e in outputFields) {

};
/**
* Mutates an address object to remove an organisation name from address
* line and shift up other lines as necessary
*
* - Ignores if only premise identifier is the organisation name
*/
export const removeOrganisation = (address) => {

@@ -143,3 +103,2 @@ if (address.organisation_name.length === 0)

if (address.line_1 === address.organisation_name) {
// Shift addresses up
address.line_1 = address.line_2;

@@ -146,0 +105,0 @@ address.line_2 = address.line_3;

@@ -8,26 +8,7 @@ declare global {

import { LoadState, Config } from "./types";
/**
* Load Autocomplete CSS
*/
export declare const downloadAutocompleteStyle: (d?: Document | undefined) => HTMLStyleElement;
/**
* Returns true if autocomplete library present
*/
export declare const autocompletePresent: (w: Window) => boolean;
/**
* Retrieves remote autocomplete script and CSS
*/
export declare const loadAutocomplete: (config: Config) => LoadState;
/**
* Returns true if jQuery present
*/
export declare const jQueryPresent: (w: Window) => boolean;
/**
* Return true if postcode lookup plugin present
*/
export declare const postcodeLookupPresent: (w: Window) => boolean;
/**
* Retrieves remote postcode lookup script. Can be repeatedly called in a loop
* and assets will only be requested once
*/
export declare const loadPostcodeLookup: (config: Config) => LoadState;

@@ -38,25 +19,7 @@ export declare const clearCache: () => void;

}
/**
* Script downloader factory. Caches script reference, only downloads once
*/
export declare const downloadScript: (url: string, integrity: string) => Downloader;
/**
* Download jQuery 3.5.1
*/
export declare const downloadJQuery: Downloader;
/**
* Download postcode lookup plugin 3.0.8
*/
export declare const downloadPostcodeLookup: Downloader;
/**
* Download autocomplete 0.2.1
*/
export declare const downloadAutocomplete: Downloader;
/**
* Inject CSS stylesheet
*/
export declare const loadStyle: (href: string, document: Document) => HTMLLinkElement;
/**
* Inject script tag
*/
export declare const loadScript: (src: string, integrity: string, document: Document) => HTMLScriptElement;

@@ -70,12 +33,4 @@ interface AssetsOptions {

}
/**
* Returns true if all necessary assets are available
*
* If false, asset retrieval will be trigered
*/
export declare const readyAssets: ReadyAssets;
/**
* Injects styke element to page
*/
export declare const injectStyle: (css: string, document: Document) => HTMLStyleElement;
export {};
let autocompleteLink;
/**
* Load Autocomplete CSS
*/
export const downloadAutocompleteStyle = (d) => {

@@ -13,5 +10,2 @@ if (autocompleteLink !== undefined)

};
/**
* Returns true if autocomplete library present
*/
export const autocompletePresent = (w) => {

@@ -26,7 +20,3 @@ if (w.IdealPostcodes === undefined)

};
/**
* Retrieves remote autocomplete script and CSS
*/
export const loadAutocomplete = (config) => {
// Exit if not available
if (config.autocomplete !== true)

@@ -40,9 +30,3 @@ return "complete";

};
/**
* Returns true if jQuery present
*/
export const jQueryPresent = (w) => w.jQuery !== undefined;
/**
* Return true if postcode lookup plugin present
*/
export const postcodeLookupPresent = (w) => {

@@ -53,6 +37,2 @@ if (jQueryPresent(w) === false)

};
/**
* Retrieves remote postcode lookup script. Can be repeatedly called in a loop
* and assets will only be requested once
*/
export const loadPostcodeLookup = (config) => {

@@ -75,5 +55,2 @@ if (config.postcodeLookup !== true)

};
/**
* Script downloader factory. Caches script reference, only downloads once
*/
export const downloadScript = (url, integrity) => (d) => {

@@ -88,17 +65,5 @@ if (cache[url])

};
/**
* Download jQuery 3.5.1
*/
export const downloadJQuery = downloadScript("https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js", "sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=");
/**
* Download postcode lookup plugin 3.0.8
*/
export const downloadPostcodeLookup = downloadScript("https://cdn.jsdelivr.net/npm/jquery-postcodes@3.0.8/dist/postcodes.min.js", "sha256-JZSN3ZEXOFlpSMFjQkHjbKnjHlsFVf8N7p1SbCI0XHI=");
/**
* Download autocomplete 0.2.1
*/
export const downloadAutocomplete = downloadScript("https://cdn.jsdelivr.net/npm/ideal-postcodes-autocomplete@0.2.1/dist/ideal-postcodes-autocomplete.min.js", "sha256-lZPaPHBx7V2Gj9iAc8QfVcW02KlWB2gbrqXpGfiEGgo=");
/**
* Inject CSS stylesheet
*/
export const loadStyle = (href, document) => {

@@ -111,5 +76,2 @@ const link = document.createElement("link");

};
/**
* Inject script tag
*/
export const loadScript = (src, integrity, document) => {

@@ -123,10 +85,4 @@ const script = document.createElement("script");

};
/**
* Returns true if all necessary assets are available
*
* If false, asset retrieval will be trigered
*/
export const readyAssets = ({ config, window }) => {
let ready = true;
// Retrieve assets
if (config.autocomplete) {

@@ -144,5 +100,2 @@ loadAutocomplete(config);

};
/**
* Injects styke element to page
*/
export const injectStyle = (css, document) => {

@@ -149,0 +102,0 @@ const style = document.createElement("style");

import { Country, ChannelIslandIso, CountryIso } from "./types";
import { Address } from "@ideal-postcodes/api-typings";
/**
* Converts Channel Island Country to Channel Island ISO code
*/
export declare const toCiIso: (address: Address) => ChannelIslandIso | null;
/**
* Converts a country to its ISO code
*
* Returns null if no match
*/
export declare const toIso: (address: Address) => CountryIso | null;
/**
* Maps UkCountry to Country
*
* Returns null if no match
*/
export declare const toCountry: (address: Address) => Country | null;
/**
* Updates country in BC country field given address selected
*/
export declare const updateCountry: (select: HTMLElement | null, address: Address) => void;
import { isSelect, isInput, hasValue, change } from "./input";
/**
* Converts Channel Island Country to Channel Island ISO code
*/
export const toCiIso = (address) => {

@@ -19,7 +16,2 @@ if (/^GY/.test(address.postcode))

const CI = "Channel Islands";
/**
* Converts a country to its ISO code
*
* Returns null if no match
*/
export const toIso = (address) => {

@@ -41,7 +33,2 @@ const country = address.country;

};
/**
* Maps UkCountry to Country
*
* Returns null if no match
*/
export const toCountry = (address) => {

@@ -68,5 +55,2 @@ const country = address.country;

};
/**
* Updates country in BC country field given address selected
*/
export const updateCountry = (select, address) => {

@@ -73,0 +57,0 @@ if (!select)

import { ParentTest, SelectorNode } from "./types";
/**
* Convert a NodeList to array
*/
export declare const toArray: <T = HTMLElement>(nodeList: NodeList) => T[];
/**
* Returns true if initialised
*/
export declare const loaded: (elem: HTMLElement) => boolean;
/**
* Marks HTML as loaded. i.e. Address validation plugin has been bound to this element
*/
export declare const markLoaded: (elem: HTMLElement) => void;
/**
* Retrives a parent by tag name
*
* Accepts node as a possible candidate for parent
*
* Executes an additional test if specified
*/
export declare const getParent: (node: HTMLElement, entity: string, test?: ParentTest) => HTMLElement | null;
/**
* Queries `parent` for a specific `selector`. Returns null if no selector
*/
export declare const toHtmlElem: (parent: HTMLElement, selector?: string | undefined) => HTMLElement | null;
/**
* Retrieves an anchor defined by a query selector
*
* Checks if anchor has been loaded, if not, marks it as loaded
*/
export declare const getAnchors: (selector: string, d?: Document | undefined) => HTMLElement[];

@@ -39,43 +15,12 @@ interface InsertBeforeOptions {

}
/**
* Inserts element before `target` element
*/
export declare const insertBefore: InsertBefore;
/**
* Scoped retrieval of a HTML element given a querystring or the element itself
*
* @hidden
*/
export declare const toElem: (elem: SelectorNode | null, context: HTMLElement | Document) => HTMLElement | null;
/**
* Outputs scope of controller
* - If null, return window.document
* - If string, resolve with query selector
* - Otherwise returns the HTMLElement or Document
*/
export declare const getScope: (scope: null | string | HTMLElement | Document) => HTMLElement | Document;
/**
* Retrieves document instance of HTML Element or Document
*
* Defaults to window.document
*/
export declare const getDocument: (scope: HTMLElement | Document) => Document;
export declare type CSSStyle = Partial<Record<keyof CSSStyleDeclaration, string>>;
/**
* Applies style object to HTML Element and returns the previous style in `string` format
*/
export declare const setStyle: (element: HTMLElement, style: CSSStyle) => string | null;
export declare const restoreStyle: (element: HTMLElement, style: string | null) => void;
/**
* Hide HTML Element
*/
export declare const hide: <T extends HTMLElement = HTMLElement>(e: T) => T;
/**
* Show HTML Element
*/
export declare const show: <T extends HTMLElement = HTMLElement>(e: T) => T;
/**
* Remove node from DOM
*/
export declare const remove: (elem: HTMLElement | null) => void;
export {};
import { isString } from "./string";
/**
* Convert a NodeList to array
*/
export const toArray = (nodeList) => Array.prototype.slice.call(nodeList);
/**
* Returns true if initialised
*/
export const loaded = (elem) => elem.getAttribute("idpc") === "true";
/**
* Marks HTML as loaded. i.e. Address validation plugin has been bound to this element
*/
export const markLoaded = (elem) => elem.setAttribute("idpc", "true");
const isTrue = () => true;
/**
* Retrives a parent by tag name
*
* Accepts node as a possible candidate for parent
*
* Executes an additional test if specified
*/
export const getParent = (node, entity, test = isTrue) => {

@@ -34,11 +18,3 @@ let parent = node;

};
/**
* Queries `parent` for a specific `selector`. Returns null if no selector
*/
export const toHtmlElem = (parent, selector) => (selector ? parent.querySelector(selector) : null);
/**
* Retrieves an anchor defined by a query selector
*
* Checks if anchor has been loaded, if not, marks it as loaded
*/
export const getAnchors = (selector, d) => {

@@ -52,5 +28,2 @@ const matches = (d || window.document).querySelectorAll(selector);

};
/**
* Inserts element before `target` element
*/
export const insertBefore = ({ elem, target }) => {

@@ -63,7 +36,2 @@ const parent = target.parentNode;

};
/**
* Scoped retrieval of a HTML element given a querystring or the element itself
*
* @hidden
*/
export const toElem = (elem, context) => {

@@ -74,12 +42,3 @@ if (isString(elem))

};
/**
* @hidden
*/
const d = window.document;
/**
* Outputs scope of controller
* - If null, return window.document
* - If string, resolve with query selector
* - Otherwise returns the HTMLElement or Document
*/
export const getScope = (scope) => {

@@ -92,7 +51,2 @@ if (isString(scope))

};
/**
* Retrieves document instance of HTML Element or Document
*
* Defaults to window.document
*/
export const getDocument = (scope) => {

@@ -105,5 +59,2 @@ if (scope instanceof Document)

};
/**
* Applies style object to HTML Element and returns the previous style in `string` format
*/
export const setStyle = (element, style) => {

@@ -117,5 +68,2 @@ const currentRules = element.getAttribute("style");

};
/**
* Hide HTML Element
*/
export const hide = (e) => {

@@ -125,5 +73,2 @@ e.style.display = "none";

};
/**
* Show HTML Element
*/
export const show = (e) => {

@@ -133,5 +78,2 @@ e.style.display = "";

};
/**
* Remove node from DOM
*/
export const remove = (elem) => {

@@ -138,0 +80,0 @@ if (elem === null || elem.parentNode === null)

@@ -9,16 +9,5 @@ interface EventOptions {

}
/**
* Generates `Event` instance
*
* Includes polyfill where window.Event not available
*/
export declare const newEvent: NewEvent;
/**
* Input events we support
*/
export declare type Events = "change" | "input" | "select";
/**
* Dispatch custom event on element
*/
export declare const trigger: (e: HTMLElement, event: Events) => boolean;
export {};

@@ -1,11 +0,4 @@

/**
* Generates `Event` instance
*
* Includes polyfill where window.Event not available
*/
export const newEvent = ({ event, bubbles = true, cancelable = true, }) => {
// if Event available
if (typeof window.Event === "function")
return new window.Event(event, { bubbles, cancelable });
// Fallback if Event not available (e.g. IE11)
const e = document.createEvent("Event");

@@ -15,5 +8,2 @@ e.initEvent(event, bubbles, cancelable);

};
/**
* Dispatch custom event on element
*/
export const trigger = (e, event) => e.dispatchEvent(newEvent({ event }));
export interface IdGen {
(): string;
}
/**
* Generates a globally unique ID
*/
export declare const idGen: (prefix?: string) => IdGen;
import { idpcState } from "./store";
/**
* Generates a globally unique ID
*/
export const idGen = (prefix = "idpc_") => () => {

@@ -6,0 +3,0 @@ const g = idpcState();

@@ -1,16 +0,4 @@

/**
* Returns true if element is select
*/
export declare const isSelect: (e: HTMLElement | null) => e is HTMLSelectElement;
/**
* Returns true if Element is <input>
*/
export declare const isInput: (e: HTMLElement | null) => e is HTMLInputElement;
/**
* Updates input value and dispatches change envet
*/
export declare const update: (input: HTMLElement | null | undefined, value: string, skipTrigger?: boolean) => void;
/**
* Returns true if HTMLElement has matching value
*/
export declare const hasValue: (select: HTMLElement, value: string | null) => boolean;

@@ -21,12 +9,3 @@ declare type InputElement = HTMLSelectElement | HTMLInputElement;

}
/**
* Assigns value using native property method
*
* If assignment fails, resort to using the setter found in prototype chain
*/
export declare const setValue: SetValue;
/**
* Sets the value of an Element using the setter for value found on the
* protype chain
*/
export declare const forceSetValue: SetValue;

@@ -41,8 +20,3 @@ interface Change {

}
/**
* Updates value of input or select field and triggers an update event
*
* https://github.com/facebook/react/issues/11488#issuecomment-558874287
*/
export declare const change: Change;
export {};
import { trigger } from "./event";
/**
* Returns true if element is select
*/
export const isSelect = (e) => {

@@ -10,5 +7,2 @@ if (e === null)

};
/**
* Returns true if Element is <input>
*/
export const isInput = (e) => {

@@ -19,5 +13,2 @@ if (e === null)

};
/**
* Updates input value and dispatches change envet
*/
export const update = (input, value, skipTrigger = false) => {

@@ -30,5 +21,2 @@ if (!input)

};
/**
* Returns true if HTMLElement has matching value
*/
export const hasValue = (select, value) => {

@@ -39,5 +27,2 @@ if (value === null)

};
/**
* Updates value property of HTMLSelectElement
*/
const updateSelect = ({ e, value, skipTrigger }) => {

@@ -53,7 +38,2 @@ if (value === null)

};
/**
* Assigns value using native property method
*
* If assignment fails, resort to using the setter found in prototype chain
*/
export const setValue = (e, value) => {

@@ -64,6 +44,2 @@ e.value = value;

};
/**
* Sets the value of an Element using the setter for value found on the
* protype chain
*/
export const forceSetValue = (e, value) => {

@@ -78,5 +54,2 @@ const descriptor = Object.getOwnPropertyDescriptor(e.constructor.prototype, "value");

};
/**
* Updates value property of HTMLInputElement
*/
const updateInput = ({ e, value, skipTrigger }) => {

@@ -92,7 +65,2 @@ if (value === null)

};
/**
* Updates value of input or select field and triggers an update event
*
* https://github.com/facebook/react/issues/11488#issuecomment-558874287
*/
export const change = (options) => {

@@ -99,0 +67,0 @@ if (options.value === null)

@@ -6,5 +6,2 @@ declare global {

}
/**
* Global store. Aimed at ensuring multiple copies of our JS libs can have some shared state if required
*/
export interface IdpcGlobal {

@@ -14,5 +11,2 @@ idGen?: Record<string, number>;

export declare const idpcState: () => IdpcGlobal;
/**
* Resets global store
*/
export declare const reset: () => void;

@@ -1,12 +0,7 @@

/**
* @hidden
*/
let g = {};
if (window) {
if (window.idpcGlobal) {
// Adopt idpcGlobal from window if it exists
g = window.idpcGlobal;
}
else {
// Assign idpcGlobal to window if not exists
window.idpcGlobal = g;

@@ -16,5 +11,2 @@ }

export const idpcState = () => g;
/**
* Resets global store
*/
export const reset = () => Object.getOwnPropertyNames(g).forEach((p) => delete g[p]);
export declare const isString: (input: unknown) => input is string;
/**
* Returns true if substring match
*/
export declare const includes: (haystack: string, needle: string) => boolean;
export const isString = (input) => typeof input === "string";
/**
* Returns true if substring match
*/
export const includes = (haystack, needle) => haystack.indexOf(needle) !== -1;
import { Address } from "@ideal-postcodes/api-typings";
export interface Binding {
/**
* Verify if can be launched
*/
pageTest: PageTest;
/**
* Binds to page
*/
bind: Bind;

@@ -35,60 +29,13 @@ }

export interface Config {
/**
* Enable / disable the integration altogether
*/
enabled: boolean;
/**
* A string of characters. Typically begins `ak_`
*
* The API Key is required to verify your account for address validation. View your API Keys from your [account dashboard](https://ideal-postcodes.co.uk/tokens).
*
* See our [API Key guide](https://ideal-postcodes.co.uk/guides/api-key) to find out more.
*/
apiKey: string;
/**
* Addresses with an organisation will overwrite the value of the company name field.
*/
populateOrganisation: boolean;
/**
* Populate the county field of an address. County data is optional for premise identification.
*
* We recommend avoid using county data altogether. Find out more from our [UK county data guide](https://ideal-postcodes.co.uk/guides/county-data).
*/
populateCounty: boolean;
/**
* Setting this to `true` will enable autocomplete integration on your address forms.
*
* See our [Address Finder Demo](https://ideal-postcodes.co.uk/address-finder) to try it out.
*/
autocomplete: boolean;
/**
* *Advanced.* Override the autocompletion plugin configuration.
*
* Pass in a [valid configuration object](https://ideal-postcodes.co.uk/documentation/ideal-postcodes-autocomplete#config) to override specific autocomplete configuration attributes.
*/
autocompleteOverride: AutocompleteConfig;
/**
* Setting this to `true` will enable postcode lookup integration on your address forms.
*
* See our [Postcode Finder Demo](https://ideal-postcodes.co.uk/postcode-finder) to try it out.
*/
postcodeLookup: boolean;
/**
* *Advanced.* Override the postcode lookup plugin configuration.
*
* Pass in a [valid configuration object](https://ideal-postcodes.co.uk/documentation/jquery-plugin) to override specific postcode lookup configuration settings.
*/
postcodeLookupOverride: PostcodeLookupConfig;
/**
* Setting this to `true` will detach our Address Validation tools from the page if an unsupported terrority is selected
*/
watchCountry?: boolean;
/**
* Setting this to `true` will attempt to deploy the Address Finder on an input away from line_1
*/
separateFinder?: boolean;
}
/**
* A map of HTML elements to be populated with address data
*/
export interface Targets {

@@ -104,45 +51,14 @@ line_1: HTMLElement | null;

}
/**
* Placeholder
*/
export declare type AutocompleteConfig = any;
export declare type PostcodeLookupConfig = any;
/**
* Countries returned by API. Splits "United Kingdom" into constitutent country
*/
export declare type UkCountry = "England" | "Wales" | "Northern Ireland" | "Scotland" | "Channel Islands" | "Isle of Man";
/**
* Channel Island ISO Codes
*/
export declare type ChannelIslandIso = "JE" | "GG";
/**
* ISO Country codes
*/
export declare type CountryIso = "GB" | "IM" | ChannelIslandIso;
/**
* Country
*/
export declare type Country = "United Kingdom" | "Jersey" | "Guernsey" | "Isle of Man";
export declare type LineCount = 1 | 2 | 3;
/**
* Describes availability of specific on page assets
* complete - Asset is either not required or loaded
* loading - Asset being retrieved or parsed
*/
export declare type LoadState = "complete" | "loading";
/**
* Method used to test whether a DOM element qualifies as parent
*/
export interface ParentTest {
(e: HTMLElement): boolean;
}
/**
* OutputFields can be identified by the address attributes supported by the API
*
* Typings for the API Address object can be found at [@ideal-postcodes/api-typings](https://api-typings.ideal-postcodes.dev/interfaces/address.html)
*/
export declare type OutputFields = Partial<Record<keyof Address, SelectorNode>>;
/**
* Represents either a HTMLInputelement or a selector pointing to one
*/
export declare type SelectorNode = string | HTMLInputElement | HTMLTextAreaElement;
import { Bind, Start, ParentTest, Stop, PageTest, Config, Selectors, Targets, Binding } from "./types";
/**
* Returns an object of attributes mapped to HTMLInputElement
*
* Returns null if any critical elements are not present (line 1, post_town, postcode)
*
* @deprecated
*/
export declare const getTargets: (parent: HTMLElement, selectors: Selectors) => Targets | null;
/**
* Given a list of bindings, return true if any are relevant to current pae
*/
export declare const relevantPage: (bindings: Binding[]) => boolean;
/**
* Setup defaults
*/
export declare const defaults: Config;

@@ -44,23 +31,8 @@ export declare const config: () => Config | undefined;

}
/**
* Deploys address search tools on page using predefined bindings
*/
export declare const setup: Setup;
interface SetupBindOptions {
selectors: Selectors;
/**
* Query selector that defines anchor. Defaults to selectors.line_1
*/
anchorSelector?: string;
/**
* Restricts subsequent selector scope once anchor is found. Defaults to `form`
*/
parentScope?: string;
/**
* Allow search in specific document
*/
doc?: Document;
/**
* Optional test to select for parent/scope
*/
parentTest?: ParentTest;

@@ -67,0 +39,0 @@ }

import { toHtmlElem, getAnchors, getParent } from "./dom";
/**
* Returns an object of attributes mapped to HTMLInputElement
*
* Returns null if any critical elements are not present (line 1, post_town, postcode)
*
* @deprecated
*/
export const getTargets = (parent, selectors) => {

@@ -35,9 +28,3 @@ const line_1 = toHtmlElem(parent, selectors.line_1);

};
/**
* Given a list of bindings, return true if any are relevant to current pae
*/
export const relevantPage = (bindings) => bindings.some((b) => b.pageTest());
/**
* Setup defaults
*/
export const defaults = {

@@ -48,6 +35,4 @@ enabled: true,

populateCounty: false,
// Autocomplete config
autocomplete: true,
autocompleteOverride: {},
// Postcode lookup config
postcodeLookup: true,

@@ -72,5 +57,3 @@ postcodeLookupOverride: {},

catch (e) {
// Terminate timer if some exception is raised
stop();
/* eslint no-console: ["error", { allow: ["log"] }] */
console.log(e);

@@ -90,5 +73,2 @@ }

const NOOP = () => { };
/**
* Deploys address search tools on page using predefined bindings
*/
export const setup = ({ bindings, callback = NOOP }) => {

@@ -95,0 +75,0 @@ const c = config();

{
"name": "@ideal-postcodes/jsutil",
"version": "4.3.4",
"version": "4.3.5",
"description": "Browser Address Autocomplete for api.ideal-postcodes.co.uk",

@@ -95,3 +95,3 @@ "author": {

},
"license": "MIT",
"license": "Copyright IDDQD Limited",
"dependencies": {

@@ -98,0 +98,0 @@ "capitalise-post-town": "~2.0.3"

[![codecov](https://codecov.io/gh/ideal-postcodes/jsutil/branch/master/graph/badge.svg?token=4VJlNKmzMu)](https://codecov.io/gh/ideal-postcodes/jsutil)
![Release](https://github.com/ideal-postcodes/jsutil/workflows/Release/badge.svg)
![CI](https://github.com/ideal-postcodes/jsutil/workflows/CI/badge.svg)
[![npm version](https://badge.fury.io/js/%40ideal-postcodes%2Fjsutil.svg)](https://badge.fury.io/js/%40ideal-postcodes%2Fjsutil)

@@ -23,3 +21,2 @@ ![Cross Browser Testing](https://github.com/ideal-postcodes/jsutil/workflows/Cross%20Browser%20Testing/badge.svg)

- [Integrations](https://ideal-postcodes.co.uk/integrations)
- [Documentation](https://jsutil.ideal-postcodes.dev)

@@ -34,2 +31,2 @@ ## Test

MIT
Copyright IDDQD Limited
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc