From 9f7048f07889d69f8f685ce1cc92d1cbc865d1e0 Mon Sep 17 00:00:00 2001 From: James Beard Date: Tue, 9 Jul 2024 00:41:25 +1000 Subject: [PATCH 1/2] Renamed turf-square/index.js to .ts in preparation for converting to Typescript. --- packages/turf-square/{index.js => index.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packages/turf-square/{index.js => index.ts} (100%) diff --git a/packages/turf-square/index.js b/packages/turf-square/index.ts similarity index 100% rename from packages/turf-square/index.js rename to packages/turf-square/index.ts From 8a87a5cd1218447a502165521b43da8d2579e4de Mon Sep 17 00:00:00 2001 From: James Beard Date: Tue, 9 Jul 2024 01:02:52 +1000 Subject: [PATCH 2/2] Converted turf-square to Typescript. --- packages/turf-square/README.md | 6 +++--- packages/turf-square/bench.ts | 9 +++++---- packages/turf-square/index.d.ts | 9 --------- packages/turf-square/index.ts | 9 +++++---- packages/turf-square/package.json | 9 +++++++-- packages/turf-square/test.ts | 9 +++++---- pnpm-lock.yaml | 15 +++++++++++++++ 7 files changed, 40 insertions(+), 26 deletions(-) delete mode 100644 packages/turf-square/index.d.ts diff --git a/packages/turf-square/README.md b/packages/turf-square/README.md index 2dc95eabd0..1f0e456a52 100644 --- a/packages/turf-square/README.md +++ b/packages/turf-square/README.md @@ -14,11 +14,11 @@ would contain the input. ### Examples ```javascript -var bbox = [-20, -20, -15, 0]; -var squared = turf.square(bbox); +const bbox = [-20, -20, -15, 0]; +const squared = turf.square(bbox); //addToMap -var addToMap = [turf.bboxPolygon(bbox), turf.bboxPolygon(squared)] +const addToMap = [turf.bboxPolygon(bbox), turf.bboxPolygon(squared)] ``` Returns **[BBox][1]** a square surrounding `bbox` diff --git a/packages/turf-square/bench.ts b/packages/turf-square/bench.ts index 21bca3ef4f..832373d5c5 100644 --- a/packages/turf-square/bench.ts +++ b/packages/turf-square/bench.ts @@ -1,14 +1,15 @@ -import Benchmark from "benchmark"; +import { BBox } from "geojson"; +import Benchmark, { Event } from "benchmark"; import { square } from "./index.js"; -var bbox = [0, 0, 5, 10]; +const bbox: BBox = [0, 0, 5, 10]; -var suite = new Benchmark.Suite("turf-square"); +const suite = new Benchmark.Suite("turf-square"); suite .add("turf-square", function () { square(bbox); }) - .on("cycle", function (event) { + .on("cycle", function (event: Event) { console.log(String(event.target)); }) .run(); diff --git a/packages/turf-square/index.d.ts b/packages/turf-square/index.d.ts deleted file mode 100644 index d5b3319263..0000000000 --- a/packages/turf-square/index.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { BBox } from "geojson"; - -/** - * http://turfjs.org/docs/#square - */ -declare function square(bbox: BBox): BBox; - -export { square }; -export default square; diff --git a/packages/turf-square/index.ts b/packages/turf-square/index.ts index e102b0c9ee..1c477b5288 100644 --- a/packages/turf-square/index.ts +++ b/packages/turf-square/index.ts @@ -1,4 +1,5 @@ import { distance } from "@turf/distance"; +import { BBox } from "geojson"; /** * Takes a bounding box and calculates the minimum square bounding box that @@ -8,13 +9,13 @@ import { distance } from "@turf/distance"; * @param {BBox} bbox extent in [west, south, east, north] order * @returns {BBox} a square surrounding `bbox` * @example - * var bbox = [-20, -20, -15, 0]; - * var squared = turf.square(bbox); + * const bbox = [-20, -20, -15, 0]; + * const squared = turf.square(bbox); * * //addToMap - * var addToMap = [turf.bboxPolygon(bbox), turf.bboxPolygon(squared)] + * const addToMap = [turf.bboxPolygon(bbox), turf.bboxPolygon(squared)] */ -function square(bbox) { +function square(bbox: BBox): BBox { var west = bbox[0]; var south = bbox[1]; var east = bbox[2]; diff --git a/packages/turf-square/package.json b/packages/turf-square/package.json index f84071a742..9b10ab7d64 100644 --- a/packages/turf-square/package.json +++ b/packages/turf-square/package.json @@ -51,14 +51,19 @@ "test:tape": "tsx test.ts" }, "devDependencies": { + "@types/benchmark": "^2.1.5", + "@types/tape": "^4.2.32", "benchmark": "^2.1.4", "npm-run-all": "^4.1.5", "tape": "^5.7.2", "tsup": "^8.0.1", - "tsx": "^4.6.2" + "tsx": "^4.6.2", + "typescript": "^5.2.2" }, "dependencies": { "@turf/distance": "workspace:^", - "@turf/helpers": "workspace:^" + "@turf/helpers": "workspace:^", + "@types/geojson": "7946.0.8", + "tslib": "^2.6.2" } } diff --git a/packages/turf-square/test.ts b/packages/turf-square/test.ts index d1fcdd9330..a83e6f927b 100644 --- a/packages/turf-square/test.ts +++ b/packages/turf-square/test.ts @@ -1,12 +1,13 @@ +import { BBox } from "geojson"; import test from "tape"; import { square } from "./index.js"; test("square", function (t) { - var bbox1 = [0, 0, 5, 10]; - var bbox2 = [0, 0, 10, 5]; + const bbox1: BBox = [0, 0, 5, 10]; + const bbox2: BBox = [0, 0, 10, 5]; - var sq1 = square(bbox1); - var sq2 = square(bbox2); + const sq1 = square(bbox1); + const sq2 = square(bbox2); t.deepEqual(sq1, [-2.5, 0, 7.5, 10]); t.deepEqual(sq2, [0, -2.5, 10, 7.5]); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3849df9af2..14c1c8241a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5469,7 +5469,19 @@ importers: '@turf/helpers': specifier: workspace:^ version: link:../turf-helpers + '@types/geojson': + specifier: 7946.0.8 + version: 7946.0.8 + tslib: + specifier: ^2.6.2 + version: 2.6.2 devDependencies: + '@types/benchmark': + specifier: ^2.1.5 + version: 2.1.5 + '@types/tape': + specifier: ^4.2.32 + version: 4.13.4 benchmark: specifier: ^2.1.4 version: 2.1.4 @@ -5485,6 +5497,9 @@ importers: tsx: specifier: ^4.6.2 version: 4.6.2 + typescript: + specifier: ^5.2.2 + version: 5.3.3 packages/turf-square-grid: dependencies: