Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TS typings + build improvements #54

Merged
merged 9 commits into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

DanielJDufour marked this conversation as resolved.
Show resolved Hide resolved
[*]
indent_style = space
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.js*]
indent_size = 2

[*.{md,ts}]
indent_size = 4
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/.vscode/
/geotrans3.7/
DanielJDufour marked this conversation as resolved.
Show resolved Hide resolved
*~
node_modules
.DS_STORE
coverage
.nyc_output
*.csv
*.tgz
geotrans3.7/
32 changes: 32 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
declare module "mgrs" {
/**
* Convert lat/lon to MGRS.
*
* @param {[number, number]} ll Array with longitude and latitude on a
* WGS84 ellipsoid.
* @param {number} [accuracy=5] Accuracy in digits (5 for 1 m, 4 for 10 m, 3 for
* 100 m, 2 for 1 km, 1 for 10 km or 0 for 100 km). Optional, default is 5.
* @return {string} the MGRS string for the given location and accuracy.
*/
export function forward(ll: [number,number], accuracy?: number): string;

/**
* Convert MGRS to lat/lon bounding box.
*
* @param {string} mgrs MGRS string.
* @return {[number,number,number,number]} An array with left (longitude),
* bottom (latitude), right
* (longitude) and top (latitude) values in WGS84, representing the
* bounding box for the provided MGRS reference.
*/
export function inverse(mgrs: string): [number,number,number,number];

/**
* Convert MGRS to lat/lon point.
*
* @param {string} mgrs MGRS string.
* @return {[number,number]} An array with longitude and latitude values in
* WGS84, representing the center point of the provided MGRS reference.
*/
export function toPoint(mgrs: string): [number,number];
}
27 changes: 14 additions & 13 deletions mgrs.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ const V = 86; // V
const Z = 90; // Z

/**
* Conversion of lat/lon to MGRS.
* Convert lat/lon to MGRS.
*
* @param {object} ll Object literal with lat and lon properties on a
* @param {[number, number]} ll Array with longitude and latitude on a
* WGS84 ellipsoid.
* @param {int} accuracy Accuracy in digits (5 for 1 m, 4 for 10 m, 3 for
* @param {number} [accuracy=5] Accuracy in digits (5 for 1 m, 4 for 10 m, 3 for
* 100 m, 2 for 1 km, 1 for 10 km or 0 for 100 km). Optional, default is 5.
* @return {string} the MGRS string for the given location and accuracy.
*/
Expand Down Expand Up @@ -64,12 +64,13 @@ export function forward(ll, accuracy) {
}

/**
* Conversion of MGRS to lat/lon.
* Convert MGRS to lat/lon bounding box.
*
* @param {string} mgrs MGRS string.
* @return {array} An array with left (longitude), bottom (latitude), right
* (longitude) and top (latitude) values in WGS84, representing the
* bounding box for the provided MGRS reference.
* @return {[number,number,number,number]} An array with left (longitude),
* bottom (latitude), right
* (longitude) and top (latitude) values in WGS84, representing the
* bounding box for the provided MGRS reference.
*/
export function inverse(mgrs) {
const bbox = UTMtoLL(decode(mgrs.toUpperCase()));
Expand Down Expand Up @@ -286,10 +287,10 @@ function UTMtoLL(utm) {
/**
* Calculates the MGRS letter designator for the given latitude.
*
* @private
* @param {number} lat The latitude in WGS84 to get the letter designator
* @private (Not intended for public API, only exported for testing.)
* @param {number} latitude The latitude in WGS84 to get the letter designator
* for.
* @return {char} The letter designator.
* @return {string} The letter designator.
*/
export function getLetterDesignator(latitude) {
if (latitude <= 84 && latitude >= 72) {
Expand Down Expand Up @@ -539,7 +540,7 @@ northing meters ${mgrsString}`);
* should be added to the other, secondary easting value.
*
* @private
* @param {char} e The first letter from a two-letter MGRS 100´k zone.
* @param {string} e The first letter from a two-letter MGRS 100´k zone.
* @param {number} set The MGRS table set for the zone number.
* @return {number} The easting value for the given letter and set.
*/
Expand Down Expand Up @@ -582,7 +583,7 @@ function getEastingFromChar(e, set) {
* to be added for the zone letter of the MGRS coordinate.
*
* @private
* @param {char} n Second letter of the MGRS 100k zone
* @param {string} n Second letter of the MGRS 100k zone
* @param {number} set The MGRS table set number, which is dependent on the
* UTM zone number.
* @return {number} The northing value for the given letter and set.
Expand Down Expand Up @@ -629,7 +630,7 @@ function getNorthingFromChar(n, set) {
* Ported from Geotrans' c Lattitude_Band_Value structure table.
*
* @private
* @param {char} zoneLetter The MGRS zone to get the min northing for.
* @param {string} zoneLetter The MGRS zone to get the min northing for.
* @return {number}
*/
function getMinNorthing(zoneLetter) {
Expand Down
Loading