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
npm install cardinal-direction
const Compass = require("cardinal-direction");
Converts a compass degree value into its correlated cardinal value.
|degree||number||yes||A number between
|subset||CardinalSubset||no||Restricts the return value to a subset of the possible cardinal directions. The default is
/* * Basic usage. * - returns "SW" */ Compass.cardinalFromDegree(221); /* * Restricting results with subset. * - returns "W" */ Compass.cardinalFromDegree(221, Compass.CardinalSubset.Basic);
Converts a cardinal direction into its correlated degree value.
|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); Compass.degreeFromCardinal(8);
Converts a cardinal value to either its abbreviation or full title.
|cardinal||string/number||yes||One of the
Compass.cardinalConverter(3): // NEbN Compass.cardinalConverter("NEbN"): // Northeast by North Compass.cardinalConverter("Northeast by North"); // NEbN
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.
|Full||Enables all possible cardinal directions to be retuned. Default|
|Basic||Restricts the possible returned cardinals to N,E,S,W.|
32 cardinal directions on a compass. But this numeric enum is
Compass.CardinalDirection; // "N" Compass.CardinalDirection["N"]; // 0 Compass.CardinalDirection.N; // 0
|1||NbE||North by East|
|3||NEbN||Northeast by North|
|5||NEbE||Northeast by East|
|7||EbN||East by North|
|9||EbS||East by South|
|11||SEbE||Southeast by East|
|13||SEbS||Southeast by South|
|15||SbE||South by East|
|17||SbW||South by West|
|19||SWbS||Southwest by South|
|21||SWbW||Southwest by West|
|23||WbS||West by South|
|25||Wbs||West by North|
|27||NWbW||Northwest by West|
|29||NWbN||Northwest by North|
|31||NbW||North by West|