Introduction
This library is intended to facilitate the use of coordinates, making conversions between formats and preparing the fields to receive this type of data effortlessly.
Instalation
npm install coords-formater --save
yarn add coords-formater
import coords from 'coords-formater'
const coords = require('coords-formater')
Destructuring
import { convert, parse } from 'coords-formater'
const { normalize } = require('coords-formater')
Properties
The properties
below can be used to configurate some methods.
Property | Description | Default Value | Type |
---|
degrees | Show degrees. Always true | true | Boolean |
minutes | Show minutes | true | Boolean |
seconds | Show seconds. False if minutes is also false | true | Boolean |
spaces | Show spaces between parts | true | Boolean |
degreeIndicator | Degree part indicator | ° | String |
minuteIndicator | Minute part indicator | ' | String |
secondIndicator | Second part indicator | " | String |
showSign | Configure to show [+/-] sign at start | true | Boolean |
showCompassDirection | Configure to show compass direction at end | true | Boolean |
decimalSeparator | Last part's decimal separator | . | String |
decimalPlaces | Number of decimal places | 5 | Integer |
Methods
normalize( String
coordinate )
Normalizes input coordinate, removing unpattern characters
Parameters
Example
const { normalize } = require('coords-formater');
normalize('41º 12.123"')
parse( String
coordinate )
Extract coordinates components from passed string
Parameters
Example
const { parse } = require('coords-formater');
parse('S17 33 08.352');
convert( String
coordinate [ , Object
options ] )
Convert cordinate
to other format according options
Parameters
Example
const { convert } = require('coords-formater') ;
convert('41° 25\' 01" W', {
showSign: true,
showCompassDirection: false,
minutes: false
}
);
toString( Object
parsedCoordinate [ , Object
options ] )
Convert the object parsedCordinate
to other format according options
Parameters
Name | Type | Optional | Description |
---|
parsedCordinate | Object | required | Object of coordinates parts, like returned by parse() |
options | Object | optional | Properties object |
Example
const { toString } = require('coords-formater') ;
const parts = {
compass:"S",
degrees:17,
minutes:33,
seconds:8.352,
signal:"-"
}
const options = {
showSign:false,
showCompassDirection:true
}
toString(parts, options );
toFloat( String
coordinate [ , Object
options ] )
Convert cordinate
to numeric format with float type
Parameters
Example
const { toFloat } = require('coords-formater') ;
toFloat('42 12 10')
toFloat('S 42 12 10')
Accepted Input Formats
- 41 25 01N
- 41°25'01"N
- S17 33 08.352
- +17 33 08.352
- -41°25'01"
- 41 25N
- 41°25'N
- N41 25.117
- -41 25.117
- -41°25'
- 41 N
- 41°N
- N41.092
- 90S
- -41°
- +N41.092
License
MIT
Copyright
(c) klawdyo.com (klawdyo) 2020