@phun-ky/cardinal v2.0.8
@phun-ky/cardinal

About
A set of JavaScript functions that gives you the cardinal direction based on degrees.
Table of Contents
Installation
npm i --save @phun-ky/cardinalUsage
With the default function:
import { cardinalDirection } from '@phun-ky/cardinal';
const direction = cardinalDirection(45);
console.log(direction); // south-eastOr with the crude function:
import { cardinalDirectionCrude } from '@phun-ky/cardinal';
const direction = cardinalDirectionCrude(45);
console.log(direction); // southOr with the detailed function:
import { cardinalDirectionDetailed } from '@phun-ky/cardinal';
const direction = cardinalDirectionDetailed(56.25);
console.log(direction); // south-south-eastAPI
cardinalDirection()
function cardinalDirection(degrees): CardinalDirectionType;Defined in: main.ts:93
Returns the 8-point cardinal direction based on degrees. Note: 0 degrees is EAST, increasing clockwise.
Parameters
| Parameter | Type | Description |
|---|---|---|
degrees | number | The angle in degrees. |
Returns
- The 8-point cardinal direction.
Throws
Parameter cannot exceed 360.
Throws
Parameter cannot be lower than 0.
Example
const direction = cardinalDirection(135); // "south"cardinalDirectionCrude()
function cardinalDirectionCrude(degrees): CardinalDirectionCrudeType;Defined in: main.ts:127
Returns the crude 4-point cardinal direction based on degrees. Note: 0 degrees is EAST, increasing clockwise.
Parameters
| Parameter | Type | Description |
|---|---|---|
degrees | number | The angle in degrees. |
Returns
- The 4-point cardinal direction.
Throws
Parameter cannot exceed 360.
Throws
Parameter cannot be lower than 0.
Example
const direction = cardinalDirectionCrude(200); // "west"cardinalDirectionDetailed()
function cardinalDirectionDetailed(degrees): CardinalDirectionDetailedType;Defined in: main.ts:49
Returns the detailed 16-point cardinal direction based on degrees. Note: 0 degrees is EAST, increasing clockwise.
Parameters
| Parameter | Type | Description |
|---|---|---|
degrees | number | The angle in degrees. |
Returns
- The 16-point cardinal direction.
Throws
Parameter cannot exceed 360.
Throws
Parameter cannot be lower than 0.
Example
const direction = cardinalDirectionDetailed(101.25); // "south-south-east"Contributing
Want to contribute? Please read the CONTRIBUTING.md and CODE_OF_CONDUCT.md
License
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog
See the CHANGELOG.md for details on the latest updates.
Sponsor me
I'm an Open Source evangelist, creating stuff that does not exist yet to help get rid of secondary activities and to enhance systems already in place, be it documentation or web sites.
The sponsorship is an unique opportunity to alleviate more hours for me to maintain my projects, create new ones and contribute to the large community we're all part of :)
Support me on GitHub Sponsors.
p.s. Ukraine is still under brutal Russian invasion. A lot of Ukrainian people are hurt, without shelter and need help. You can help in various ways, for instance, directly helping refugees, spreading awareness, putting pressure on your local government or companies. You can also support Ukraine by donating e.g. to Red Cross, Ukraine humanitarian organisation or donate Ambulances for Ukraine.
Attributions
Compass by Justicon from Noun Project (CC BY 3.0)