latlon-formatter
A set of functions to format latitude and longitude angles.
Installation
npm install latlon-formatter --save
Usage
-
ES6:
;const latitude = ; // => 60° 00′ 00″ Nconst longitude =; // => 034° 24′ 00″ W -
require with Node.js:
var formatter = ;var latitude = formatter; // => 60° 00′ 00″ Nvar longitude = formatter; // => 034° 24′ 00″ W -
in browser include
dist/latlon-formatter.js
ordist/latlon-formatter.min.js
script:var formatter = windowlatlonFormatter;var latitude = formatter; // => 60° 00′ 00″ Nvar longitude = formatter; // => 034° 24′ 00″ W
Methods
-
latitude
orformatLatitude
— format latitude angle.Arguments:
value
— angle's value;options
:template
— custom template (optional, default —{degree}° {prime}′ {doublePrime}″ {direction}
);degrees
— specifies whethervalue
is in degrees or in radians (optional, default —false
);fixedCount
— count of precision digits (optional, default —null
leaving precision as is).
Examples:
formatter; // => 34° 24′ 00″ Nformatter; // => 14° 45′ 00″ Sformatter; // => —14.8° -
longitude
orformatLongitude
— format longitude angle.Arguments:
value
— angle's value;options
:template
— custom template (optional, default —{degree}° {prime}′ {doublePrime}″ {direction}
);degrees
— specifies whethervalue
is in degrees or in radians (optional, default —false
);fixedCount
— count of precision digits (optional, default —null
leaving precision as is).
Examples:
formatter; // => 034° 24′ 00″ Eformatter; // => 014° 45′ 00″ Wformatter; // => —14.8° -
angle
orformatAngle
— format any custom angle.Arguments:
value
— angle's value;options
:template
— custom template (optional, default —{negativeSign}{value}°
);degrees
— specifies whethervalue
is in degrees or in radians (optional, default —false
);fixedCount
— count of precision digits (optional, default —null
leaving precision as is);customTokens
— an object or a function returning an object of additional custom tokens used intemplate
.
Examples:
formatter; // => 03° 24′ 00″ N
Template tokens
All three format methods (latitude
, longitude
and angle
) have the following predefined template tokens:
value
— angle's absolute value with optional precision specified byfixedCount
option;degree
— absolute (two-digits and three-digits forlatitude
andlongitude
respectively) degree value;prime
— absolute two-digits prime value;doublePrime
— absolute two-digits double prime value;sign
— value's sign:+
— positive value;—
— negative value;- empty — zero value;
negativeSign
— the same assign
except that it's empty for both zero and positive values.
latitude
and longitude
methods additionally have direction
token:
N
— non-negative latitude;S
— negative latitude;E
— non-negative longitude;W
— negative longitude.
Any custom additional tokens can be specified by customTokens
option of angle
method.
Building
In order to build library run:
npm run build
Testing
Run unit tests:
npm test
Run tests with coverage:
npm run test:coverage
In order to run tests with Coveralls locally you have to provide COVERALLS_REPO_TOKEN
:
COVERALLS_REPO_TOKEN=<token> npm run test:coveralls
Contributing
Before making a pull request, please, be sure that you start from develop
branch.