Skip to content

Commit

Permalink
added typescript support
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielJDufour committed Jun 19, 2022
1 parent 79befce commit b3b8c7b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@
"main": "dist/geo-extent.cjs",
"module": "dist/geo-extent.mjs",
"type": "module",
"types": "./types.d.ts",
"files": [
"src/geo-extent.js",
"dist/geo-extent.cjs",
"dist/geo-extent.mjs"
],
"scripts": {
"build": "cp ./src/geo-extent.js ./dist/geo-extent.mjs && npx babel ./src/geo-extent.js --out-file ./dist/geo-extent.cjs --plugins=@babel/plugin-transform-modules-commonjs",
"f": "npm run format",
"format": "npx prettier --arrow-parens=avoid --print-width=120 --trailing-comma=none --write src/*.js test/*.js test/*.mjs",
"prepublishOnly": "npm run format",
"test": "for f in ./test/*; do node $f; done"
"test": "for f in ./test/*; do echo \"node $f\" && node $f && echo \"npx ts-node $f\" && npx ts-node $f; done"
},
"repository": {
"type": "git",
Expand Down
42 changes: 42 additions & 0 deletions types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
export type GeoExtent = {
// properties
bbox: [number, number, number, number];
bbox_str: [string, string, string, string];
srs: string;
xmin: number;
xmin_str: string;
xmax: number;
xmax_str: string;
ymin: number;
ymin_str: string;
ymax: number;
ymax_str: string;
height: number;
height_str: string;
width: number;
width_str: string;
area: number;
area_str: string;
perimeter: number;
perimeter_str: string;
center: { x: number, y: number };
center_str: { x: string, y: string };
bottomLeft: { x: number, y: number };
bottomRight: { x: number, y: number };
topLeft: { x: number, y: number };
topRight: { x: number, y: number };
str: string;
leafletBounds: [[number, number], [number, number]];

// functions
asEsriJSON: () => { xmin: number, ymin: number, xmax: number, ymax: number, spatialReference: { wkid: string }};
asGeoJSON: () => { type: "Feature", geometry: { type: "Polygon", coordinates: [number[]]}};
clone: () => GeoExtent;
combine: (other: GeoExtent) => GeoExtent;
contains: (other: GeoExtent) => GeoExtent;
crop: (other: GeoExtent) => GeoExtent;
equals: (other: GeoExtent, options?: { digits?: number }) => boolean;
overlaps: (other: GeoExtent) => boolean;
reproj: ((srs: number, options?: { quiet: false }) => GeoExtent) | ((srs: number, options: { quiet: true }) => (GeoExtent | undefined));
unwrap: () => GeoExtent[];
}

0 comments on commit b3b8c7b

Please sign in to comment.