Giter VIP home page Giter VIP logo

cardinal-direction's Introduction

npm size
support

Cardinal Direction

Each of the 4 main compass quadrants (N,E,S,W), contain 7 sub-regions. This tool can be used to convert a degree ranging from 0-360 to a correlated cardinal direction.


Example of North Quadrant Cardinal Directions

See CardinalDirection for the full list.

  • N – North
  • NbE – North by East
  • NNE – North Northeast
  • NEbN – Northeast by North
  • NE – Northeast
  • NEbE – Northeast by East
  • ENE – East Northeast
  • EbN – East by North

Install

npm install cardinal-direction

Usage

const Compass = require("cardinal-direction");

cardinalFromDegree

Converts a compass degree value into its correlated cardinal value.

Param Type Required Description
degree number yes A number between 0 and 360.
subset CardinalSubset no Restricts the return value to a subset of the possible cardinal directions. The default is Full. See CardinalSubset for more.
/*
 * Basic usage.
 * - returns "SW"
 */
Compass.cardinalFromDegree(221);

/*
 * Restricting results with subset.
 * - returns "W"
 */
Compass.cardinalFromDegree(221, Compass.CardinalSubset.Basic);

degreeFromCardinal

Converts a cardinal direction into its correlated degree value.

Param Type Required Description
cardinal CardinalDirection yes One of the possible cardinal directions. See CardinalDirection for more.
/*
 * These all return 90.
 */
Compass.degreeFromCardinal("E");
Compass.degreeFromCardinal(Compass.CardinalDirection["E"]);
Compass.degreeFromCardinal(Compass.CardinalDirection.E);
Compass.degreeFromCardinal(Compass.CardinalDirection[8]);
Compass.degreeFromCardinal(8);

cardinalConverter

Converts a cardinal value to either its abbreviation or full title.

Param Type Required Description
cardinal string/number yes One of the CardinalDirection enum member values, or its full title. See Cardinal Table for context.
Compass.cardinalConverter(3): // NEbN
Compass.cardinalConverter("NEbN"): // Northeast by North
Compass.cardinalConverter("Northeast by North"); // NEbN

CardinalSubset enum

This subset enum can be used to fine tune the return value of cardinalFromDegree. When used the specified degree will be pushed to the nearest accepted cardinal direction, based on your restriction.

Value Description
Full Enables all possible cardinal directions to be retuned. Default
Basic Restricts the possible returned cardinals to N,E,S,W.
Ordinal Extends Basic to include NE,SE,SW,NW,.
Intercardinal Extends Ordinal to include NNE,ENE,ESE,SSE,SSW,WSW,WNW,NNW.

CardinalDirection enum

There are 32 cardinal directions on a compass. But this numeric enum is 0 indexed.

Compass.CardinalDirection[0]; // "N"
Compass.CardinalDirection["N"]; // 0
Compass.CardinalDirection.N; // 0

Cardinal Table

Integer Abbreviation Title
0 N North
1 NbE North by East
2 NNE North Northeast
3 NEbN Northeast by North
4 NE Northeast
5 NEbE Northeast by East
6 ENE East Northeast
7 EbN East by North
8 E East
9 EbS East by South
10 ESE East Southeast
11 SEbE Southeast by East
12 SE Southeast
13 SEbS Southeast by South
14 SSE South Southeast
15 SbE South by East
16 S South
17 SbW South by West
18 SSW South Southwest
19 SWbS Southwest by South
20 SW Southwest
21 SWbW Southwest by West
22 WSW West Southwest
23 WbS West by South
24 W West
25 Wbs West by North
26 WNW West Northwest
27 NWbW Northwest by West
28 NW Northwest
29 NWbN Northwest by North
30 NNW North Northwest
31 NbW North by West

cardinal-direction's People

Contributors

mudlabs avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

cardinal-direction's Issues

Cardinal to Words

Would be nice if you could also convert to words, like N to North.

Failed to parse source map

Hey,
Love your lib.
I'm getting a warning and I don't know of its my computer although it still seems to work.

WARNING in ./node_modules/cardinal-direction/dist/index.js
Module Warning (from ./node_modules/source-map-loader/dist/cjs.js):
Failed to parse source map from '/Users/Name/Documents/React_projects/open-weather-web-app/node_modules/cardinal-direction/index.ts' file: Error: ENOENT: no such file or directory, open '/Users/Name/Documents/React_projects/open-weather-web-app/node_modules/cardinal-direction/index.ts'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.