Need private packages and team management tools?Check out npm Teams »


1.0.0 • Public • Published

npm install size

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 – Noth-northeast
  • NEbN – Northeast by North
  • NE – Northeast
  • NEbE – Northeast by East
  • ENE – East-northeast
  • EbN – East by North


npm install cardinal-direction


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


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"
 * Restricting results with subset.
 * - returns "W"
Compass.cardinalFromDegree(221, Compass.CardinalSubset.Basic);


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.

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
Name Value Legend
N 0 North
NbE 1 North by East
NNE 2 Noth-northeast
NEbN 3 Northeast by North
NE 4 Northeast
NEbE 5 Northeast by East
ENE 6 East-northeast
EbN 7 East by North
E 8 East
EbS 9 East by South
ESE 10 East-southeast
SEbE 11 Southeast by East
SE 12 Southeast
SEbS 13 Southeast By South
SSE 14 South-southeast
SbE 15 South be East
S 16 South
SbW 17 South by West
SSW 18 South-southwest
SWbS 19 Southwest by South
SW 20 Southwest
SWbW 21 Southwest by West
WSW 22 West-southwest
WbS 23 West by South
W 24 West
Wbs 25 West by North
WNW 26 West-northwest
NWbW 27 Northwest by West
NW 28 Northwest
NWbN 29 Northwest by North
NNW 30 North-northwest
NbW 31 North by West


npm i cardinal-direction

DownloadsWeekly Downloads






Unpacked Size

15 kB

Total Files


Last publish


  • avatar