npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

cardinal-direction

v1.1.1

Published

Convert compass degrees to and from cardinal direction values.

Readme

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 |