UNPKG

@hamlog/maidenhead

Version:

For various amateur radio needs, we at [Hamlog.Online](https://hamlog.online) required a library to process [Maidenhead grid locators](https://en.wikipedia.org/wiki/Maidenhead_Locator_System) in Javascript.

52 lines (51 loc) 2.01 kB
/** * Basic coordinate type, explicit so it's easier to interface it to other things that want coordinates. */ export interface LatLon { lat: number; lon: number; } /** A grid square is a tuple of points in two different corners of the square */ export type GridBox = [LatLon, LatLon]; /** A grid square string is just a string */ export type MaidenheadGrid = string; /** * Validate that a given string is a correct Maidenhead grid locator. * * This is more complicated than it sounds! * * A valid locator has no restrictions on letter case, despite the * popular usage. It has different restrictions for the first pair * of letters and for the subsequent pairs. It can actually be * extended indefinitely, even though with 12 * characters you get into sub-millimeter precision. And the shortest * possible grid locator is actually 2 characters, and yes, this also * makes sense. * * @param grid Maidenhead locator * @returns true if the locator is valid */ export declare function validateGrid(grid: MaidenheadGrid): boolean; /** * Compute the position and size of the given Maidenhead grid square on a map. * * @param grid Grid to convert * @returns A {GridBox} with two corners describing the grid square. */ export declare function gridToBox(grid: MaidenheadGrid): GridBox; /** * Convert grid to a point. Unlike some people, we return the * center of the square instead of a corner. * * @param grid Grid to convert * @returns A {lat: ..., lon:... } of the point in the center of the grid square. */ export declare function gridToPoint(grid: MaidenheadGrid): LatLon; /** * * @param point Coordinates to convert * @param precision Number of characters in output, defaults to 6. * @param humanize Humanize the representation the way it is normally done, i.e. by lowercasing the odd pairs of letters. * @returns Maidenhead grid to the precision requested. */ export declare function pointToGrid(point: LatLon, precision?: number, humanize?: boolean): MaidenheadGrid;