Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

coords-formater

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

coords-formater

A coordinates parser and formater

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

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
npm install coords-formater --save

# Yarn
yarn add coords-formater
// Es6 module pattern
import coords from 'coords-formater'

// Node module pattern
const coords = require('coords-formater')

Destructuring

// Es6 module pattern
import { convert, parse } from 'coords-formater'

// Node module pattern
const { normalize } = require('coords-formater')

Properties

The properties below can be used to configurate some methods.

PropertyDescriptionDefault ValueType
degreesShow degrees. Always truetrueBoolean
minutesShow minutestrueBoolean
secondsShow seconds. False if minutes is also falsetrueBoolean
spacesShow spaces between partstrueBoolean
degreeIndicatorDegree part indicator°String
minuteIndicatorMinute part indicator'String
secondIndicatorSecond part indicator"String
showSignConfigure to show [+/-] sign at starttrueBoolean
showCompassDirectionConfigure to show compass direction at endtrueBoolean
decimalSeparatorLast part's decimal separator.String
decimalPlacesNumber of decimal places5Integer

Methods

normalize( String coordinate )

Normalizes input coordinate, removing unpattern characters

Parameters

NameTypeOptionalDescription
coordinateStringrequiredCoordinate in any Accepted Input Formats

Example

// Import
const { normalize } = require('coords-formater');

// Replaces "º" by "°"
normalize('41º 12.123"') 

// Returns
// 41° 12.123"

parse( String coordinate )

Extract coordinates components from passed string

Parameters

NameTypeOptionalDescription
coordinateStringrequiredCoordinate in any Accepted Input Formats

Example

const { parse } = require('coords-formater');

parse('S17 33 08.352');

/*Returns
{
    compass:"S",
    degrees:17,
    minutes:33,
    seconds:8.352,
    signal:"-"
}*/

convert( String coordinate [ , Object options ] )

Convert cordinate to other format according options

Parameters

NameTypeOptionalDescription
coordinateStringrequiredCoordinate in any Accepted Input Formats
optionsObjectoptionalProperties object

Example


const { convert } = require('coords-formater') ;

convert('41° 25\' 01" W', { 
  showSign: true, 
  showCompassDirection: false, 
  minutes: false 
  } 
);

// Returns
// - 41.41694444444445°


toString( Object parsedCoordinate [ , Object options ] )

Convert the object parsedCordinate to other format according options

Parameters

NameTypeOptionalDescription
parsedCordinateObjectrequiredObject of coordinates parts, like returned by parse()
optionsObjectoptionalProperties object

Example


const { toString } = require('coords-formater') ;

// object returned by parse()
const parts = {
  compass:"S",
  degrees:17,
  minutes:33,
  seconds:8.352,
  signal:"-"
}

// Configuration options
const options = {
  showSign:false, 
  showCompassDirection:true
}

toString(parts, options );

// Returns 
// 17° 33' 8.352" S

toFloat( String coordinate [ , Object options ] )

Convert cordinate to numeric format with float type

Parameters

NameTypeOptionalDescription
coordinateStringrequiredCoordinate in any Accepted Input Formats

Example


const { toFloat } = require('coords-formater') ;

toFloat('42 12 10')
// Returns
// 42.202777777777776

toFloat('S 42 12 10')
// Returns
// - 42.202777777777776

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

(c) klawdyo.com (klawdyo) 2020

FAQs

Package last updated on 10 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc