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

@ideal-postcodes/jsutil

Package Overview
Dependencies
Maintainers
3
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 6.4.0 to 7.0.0

20

CHANGELOG.md

@@ -0,1 +1,21 @@

# [7.0.0](https://github.com/ideal-postcodes/jsutil/compare/6.4.0...7.0.0) (2024-03-05)
### Bug Fixes
* **PopulateAddress:** Retain organisation name ([92deaac](https://github.com/ideal-postcodes/jsutil/commit/92deaac30e0eb3851acfcbff140003b95fb6ad61))
### Features
* **MutateAddress:** Export address mutate method ([9890f6e](https://github.com/ideal-postcodes/jsutil/commit/9890f6ec2e6f45b2de479c21f7d8b6ce1e706d24))
### BREAKING CHANGES
* **PopulateAddress:** If org name is to be omitted from address line, continue to
offer it via organisation_name field.
No compelling reason for old behaviour
# [6.4.0](https://github.com/ideal-postcodes/jsutil/compare/6.3.0...6.4.0) (2023-10-27)

@@ -2,0 +22,0 @@

15

dist/address.d.ts

@@ -18,2 +18,3 @@ import { AnyAddress, GbrAddress } from "./types";

export interface MaxLineConfig {
lines?: LineCount;
maxLineOne?: number;

@@ -25,3 +26,2 @@ maxLineTwo?: number;

scope: HTMLElement | Document;
titleizePostTown?: boolean;
removeOrganisation?: boolean;

@@ -38,2 +38,11 @@ populateCounty?: boolean;

}
export interface MutateConfig extends MaxLineConfig {
removeOrganisation?: boolean;
populateCounty?: boolean;
populateOrganisation?: boolean;
}
export interface MutateAddressOptions {
address: AnyAddress;
config: MutateConfig;
}
interface PopulateAddress {

@@ -44,4 +53,8 @@ (options: PopulateAddressOptions): void;

export declare const searchLabels: (labels: NamedFields, scope: HTMLElement | Document) => OutputFields;
interface MutateAddress {
(options: PopulateAddressOptions): AnyAddress;
}
export declare const mutateAddress: MutateAddress;
export declare const populateAddress: PopulateAddress;
export declare const removeOrganisation: (address: GbrAddress) => GbrAddress;
export {};

47

dist/address.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeOrganisation = exports.populateAddress = exports.searchLabels = exports.searchNames = exports.getFields = exports.extract = exports.toAddressLines = exports.toMaxLengthLines = exports.charArrayLength = exports.join = exports.numberOfLines = void 0;
const capitalise_post_town_1 = require("capitalise-post-town");
exports.removeOrganisation = exports.populateAddress = exports.mutateAddress = exports.searchLabels = exports.searchNames = exports.getFields = exports.extract = exports.toAddressLines = exports.toMaxLengthLines = exports.charArrayLength = exports.join = exports.numberOfLines = void 0;
const input_1 = require("./input");

@@ -123,8 +122,2 @@ const dom_1 = require("./dom");

exports.getFields = getFields;
const updateLines = (fields, address, scope, config) => {
const [line_1, line_2, line_3] = (0, exports.toAddressLines)((0, exports.numberOfLines)(fields), address, config);
(0, input_1.update)((0, dom_1.toElem)(fields.line_1 || null, scope), line_1);
(0, input_1.update)((0, dom_1.toElem)(fields.line_2 || null, scope), line_2);
(0, input_1.update)((0, dom_1.toElem)(fields.line_3 || null, scope), line_3);
};
const searchNames = (names, scope) => {

@@ -179,24 +172,32 @@ const result = {};

exports.searchLabels = searchLabels;
const skipFields = ["country", "country_iso_2", "country_iso"];
const mutateAddress = (o) => {
const address = { ...o.address };
if ((0, types_1.isGbrAddress)(address)) {
if (o.config.removeOrganisation)
(0, exports.removeOrganisation)(address);
}
const [line_1, line_2, line_3] = (0, exports.toAddressLines)(o.config.lines || 3, address, o.config);
address.line_1 = line_1;
address.line_2 = line_2;
if ((0, types_1.isGbrAddress)(address))
address.line_3 = line_3;
return address;
};
exports.mutateAddress = mutateAddress;
const populateAddress = (options) => {
const { config } = options;
const address = { ...options.address };
const { scope, titleizePostTown, populateOrganisation, populateCounty } = config;
const address = (0, exports.mutateAddress)(options);
const { scope, populateCounty } = config;
const fields = (0, exports.getFields)(options);
if (config.lines !== undefined)
config.lines = (0, exports.numberOfLines)(fields);
const skip = [...skipFields];
if ((0, types_1.isGbrAddress)(address)) {
if (config.removeOrganisation)
(0, exports.removeOrganisation)(address);
if ("post_town" in address && titleizePostTown) {
address.post_town = (0, capitalise_post_town_1.capitalisePostTown)(address.post_town);
}
if (populateOrganisation === false)
delete address.organisation_name;
if (populateCounty === false)
delete address.county;
skip.push("county");
}
updateLines(fields, address, scope, config);
delete address.line_1;
delete address.line_2;
delete address.line_3;
(0, country_1.updateCountry)((0, dom_1.toElem)(fields.country || null, scope), address);
delete address.country;
const iso2Elem = (0, dom_1.toElem)(fields.country_iso_2 || null, scope);

@@ -210,3 +211,2 @@ if ((0, input_1.isSelect)(iso2Elem)) {

}
delete address.country_iso_2;
const iso3Elem = (0, dom_1.toElem)(fields.country_iso || null, scope);

@@ -219,5 +219,6 @@ if ((0, input_1.isSelect)(iso3Elem)) {

(0, input_1.update)(iso3Elem, address.country_iso || "");
delete address.country_iso;
let e;
for (e in fields) {
if (skip.includes(e))
continue;
if (address[e] === undefined)

@@ -224,0 +225,0 @@ continue;

@@ -18,2 +18,3 @@ import { AnyAddress, GbrAddress } from "./types";

export interface MaxLineConfig {
lines?: LineCount;
maxLineOne?: number;

@@ -25,3 +26,2 @@ maxLineTwo?: number;

scope: HTMLElement | Document;
titleizePostTown?: boolean;
removeOrganisation?: boolean;

@@ -38,2 +38,11 @@ populateCounty?: boolean;

}
export interface MutateConfig extends MaxLineConfig {
removeOrganisation?: boolean;
populateCounty?: boolean;
populateOrganisation?: boolean;
}
export interface MutateAddressOptions {
address: AnyAddress;
config: MutateConfig;
}
interface PopulateAddress {

@@ -44,4 +53,8 @@ (options: PopulateAddressOptions): void;

export declare const searchLabels: (labels: NamedFields, scope: HTMLElement | Document) => OutputFields;
interface MutateAddress {
(options: PopulateAddressOptions): AnyAddress;
}
export declare const mutateAddress: MutateAddress;
export declare const populateAddress: PopulateAddress;
export declare const removeOrganisation: (address: GbrAddress) => GbrAddress;
export {};

@@ -1,2 +0,1 @@

import { capitalisePostTown } from "capitalise-post-town";
import { update, change, isSelect, isInput, hasValue } from "./input";

@@ -113,8 +112,2 @@ import { toElem, contains } from "./dom";

});
const updateLines = (fields, address, scope, config) => {
const [line_1, line_2, line_3] = toAddressLines(numberOfLines(fields), address, config);
update(toElem(fields.line_1 || null, scope), line_1);
update(toElem(fields.line_2 || null, scope), line_2);
update(toElem(fields.line_3 || null, scope), line_3);
};
export const searchNames = (names, scope) => {

@@ -167,24 +160,31 @@ const result = {};

};
const skipFields = ["country", "country_iso_2", "country_iso"];
export const mutateAddress = (o) => {
const address = { ...o.address };
if (isGbrAddress(address)) {
if (o.config.removeOrganisation)
removeOrganisation(address);
}
const [line_1, line_2, line_3] = toAddressLines(o.config.lines || 3, address, o.config);
address.line_1 = line_1;
address.line_2 = line_2;
if (isGbrAddress(address))
address.line_3 = line_3;
return address;
};
export const populateAddress = (options) => {
const { config } = options;
const address = { ...options.address };
const { scope, titleizePostTown, populateOrganisation, populateCounty } = config;
const address = mutateAddress(options);
const { scope, populateCounty } = config;
const fields = getFields(options);
if (config.lines !== undefined)
config.lines = numberOfLines(fields);
const skip = [...skipFields];
if (isGbrAddress(address)) {
if (config.removeOrganisation)
removeOrganisation(address);
if ("post_town" in address && titleizePostTown) {
address.post_town = capitalisePostTown(address.post_town);
}
if (populateOrganisation === false)
delete address.organisation_name;
if (populateCounty === false)
delete address.county;
skip.push("county");
}
updateLines(fields, address, scope, config);
delete address.line_1;
delete address.line_2;
delete address.line_3;
updateCountry(toElem(fields.country || null, scope), address);
delete address.country;
const iso2Elem = toElem(fields.country_iso_2 || null, scope);

@@ -198,3 +198,2 @@ if (isSelect(iso2Elem)) {

}
delete address.country_iso_2;
const iso3Elem = toElem(fields.country_iso || null, scope);

@@ -207,5 +206,6 @@ if (isSelect(iso3Elem)) {

update(iso3Elem, address.country_iso || "");
delete address.country_iso;
let e;
for (e in fields) {
if (skip.includes(e))
continue;
if (address[e] === undefined)

@@ -212,0 +212,0 @@ continue;

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

@@ -102,5 +102,3 @@ "author": {

"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"capitalise-post-town": "~3.0.1"
},
"dependencies": {},
"devDependencies": {

@@ -107,0 +105,0 @@ "@babel/core": "~7.18.10",

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