From 138c5e9f332dea57747e8540e02b129324211e5e Mon Sep 17 00:00:00 2001 From: abiddiscombe <76795128+abiddiscombe@users.noreply.github.com> Date: Sat, 2 Sep 2023 11:42:19 +0100 Subject: [PATCH 1/4] docs: fix spelling errors --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 25854af..936f5be 100644 --- a/README.md +++ b/README.md @@ -241,7 +241,7 @@ Parameters: Optional Parameters (add as named arguments e.g. `{crs: 27700}`): - `offset` (integer, default 0) - The starting position to collect features -- `limit` (integrer, default 1,000) - The maximum number of features to return +- `limit` (integer, default 1,000) - The maximum number of features to return #### [**Point-Based Radius**](https://ordnancesurvey.github.io/osdatahub-js/docs/functions/placesAPI.radius.html) @@ -260,7 +260,7 @@ Parameters: Optional Parameters (add as named arguments e.g. `{crs: 27700}`): - `offset` (integer, default 0) - The starting position to collect features -- `limit` (integrer, default 1,000) - The maximum number of features to return +- `limit` (integer, default 1,000) - The maximum number of features to return #### [**Nearest Feature**](https://ordnancesurvey.github.io/osdatahub-js/docs/functions/placesAPI.nearest.html) @@ -291,7 +291,7 @@ Parameters: Optional Parameters (add as named arguments e.g. `{crs: 27700}`): - `offset` (integer, default 0) - The starting position to collect features -- `limit` (integrer, default 1,000) - The maximum number of features to return +- `limit` (integer, default 1,000) - The maximum number of features to return #### [**UPRN (Unique Property Reference Number)**](https://ordnancesurvey.github.io/osdatahub-js/docs/functions/placesAPI.uprn.html) @@ -304,7 +304,7 @@ osdatahub.placesAPI.uprn(apiKey, uprnIdentifer, {}); Parameters: - `apiKey` (string) - Your OS Data Hub API Key -- `uprnIdentifier` (integer) - A valid UPRN identifer +- `uprnIdentifier` (integer) - A valid UPRN identifier #### [**Postcode (Full or Partial)**](https://ordnancesurvey.github.io/osdatahub-js/docs/functions/placesAPI.postcode.html) @@ -322,7 +322,7 @@ Parameters: Optional Parameters (add as named arguments e.g. `{crs: 27700}`): - `offset` (integer, default 0) - The starting position to collect features -- `limit` (integrer, default 1,000) - The maximum number of features to return +- `limit` (integer, default 1,000) - The maximum number of features to return #### [**Find (Plain Text Search)**](https://ordnancesurvey.github.io/osdatahub-js/docs/functions/placesAPI.find.html) @@ -340,7 +340,7 @@ Parameters: Optional Parameters (add as named arguments e.g. `{crs: 27700}`): - `offset` (integer, default 0) - The starting position to collect features -- `limit` (integrer, default 1,000) - The maximum number of features to return +- `limit` (integer, default 1,000) - The maximum number of features to return
@@ -379,7 +379,7 @@ Parameters: Optional Parameters (add as named arguments e.g. `{crs: 27700}`): - `offset` (integer, default 0) - The starting position to collect features -- `limit` (integrer, default 1,000) - The maximum number of features to return +- `limit` (integer, default 1,000) - The maximum number of features to return ## Authors From 90d35783736e8ac840a51ad0cfbb7cbeeebacf79 Mon Sep 17 00:00:00 2001 From: abiddiscombe <76795128+abiddiscombe@users.noreply.github.com> Date: Sat, 2 Sep 2023 11:43:19 +0100 Subject: [PATCH 2/4] docs: remove ad message --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 936f5be..2e6ab57 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,6 @@ Ordnance Survey is the national mapping agency for Great Britain and produces a - Data Hub Explorer: [https://labs.os.uk/prototyping/data-hub-explorer/](https://labs.os.uk/prototyping/data-hub-explorer/) - Free Software: [Open Government License](https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/) -**Note:** This package is under active development. - ## Contents - [osdatahub (JavaScript)](#osdatahub-javascript) From 2d1a32f5f0723a4398c7f8780aed56c4739c6876 Mon Sep 17 00:00:00 2001 From: abiddiscombe <76795128+abiddiscombe@users.noreply.github.com> Date: Sat, 2 Sep 2023 11:45:27 +0100 Subject: [PATCH 3/4] docs: expand NGD acronym --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2e6ab57..d344ee9 100644 --- a/README.md +++ b/README.md @@ -134,7 +134,7 @@ Different APIs support different search operations. Let's explore them... --- -The OS NGD API can be accessed via `osdatahub.ngd`. For further information on using the OS NGD API and its capabilities, please refer to the [OS Data Hub](https://osdatahub.os.uk/docs/ofa/overview) documentation and technical specification. +The OS NGD (National Geographic Database) API can be accessed via `osdatahub.ngd`. For further information on using the OS NGD API and its capabilities, please refer to the [OS Data Hub](https://osdatahub.os.uk/docs/ofa/overview) documentation and technical specification. #### [**Features (Collection Items)**](https://ordnancesurvey.github.io/osdatahub-js/docs/functions/ngd.features.html) From d15537ee894150aef48357386fa3dca1074e8e96 Mon Sep 17 00:00:00 2001 From: abiddiscombe Date: Sat, 2 Sep 2023 10:53:09 +0000 Subject: [PATCH 4/4] Prettified Code! --- docs/assets/main.js | 34 ++++++++++++------------ docs/assets/search.js | 2 +- src/names.ts | 6 ++--- src/ngd.ts | 14 +++++----- src/places.ts | 26 +++++++++--------- src/utils/coords.ts | 4 +-- src/utils/geojson.ts | 6 ++--- src/utils/ngd/request.ts | 2 +- src/utils/ngd/url.ts | 2 +- src/utils/ngd/validate.ts | 4 +-- src/utils/request.ts | 8 +++--- src/utils/url.ts | 2 +- src/utils/validate.ts | 20 +++++++------- tests/crs.test.ts | 4 +-- tests/names.test.ts | 6 ++--- tests/ngd.test.ts | 30 ++++++++++----------- tests/places.test.ts | 56 +++++++++++++++++++-------------------- 17 files changed, 113 insertions(+), 113 deletions(-) diff --git a/docs/assets/main.js b/docs/assets/main.js index f248f82..0e5f4b0 100644 --- a/docs/assets/main.js +++ b/docs/assets/main.js @@ -27,7 +27,7 @@ e || !t || !t.__esModule ? ae(n, "default", { value: t, enumerable: !0 }) : n, - t + t, ) ); var de = _e((ce, he) => { @@ -73,7 +73,7 @@ continue; } throw new TypeError( - "clone is not deep and does not support nested objects" + "clone is not deep and does not support nested objects", ); } return n; @@ -151,7 +151,7 @@ : e === t.Set.empty ? this : new t.Set( - Object.keys(this.elements).concat(Object.keys(e.elements)) + Object.keys(this.elements).concat(Object.keys(e.elements)), ); }), (t.idf = function (e, n) { @@ -185,7 +185,7 @@ return e.map(function (m) { return new t.Token( t.utils.asString(m).toLowerCase(), - t.utils.clone(n) + t.utils.clone(n), ); }); for ( @@ -228,7 +228,7 @@ t.utils.warn( `Function is not registered with pipeline. This may cause problems when serialising the index. `, - e + e, ); }), (t.Pipeline.load = function (e) { @@ -1021,7 +1021,7 @@ t.version + "' does not match serialized index '" + e.version + - "'" + "'", ); for (var l = 0; l < i.length; l++) { var h = i[l], @@ -1067,7 +1067,7 @@ (t.Builder.prototype.field = function (e, n) { if (/\//.test(e)) throw new RangeError( - "Field '" + e + "' contains illegal character '/'" + "Field '" + e + "' contains illegal character '/'", ); this._fields[e] = n || {}; }), @@ -1190,7 +1190,7 @@ }), (t.Builder.prototype.createTokenSet = function () { this.tokenSet = t.TokenSet.fromArray( - Object.keys(this.invertedIndex).sort() + Object.keys(this.invertedIndex).sort(), ); }), (t.Builder.prototype.build = function () { @@ -1241,7 +1241,7 @@ this.metadata[i][a][h] == null ? (this.metadata[i][a][h] = e.metadata[i][a][h]) : (this.metadata[i][a][h] = this.metadata[i][a][h].concat( - e.metadata[i][a][h] + e.metadata[i][a][h], )); } } @@ -1704,11 +1704,11 @@ (this.navigation = document.querySelector(".col-menu")), window.addEventListener( "scroll", - ne(() => this.onScroll(), 10) + ne(() => this.onScroll(), 10), ), window.addEventListener( "resize", - ne(() => this.onResize(), 10) + ne(() => this.onResize(), 10), ), (this.searchInput = document.querySelector("#tsd-search input")), this.searchInput && @@ -1827,7 +1827,7 @@ r = document.querySelector("#tsd-search .results"); if (!n || !r) throw new Error( - "The input field or the result list wrapper was not found" + "The input field or the result list wrapper was not found", ); let i = !1; r.addEventListener("mousedown", () => (i = !0)), @@ -1846,7 +1846,7 @@ "input", ue(() => { Ae(t, e, n, r); - }, 200) + }, 200), ); let i = !1; n.addEventListener("keydown", (s) => { @@ -1943,7 +1943,7 @@ for (; o != -1; ) i.push( ie(t.substring(s, o)), - `${ie(t.substring(o, o + r.length))}` + `${ie(t.substring(o, o + r.length))}`, ), (s = o + r.length), (o = n.indexOf(r, s)); @@ -1968,7 +1968,7 @@ je = !1, H = !1, xe = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( - navigator.userAgent + navigator.userAgent, ); document.documentElement.classList.add(xe ? "is-mobile" : "not-mobile"); xe && @@ -2073,7 +2073,7 @@ document.querySelectorAll(".tsd-index-section").forEach((n) => { n.style.display = "block"; let r = Array.from(n.querySelectorAll(".tsd-index-link")).every( - (i) => i.offsetParent == null + (i) => i.offsetParent == null, ); n.style.display = r ? "none" : "block"; }); @@ -2139,7 +2139,7 @@ this.getIconRotation(i), ], }, - o + o, ) .addEventListener("finish", () => { this.icon.style.transform = this.getIconRotation(i); diff --git a/docs/assets/search.js b/docs/assets/search.js index efb8456..a876611 100644 --- a/docs/assets/search.js +++ b/docs/assets/search.js @@ -1,3 +1,3 @@ window.searchData = JSON.parse( - '{"kinds":{"4":"Namespace","64":"Function"},"rows":[{"kind":4,"name":"namesAPI","url":"modules/namesAPI.html","classes":"tsd-kind-namespace"},{"kind":64,"name":"nearest","url":"functions/namesAPI.nearest.html","classes":"tsd-kind-function tsd-parent-kind-namespace","parent":"namesAPI"},{"kind":64,"name":"find","url":"functions/namesAPI.find.html","classes":"tsd-kind-function tsd-parent-kind-namespace","parent":"namesAPI"},{"kind":4,"name":"placesAPI","url":"modules/placesAPI.html","classes":"tsd-kind-namespace"},{"kind":64,"name":"polygon","url":"functions/placesAPI.polygon.html","classes":"tsd-kind-function tsd-parent-kind-namespace","parent":"placesAPI"},{"kind":64,"name":"radius","url":"functions/placesAPI.radius.html","classes":"tsd-kind-function tsd-parent-kind-namespace","parent":"placesAPI"},{"kind":64,"name":"bbox","url":"functions/placesAPI.bbox.html","classes":"tsd-kind-function tsd-parent-kind-namespace","parent":"placesAPI"},{"kind":64,"name":"nearest","url":"functions/placesAPI.nearest.html","classes":"tsd-kind-function tsd-parent-kind-namespace","parent":"placesAPI"},{"kind":64,"name":"uprn","url":"functions/placesAPI.uprn.html","classes":"tsd-kind-function tsd-parent-kind-namespace","parent":"placesAPI"},{"kind":64,"name":"postcode","url":"functions/placesAPI.postcode.html","classes":"tsd-kind-function tsd-parent-kind-namespace","parent":"placesAPI"},{"kind":64,"name":"find","url":"functions/placesAPI.find.html","classes":"tsd-kind-function tsd-parent-kind-namespace","parent":"placesAPI"},{"kind":4,"name":"ngd","url":"modules/ngd.html","classes":"tsd-kind-namespace"},{"kind":64,"name":"features","url":"functions/ngd.features.html","classes":"tsd-kind-function tsd-parent-kind-namespace","parent":"ngd"},{"kind":64,"name":"collections","url":"functions/ngd.collections.html","classes":"tsd-kind-function tsd-parent-kind-namespace","parent":"ngd"},{"kind":64,"name":"schema","url":"functions/ngd.schema.html","classes":"tsd-kind-function tsd-parent-kind-namespace","parent":"ngd"},{"kind":64,"name":"queryables","url":"functions/ngd.queryables.html","classes":"tsd-kind-function tsd-parent-kind-namespace","parent":"ngd"},{"kind":64,"name":"feature","url":"functions/ngd.feature.html","classes":"tsd-kind-function tsd-parent-kind-namespace","parent":"ngd"}],"index":{"version":"2.3.9","fields":["name","comment"],"fieldVectors":[["name/0",[0,24.849]],["comment/0",[]],["name/1",[1,19.741]],["comment/1",[]],["name/2",[2,19.741]],["comment/2",[]],["name/3",[3,24.849]],["comment/3",[]],["name/4",[4,24.849]],["comment/4",[]],["name/5",[5,24.849]],["comment/5",[]],["name/6",[6,24.849]],["comment/6",[]],["name/7",[1,19.741]],["comment/7",[]],["name/8",[7,24.849]],["comment/8",[]],["name/9",[8,24.849]],["comment/9",[]],["name/10",[2,19.741]],["comment/10",[]],["name/11",[9,24.849]],["comment/11",[]],["name/12",[10,24.849]],["comment/12",[]],["name/13",[11,24.849]],["comment/13",[]],["name/14",[12,24.849]],["comment/14",[]],["name/15",[13,24.849]],["comment/15",[]],["name/16",[14,24.849]],["comment/16",[]]],"invertedIndex":[["bbox",{"_index":6,"name":{"6":{}},"comment":{}}],["collections",{"_index":11,"name":{"13":{}},"comment":{}}],["feature",{"_index":14,"name":{"16":{}},"comment":{}}],["features",{"_index":10,"name":{"12":{}},"comment":{}}],["find",{"_index":2,"name":{"2":{},"10":{}},"comment":{}}],["namesapi",{"_index":0,"name":{"0":{}},"comment":{}}],["nearest",{"_index":1,"name":{"1":{},"7":{}},"comment":{}}],["ngd",{"_index":9,"name":{"11":{}},"comment":{}}],["placesapi",{"_index":3,"name":{"3":{}},"comment":{}}],["polygon",{"_index":4,"name":{"4":{}},"comment":{}}],["postcode",{"_index":8,"name":{"9":{}},"comment":{}}],["queryables",{"_index":13,"name":{"15":{}},"comment":{}}],["radius",{"_index":5,"name":{"5":{}},"comment":{}}],["schema",{"_index":12,"name":{"14":{}},"comment":{}}],["uprn",{"_index":7,"name":{"8":{}},"comment":{}}]],"pipeline":[]}}' + '{"kinds":{"4":"Namespace","64":"Function"},"rows":[{"kind":4,"name":"namesAPI","url":"modules/namesAPI.html","classes":"tsd-kind-namespace"},{"kind":64,"name":"nearest","url":"functions/namesAPI.nearest.html","classes":"tsd-kind-function tsd-parent-kind-namespace","parent":"namesAPI"},{"kind":64,"name":"find","url":"functions/namesAPI.find.html","classes":"tsd-kind-function tsd-parent-kind-namespace","parent":"namesAPI"},{"kind":4,"name":"placesAPI","url":"modules/placesAPI.html","classes":"tsd-kind-namespace"},{"kind":64,"name":"polygon","url":"functions/placesAPI.polygon.html","classes":"tsd-kind-function tsd-parent-kind-namespace","parent":"placesAPI"},{"kind":64,"name":"radius","url":"functions/placesAPI.radius.html","classes":"tsd-kind-function tsd-parent-kind-namespace","parent":"placesAPI"},{"kind":64,"name":"bbox","url":"functions/placesAPI.bbox.html","classes":"tsd-kind-function tsd-parent-kind-namespace","parent":"placesAPI"},{"kind":64,"name":"nearest","url":"functions/placesAPI.nearest.html","classes":"tsd-kind-function tsd-parent-kind-namespace","parent":"placesAPI"},{"kind":64,"name":"uprn","url":"functions/placesAPI.uprn.html","classes":"tsd-kind-function tsd-parent-kind-namespace","parent":"placesAPI"},{"kind":64,"name":"postcode","url":"functions/placesAPI.postcode.html","classes":"tsd-kind-function tsd-parent-kind-namespace","parent":"placesAPI"},{"kind":64,"name":"find","url":"functions/placesAPI.find.html","classes":"tsd-kind-function tsd-parent-kind-namespace","parent":"placesAPI"},{"kind":4,"name":"ngd","url":"modules/ngd.html","classes":"tsd-kind-namespace"},{"kind":64,"name":"features","url":"functions/ngd.features.html","classes":"tsd-kind-function tsd-parent-kind-namespace","parent":"ngd"},{"kind":64,"name":"collections","url":"functions/ngd.collections.html","classes":"tsd-kind-function tsd-parent-kind-namespace","parent":"ngd"},{"kind":64,"name":"schema","url":"functions/ngd.schema.html","classes":"tsd-kind-function tsd-parent-kind-namespace","parent":"ngd"},{"kind":64,"name":"queryables","url":"functions/ngd.queryables.html","classes":"tsd-kind-function tsd-parent-kind-namespace","parent":"ngd"},{"kind":64,"name":"feature","url":"functions/ngd.feature.html","classes":"tsd-kind-function tsd-parent-kind-namespace","parent":"ngd"}],"index":{"version":"2.3.9","fields":["name","comment"],"fieldVectors":[["name/0",[0,24.849]],["comment/0",[]],["name/1",[1,19.741]],["comment/1",[]],["name/2",[2,19.741]],["comment/2",[]],["name/3",[3,24.849]],["comment/3",[]],["name/4",[4,24.849]],["comment/4",[]],["name/5",[5,24.849]],["comment/5",[]],["name/6",[6,24.849]],["comment/6",[]],["name/7",[1,19.741]],["comment/7",[]],["name/8",[7,24.849]],["comment/8",[]],["name/9",[8,24.849]],["comment/9",[]],["name/10",[2,19.741]],["comment/10",[]],["name/11",[9,24.849]],["comment/11",[]],["name/12",[10,24.849]],["comment/12",[]],["name/13",[11,24.849]],["comment/13",[]],["name/14",[12,24.849]],["comment/14",[]],["name/15",[13,24.849]],["comment/15",[]],["name/16",[14,24.849]],["comment/16",[]]],"invertedIndex":[["bbox",{"_index":6,"name":{"6":{}},"comment":{}}],["collections",{"_index":11,"name":{"13":{}},"comment":{}}],["feature",{"_index":14,"name":{"16":{}},"comment":{}}],["features",{"_index":10,"name":{"12":{}},"comment":{}}],["find",{"_index":2,"name":{"2":{},"10":{}},"comment":{}}],["namesapi",{"_index":0,"name":{"0":{}},"comment":{}}],["nearest",{"_index":1,"name":{"1":{},"7":{}},"comment":{}}],["ngd",{"_index":9,"name":{"11":{}},"comment":{}}],["placesapi",{"_index":3,"name":{"3":{}},"comment":{}}],["polygon",{"_index":4,"name":{"4":{}},"comment":{}}],["postcode",{"_index":8,"name":{"9":{}},"comment":{}}],["queryables",{"_index":13,"name":{"15":{}},"comment":{}}],["radius",{"_index":5,"name":{"5":{}},"comment":{}}],["schema",{"_index":12,"name":{"14":{}},"comment":{}}],["uprn",{"_index":7,"name":{"8":{}},"comment":{}}]],"pipeline":[]}}', ); diff --git a/src/names.ts b/src/names.ts index c8d779a..6d76fb0 100644 --- a/src/names.ts +++ b/src/names.ts @@ -17,7 +17,7 @@ async function requestNames(config: Config): Promise { responseObject.results.forEach((result) => { coordsTemp = coords.fromBNG( result.GAZETTEER_ENTRY.GEOMETRY_X, - result.GAZETTEER_ENTRY.GEOMETRY_Y + result.GAZETTEER_ENTRY.GEOMETRY_Y, ); result.GAZETTEER_ENTRY.LNG = coordsTemp.lng; result.GAZETTEER_ENTRY.LAT = coordsTemp.lat; @@ -35,7 +35,7 @@ async function requestNames(config: Config): Promise { */ export const nearest = async ( apiKey: string, - point: [number, number] + point: [number, number], ): Promise => { validateParams({ apiKey, point }); @@ -64,7 +64,7 @@ export const nearest = async ( export const find = async ( apiKey: string, query: string, - { offset = 0, limit = 100 }: { offset?: number; limit?: number } = {} + { offset = 0, limit = 100 }: { offset?: number; limit?: number } = {}, ): Promise => { validateParams({ apiKey, query, offset, limit }); diff --git a/src/ngd.ts b/src/ngd.ts index 8b372a6..fda19c0 100644 --- a/src/ngd.ts +++ b/src/ngd.ts @@ -58,7 +58,7 @@ export const features = async ( crs?: null | string | number; bboxCRS?: null | string | number; filterCRS?: null | string | number; - } = {} + } = {}, ): Promise => { validateParams({ bbox, datetime }); const config = initialiseConfig(apiKey, offset, limit); @@ -81,7 +81,7 @@ export const features = async ( * @return {Promise} - Collection information */ export const collections = async ( - collectionId = "" + collectionId = "", ): Promise => { const endpoint = root + `${collectionId}`; return (await get(endpoint).then((response) => response.json())) as Promise< @@ -98,7 +98,7 @@ export const collections = async ( export const schema = async (collectionId: string): Promise => { const endpoint = root + `${collectionId}/schema`; return (await get(endpoint).then((response) => - response.json() + response.json(), )) as Promise; }; @@ -109,11 +109,11 @@ export const schema = async (collectionId: string): Promise => { * @return {Promise} - JSON containing querable properties */ export const queryables = async ( - collectionId: string + collectionId: string, ): Promise => { const endpoint = root + `${collectionId}/queryables`; return (await get(endpoint).then((response) => - response.json() + response.json(), )) as Promise; }; @@ -135,10 +135,10 @@ export const feature = async ( crs = null, }: { crs?: null | string | number; - } = {} + } = {}, ): Promise => { const endpoint = buildUrl(collectionId, { featureId, crs }); return (await get(endpoint, apiKey).then((response) => - response.json() + response.json(), )) as Promise; }; diff --git a/src/places.ts b/src/places.ts index e7cbbe9..11631ac 100644 --- a/src/places.ts +++ b/src/places.ts @@ -25,13 +25,13 @@ async function requestPlaces(config: Config): Promise { } function isFeature( - geojson: Feature | FeatureCollection | Polygon + geojson: Feature | FeatureCollection | Polygon, ): geojson is Feature { return "type" in geojson && geojson.type == "Feature"; } function isFeatureCollection( - geojson: Feature | FeatureCollection | Polygon + geojson: Feature | FeatureCollection | Polygon, ): geojson is FeatureCollection { return "type" in geojson && geojson.type == "FeatureCollection"; } @@ -41,7 +41,7 @@ function isPolygon(geom: Geometry): geom is Polygon { } function preprocessPlacesPolygon( - geoJson: Feature | FeatureCollection | Polygon + geoJson: Feature | FeatureCollection | Polygon, ) { try { if (isFeatureCollection(geoJson) && geoJson.features.length === 0) { @@ -50,7 +50,7 @@ function preprocessPlacesPolygon( throw new Error( `Input feature collection has too many features. Expected 1, got ${ (geoJson as FeatureCollection).features.length - }` + }`, ); } @@ -73,14 +73,14 @@ function preprocessPlacesPolygon( if (coords.isLngLat(geom.coordinates[0][0])) { geom.coordinates[0] = geom.coordinates[0].map( (coordinate) => - coords.swivelPoint(coordinate as [number, number]) + coords.swivelPoint(coordinate as [number, number]), ); } return geom; } catch { throw new Error( - "Failed to read GeoJSON input. Does the GeoJSON input adhere to specification?" + "Failed to read GeoJSON input. Does the GeoJSON input adhere to specification?", ); } } @@ -98,7 +98,7 @@ function preprocessPlacesPolygon( export const polygon = async ( apiKey: string, polygon: Feature | FeatureCollection | Polygon, - { offset = 0, limit = 100 }: { offset?: number; limit?: number } = {} + { offset = 0, limit = 100 }: { offset?: number; limit?: number } = {}, ): Promise => { validateParams({ apiKey, polygon, offset, limit }); @@ -131,7 +131,7 @@ export const radius = async ( apiKey: string, point: [number, number], radius: number, - { offset = 0, limit = 100 }: { offset?: number; limit?: number } = {} + { offset = 0, limit = 100 }: { offset?: number; limit?: number } = {}, ): Promise => { validateParams({ apiKey, point, radius, offset, limit }); @@ -163,7 +163,7 @@ export const radius = async ( export const bbox = async ( apiKey: string, bbox: [number, number, number, number], - { offset = 0, limit = 100 }: { offset?: number; limit?: number } = {} + { offset = 0, limit = 100 }: { offset?: number; limit?: number } = {}, ): Promise => { validateParams({ apiKey, bbox, offset, limit }); @@ -190,7 +190,7 @@ export const bbox = async ( */ export const nearest = async ( apiKey: string, - point: [number, number] + point: [number, number], ): Promise => { validateParams({ apiKey, point }); @@ -218,7 +218,7 @@ export const nearest = async ( */ export const uprn = async ( apiKey: string, - uprn: number + uprn: number, ): Promise => { validateParams({ apiKey, uprn }); @@ -246,7 +246,7 @@ export const uprn = async ( export const postcode = async ( apiKey: string, postcode: string, - { offset = 0, limit = 100 }: { offset?: number; limit?: number } = {} + { offset = 0, limit = 100 }: { offset?: number; limit?: number } = {}, ): Promise => { validateParams({ apiKey, postcode, offset, limit }); @@ -273,7 +273,7 @@ export const postcode = async ( export const find = async ( apiKey: string, query: string, - { offset = 0, limit = 100 }: { offset?: number; limit?: number } = {} + { offset = 0, limit = 100 }: { offset?: number; limit?: number } = {}, ): Promise => { validateParams({ apiKey, query, offset, limit }); diff --git a/src/utils/coords.ts b/src/utils/coords.ts index f9f7b39..bd119b6 100644 --- a/src/utils/coords.ts +++ b/src/utils/coords.ts @@ -19,7 +19,7 @@ const coords: { [key: string]: Function } = { fromBNG: (ea: number, no: number): { lat: number; lng: number } => { proj4.defs( "EPSG:27700", - "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs" + "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs", ); const point = proj4("EPSG:27700", "EPSG:4326", [ea, no]); @@ -33,7 +33,7 @@ const coords: { [key: string]: Function } = { toBNG: (lat: number, lng: number): { ea: number; no: number } => { proj4.defs( "EPSG:27700", - "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs" + "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs", ); const point = proj4("EPSG:4326", "EPSG:27700", [lng, lat]); diff --git a/src/utils/geojson.ts b/src/utils/geojson.ts index baeac7a..9c93bd1 100644 --- a/src/utils/geojson.ts +++ b/src/utils/geojson.ts @@ -23,7 +23,7 @@ function toGeoJSON(response: OSDataHubResponse): OSFeatureCollection { } function responseToFeatureCollection( - response: OSDataHubResponse + response: OSDataHubResponse, ): OSFeatureCollection { let features: Feature[]; if ("DPA" in response.results[0]) { @@ -53,7 +53,7 @@ function namesResponseToFeatures(response: NamesResponse): Feature[] { ], }, properties: feature.GAZETTEER_ENTRY, - } + }, ); } @@ -67,6 +67,6 @@ function placesResponseToFeatures(response: PlacesResponse): Feature[] { coordinates: [feature.DPA.LNG, feature.DPA.LAT], }, properties: feature.DPA, - } + }, ); } diff --git a/src/utils/ngd/request.ts b/src/utils/ngd/request.ts index 33be6c3..8941506 100644 --- a/src/utils/ngd/request.ts +++ b/src/utils/ngd/request.ts @@ -30,7 +30,7 @@ async function get(endpoint: string, key = ""): Promise { function getOffsetEndpointNGD(config: Config, featureCount: number): string { const limit = Math.min( config.paging.limitValue - config.paging.startValue - featureCount, - 100 + 100, ); return config.url + "&offset=" + config.paging.position + "&limit=" + limit; } diff --git a/src/utils/ngd/url.ts b/src/utils/ngd/url.ts index 2741c41..e55e98b 100644 --- a/src/utils/ngd/url.ts +++ b/src/utils/ngd/url.ts @@ -24,7 +24,7 @@ function buildUrl( crs?: null | number | string; bboxCRS?: null | number | string; filterCRS?: null | number | string; - } = {} + } = {}, ) { const queryParams: { bbox?: string; diff --git a/src/utils/ngd/validate.ts b/src/utils/ngd/validate.ts index 91ee90f..02e47f1 100644 --- a/src/utils/ngd/validate.ts +++ b/src/utils/ngd/validate.ts @@ -25,7 +25,7 @@ Expected either a local date, a date-time with UTC time zone (Z) or an open or c - A closed interval: '2021-12-12T00:00:00Z/2021-12-18T12:31:12Z' - Open intervals: '2021-12-12T00:00:00Z/..' or '../2021-12-18T12:31:12Z' - An interval until now: '2018-02-12T00:00:00Z/..' or '2018-02-12T00:00:00Z/' -` +`, ); } @@ -34,7 +34,7 @@ const validate: { [key: string]: Function } = { bbox: function (bbox: BBox) { if (bbox[0] > bbox[2] || bbox[1] > bbox[3]) { throw new Error( - "Invalid bounding box (bbox), expected [minLng, minLat, maxLng, maxLat] or [minLat, minLng, maxLat, maxLng]" + "Invalid bounding box (bbox), expected [minLng, minLat, maxLng, maxLat] or [minLat, minLng, maxLat, maxLng]", ); } return true; diff --git a/src/utils/request.ts b/src/utils/request.ts index 3f5d7ef..8de3e40 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -9,7 +9,7 @@ export { request, checkStatusCode, logEndConditions, continuePaging }; async function post( endpoint: string, key: string, - body: string + body: string, ): Promise { logging.info("🔍 " + endpoint); return await fetch(endpoint, { @@ -35,7 +35,7 @@ async function get(endpoint: string, key: string): Promise { function getOffsetEndpoint(config: Config, featureCount: number): string { const limit = Math.min( config.paging.limitValue - config.paging.startValue - featureCount, - 100 + 100, ); return ( config.url + "&offset=" + config.paging.position + "&maxresults=" + limit @@ -47,7 +47,7 @@ function checkStatusCode(statusCode: number): void { switch (statusCode) { case 400: throw new Error( - `HTTP 400 (Bad Request - Potential CQL/Bounding Geometry Error)` + `HTTP 400 (Bad Request - Potential CQL/Bounding Geometry Error)`, ); case 401: throw new Error(`HTTP 401 (Unauthorized - Check Your API Key)`); @@ -60,7 +60,7 @@ function checkStatusCode(statusCode: number): void { function logEndConditions(config: Config, featureCount: number): void { if (config.paging.position == config.paging.limitValue) { logging.warn( - `🔸 The hard limit (${config.paging.limitValue} features) was reached. Additional features may be available to collect.` + `🔸 The hard limit (${config.paging.limitValue} features) was reached. Additional features may be available to collect.`, ); } else { logging.info(`🔹 All features (${featureCount}) have been collected.`); diff --git a/src/utils/url.ts b/src/utils/url.ts index 1ddf689..c16bd9d 100644 --- a/src/utils/url.ts +++ b/src/utils/url.ts @@ -5,7 +5,7 @@ export { buildUrl }; function buildUrl( api: string, operation: string, - params: { [key: string]: string } + params: { [key: string]: string }, ) { const root = "https://api.os.uk/search/"; const query = new URLSearchParams(params); diff --git a/src/utils/validate.ts b/src/utils/validate.ts index dc38fc9..bbf983e 100644 --- a/src/utils/validate.ts +++ b/src/utils/validate.ts @@ -21,13 +21,13 @@ interface ValidationParams { } function isFeature( - geojson: Feature | FeatureCollection | Polygon + geojson: Feature | FeatureCollection | Polygon, ): geojson is Feature { return "type" in geojson && geojson.type == "Feature"; } function isFeatureCollection( - geojson: Feature | FeatureCollection | Polygon + geojson: Feature | FeatureCollection | Polygon, ): geojson is FeatureCollection { return "type" in geojson && geojson.type == "FeatureCollection"; } @@ -60,7 +60,7 @@ const validate: { [key: string]: Function } = { point[1] > 2.043457 ) { throw new Error( - "Invalid Point, not within the UK (Lng, Lat): [-7.910156, 49.781264, 2.043457, 59.164668]" + "Invalid Point, not within the UK (Lng, Lat): [-7.910156, 49.781264, 2.043457, 59.164668]", ); } } else { @@ -71,7 +71,7 @@ const validate: { [key: string]: Function } = { point[0] > 2.043457 ) { throw new Error( - "Invalid Point, not within the UK (Lng, Lat): [-7.910156, 49.781264, 2.043457, 59.164668]" + "Invalid Point, not within the UK (Lng, Lat): [-7.910156, 49.781264, 2.043457, 59.164668]", ); } } @@ -86,14 +86,14 @@ const validate: { [key: string]: Function } = { !isPolygon(polygon.features[0].geometry) ) { throw new Error( - `Expected Polygon, got ${polygon.features[0].geometry.type}` + `Expected Polygon, got ${polygon.features[0].geometry.type}`, ); } }, bbox: function (bbox: [number, number, number, number]) { if (bbox[0] > bbox[2] || bbox[1] > bbox[3]) { throw new Error( - "Invalid bounding box (bbox), expected [minLng, minLat, maxLng, maxLat] or [minLat, minLng, maxLat, maxLng]" + "Invalid bounding box (bbox), expected [minLng, minLat, maxLng, maxLat] or [minLat, minLng, maxLat, maxLng]", ); } @@ -106,7 +106,7 @@ const validate: { [key: string]: Function } = { bbox[3] > 2.043457 ) { throw new Error( - "Invalid bounding box (bbox), not within the UK (Lng, Lat): [-7.910156, 49.781264, 2.043457, 59.164668]" + "Invalid bounding box (bbox), not within the UK (Lng, Lat): [-7.910156, 49.781264, 2.043457, 59.164668]", ); } } else { @@ -117,7 +117,7 @@ const validate: { [key: string]: Function } = { bbox[2] > 2.043457 ) { throw new Error( - "Invalid bounding box (bbox), not within the UK (Lng, Lat): [-7.910156, 49.781264, 2.043457, 59.164668]" + "Invalid bounding box (bbox), not within the UK (Lng, Lat): [-7.910156, 49.781264, 2.043457, 59.164668]", ); } } @@ -128,14 +128,14 @@ const validate: { [key: string]: Function } = { const query = /^[A-Z]{1,2}[0-9][A-Z0-9]?( ?[0-9][A-Z]{2})?$/g; if (!query.test(postcode)) { throw new Error( - "Invalid Postcode: The minimum for the resource is the area and district e.g. SO16" + "Invalid Postcode: The minimum for the resource is the area and district e.g. SO16", ); } }, uprn: function (uprn: number) { if (!Number.isInteger(uprn) || uprn < 0 || uprn.toString().length > 12) { throw new Error( - "Invalid UPRN, should be a positive integer (max. 12 digits)" + "Invalid UPRN, should be a positive integer (max. 12 digits)", ); } }, diff --git a/tests/crs.test.ts b/tests/crs.test.ts index d692cb2..0f56267 100644 --- a/tests/crs.test.ts +++ b/tests/crs.test.ts @@ -5,7 +5,7 @@ import { testError } from "./utils"; describe("Get valid CRS", () => { test("getCRS with string passes", () => { expect(getCRS("epsg:27700")).toBe( - "http://www.opengis.net/def/crs/EPSG/0/27700" + "http://www.opengis.net/def/crs/EPSG/0/27700", ); }); @@ -15,7 +15,7 @@ describe("Get valid CRS", () => { test("getCRS with uppercase string passes", () => { expect(getCRS("WGS84")).toBe( - "http://www.opengis.net/def/crs/OGC/1.3/CRS84" + "http://www.opengis.net/def/crs/OGC/1.3/CRS84", ); }); diff --git a/tests/names.test.ts b/tests/names.test.ts index dd4dae4..e6a2a84 100644 --- a/tests/names.test.ts +++ b/tests/names.test.ts @@ -13,7 +13,7 @@ beforeAll(() => { } else { throw Error( "OS_API_KEY not provided. Make sure you provide a valid api" + - "key either throw your environment variables or a .env file" + "key either throw your environment variables or a .env file", ); } }); @@ -41,8 +41,8 @@ describe("Nearest Endpoint", () => { }); expect(error).toEqual( new Error( - "Invalid Point, not within the UK (Lng, Lat): [-7.910156, 49.781264, 2.043457, 59.164668]" - ) + "Invalid Point, not within the UK (Lng, Lat): [-7.910156, 49.781264, 2.043457, 59.164668]", + ), ); }); }); diff --git a/tests/ngd.test.ts b/tests/ngd.test.ts index 567b6e2..c83f568 100644 --- a/tests/ngd.test.ts +++ b/tests/ngd.test.ts @@ -22,7 +22,7 @@ beforeAll(() => { } else { throw Error( "OS_API_KEY not provided. Make sure you provide a valid api" + - "key either throw your environment variables or a .env file" + "key either throw your environment variables or a .env file", ); } }); @@ -102,8 +102,8 @@ describe("Features Endpoint Fails", () => { }); expect(error).toEqual( new Error( - "Invalid bounding box (bbox), expected [minLng, minLat, maxLng, maxLat] or [minLat, minLng, maxLat, maxLng]" - ) + "Invalid bounding box (bbox), expected [minLng, minLat, maxLng, maxLat] or [minLat, minLng, maxLat, maxLng]", + ), ); }); @@ -122,8 +122,8 @@ describe("Features Endpoint Fails", () => { }); expect(error).toEqual( new Error( - "The feature collection 'bld-fts-buildingpjart' could not be found. Please check it is a supported collection." - ) + "The feature collection 'bld-fts-buildingpjart' could not be found. Please check it is a supported collection.", + ), ); }); }); @@ -239,8 +239,8 @@ describe("Collections Endpoint", () => { }); expect(error).toEqual( new Error( - "The feature collection 'bld-fts-buildingpjart' could not be found. Please check it is a supported collection." - ) + "The feature collection 'bld-fts-buildingpjart' could not be found. Please check it is a supported collection.", + ), ); }); }); @@ -258,8 +258,8 @@ describe("Schema Endpoint", () => { }); expect(error).toEqual( new Error( - "The feature collection 'bld-fts-buildingpjart' could not be found. Please check it is a supported collection." - ) + "The feature collection 'bld-fts-buildingpjart' could not be found. Please check it is a supported collection.", + ), ); }); }); @@ -277,8 +277,8 @@ describe("Queryables Endpoint", () => { }); expect(error).toEqual( new Error( - "The feature collection 'bld-fts-buildingpjart' could not be found. Please check it is a supported collection." - ) + "The feature collection 'bld-fts-buildingpjart' could not be found. Please check it is a supported collection.", + ), ); }); }); @@ -300,7 +300,7 @@ describe("Feature Endpoint", () => { apiKey, collectionId, featureId, - options + options, ); checkNotWGS84(response.geometry.coordinates); }); @@ -314,7 +314,7 @@ describe("Feature Endpoint", () => { apiKey, collectionId, featureId, - options + options, ); checkNotWGS84(response.geometry.coordinates); }); @@ -347,8 +347,8 @@ describe("Feature Endpoint", () => { }); expect(error).toEqual( new Error( - "The feature collection 'bld-fts-buildingsline' could not be found. Please check it is a supported collection." - ) + "The feature collection 'bld-fts-buildingsline' could not be found. Please check it is a supported collection.", + ), ); }); }); diff --git a/tests/places.test.ts b/tests/places.test.ts index bc5042b..9b7a63a 100644 --- a/tests/places.test.ts +++ b/tests/places.test.ts @@ -72,7 +72,7 @@ beforeAll(() => { } else { throw Error( "OS_API_KEY not provided. Make sure you provide a valid api key either throw your environment variables" + - "or a .env file" + "or a .env file", ); } }); @@ -87,11 +87,11 @@ describe("Polygon Endpoint", () => { const response = await placesAPI.polygon( apiKey, featureCollection, - options + options, ); const requiredProperties = ["features", "header", "type"]; requiredProperties.map((prop: string) => - expect(response).toHaveProperty(prop) + expect(response).toHaveProperty(prop), ); expect(response.features.length).toBeGreaterThanOrEqual(1); }); @@ -104,7 +104,7 @@ describe("Polygon Endpoint", () => { const response = await placesAPI.polygon(apiKey, polygon, options); const requiredProperties = ["features", "header", "type"]; requiredProperties.map((prop: string) => - expect(response).toHaveProperty(prop) + expect(response).toHaveProperty(prop), ); expect(response.features.length).toBeGreaterThanOrEqual(1); }); @@ -116,10 +116,10 @@ describe("Polygon Endpoint", () => { const response = await placesAPI.polygon( apiKey, featureCollection, - options + options, ); requiredProperties.map((prop: string) => - expect(response).toHaveProperty(prop) + expect(response).toHaveProperty(prop), ); expect(response.features.length).toEqual(7); }); @@ -171,21 +171,21 @@ describe("Radius Endpoint", () => { return await placesAPI.radius(apiKey, center, -1, options); }); expect(error).toEqual( - new RangeError("Radius must be an integer between 1-1000m") + new RangeError("Radius must be an integer between 1-1000m"), ); error = await testError(async () => { return await placesAPI.radius(apiKey, center, 5000, options); }); expect(error).toEqual( - new RangeError("Radius must be an integer between 1-1000m") + new RangeError("Radius must be an integer between 1-1000m"), ); error = await testError(async () => { return await placesAPI.radius(apiKey, center, 0.001, options); }); expect(error).toEqual( - new Error("Radius must be an integer between 1-1000m") + new Error("Radius must be an integer between 1-1000m"), ); }); @@ -238,13 +238,13 @@ describe("BBox Endpoint", () => { return await placesAPI.bbox( apiKey, [-1.907287, 52.479173, -1.917543, 52.485211], - options + options, ); }); expect(error).toEqual( new Error( - "Invalid bounding box (bbox), expected [minLng, minLat, maxLng, maxLat] or [minLat, minLng, maxLat, maxLng]" - ) + "Invalid bounding box (bbox), expected [minLng, minLat, maxLng, maxLat] or [minLat, minLng, maxLat, maxLng]", + ), ); // North and South are switched @@ -252,13 +252,13 @@ describe("BBox Endpoint", () => { return await placesAPI.bbox( apiKey, [-1.917543, 52.485211, -1.907287, 52.479173], - options + options, ); }); expect(error).toEqual( new Error( - "Invalid bounding box (bbox), expected [minLng, minLat, maxLng, maxLat] or [minLat, minLng, maxLat, maxLng]" - ) + "Invalid bounding box (bbox), expected [minLng, minLat, maxLng, maxLat] or [minLat, minLng, maxLat, maxLng]", + ), ); // // Obviously not latitude and longitude @@ -267,8 +267,8 @@ describe("BBox Endpoint", () => { }); expect(error).toEqual( new Error( - "Invalid bounding box (bbox), not within the UK (Lng, Lat): [-7.910156, 49.781264, 2.043457, 59.164668]" - ) + "Invalid bounding box (bbox), not within the UK (Lng, Lat): [-7.910156, 49.781264, 2.043457, 59.164668]", + ), ); // // Invalid latitude values (need to be -90 <= x <= 90) @@ -277,8 +277,8 @@ describe("BBox Endpoint", () => { }); expect(error).toEqual( new Error( - "Invalid bounding box (bbox), not within the UK (Lng, Lat): [-7.910156, 49.781264, 2.043457, 59.164668]" - ) + "Invalid bounding box (bbox), not within the UK (Lng, Lat): [-7.910156, 49.781264, 2.043457, 59.164668]", + ), ); }); }); @@ -310,8 +310,8 @@ describe("Nearest Endpoint", () => { }); expect(error).toEqual( new Error( - "Invalid Point, not within the UK (Lng, Lat): [-7.910156, 49.781264, 2.043457, 59.164668]" - ) + "Invalid Point, not within the UK (Lng, Lat): [-7.910156, 49.781264, 2.043457, 59.164668]", + ), ); }); }); @@ -329,7 +329,7 @@ describe("UPRN Endpoint", () => { return await placesAPI.uprn(apiKey, -1000); }); expect(error).toEqual( - new Error("Invalid UPRN, should be a positive integer (max. 12 digits)") + new Error("Invalid UPRN, should be a positive integer (max. 12 digits)"), ); // can't be a decimal @@ -337,7 +337,7 @@ describe("UPRN Endpoint", () => { return await placesAPI.uprn(apiKey, 1.2345); }); expect(error).toEqual( - new Error("Invalid UPRN, should be a positive integer (max. 12 digits)") + new Error("Invalid UPRN, should be a positive integer (max. 12 digits)"), ); // can't be greater than 12 characters @@ -345,7 +345,7 @@ describe("UPRN Endpoint", () => { return await placesAPI.uprn(apiKey, 1234567890123); }); expect(error).toEqual( - new Error("Invalid UPRN, should be a positive integer (max. 12 digits)") + new Error("Invalid UPRN, should be a positive integer (max. 12 digits)"), ); }); }); @@ -373,8 +373,8 @@ describe("Postcode Endpoint", () => { }); expect(error).toEqual( new Error( - "Invalid Postcode: The minimum for the resource is the area and district e.g. SO16" - ) + "Invalid Postcode: The minimum for the resource is the area and district e.g. SO16", + ), ); // Requested postcode must contain a minimum of the sector plus 1 digit of the district e.g. SO1 @@ -383,8 +383,8 @@ describe("Postcode Endpoint", () => { }); expect(error).toEqual( new Error( - "Invalid Postcode: The minimum for the resource is the area and district e.g. SO16" - ) + "Invalid Postcode: The minimum for the resource is the area and district e.g. SO16", + ), ); });