2.0.8 • Published 5 months ago

@phun-ky/cardinal v2.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

@phun-ky/cardinal

Cardinal: A set of JavaScript functions that gives you the cardinal direction based on degrees

Commitizen friendly PRs Welcome SemVer 2.0 npm version issues license size npm GitHub Repo stars codecov build

About

A set of JavaScript functions that gives you the cardinal direction based on degrees.

Table of Contents

Installation

npm i --save @phun-ky/cardinal

Usage

With the default function:

import { cardinalDirection } from '@phun-ky/cardinal';

const direction = cardinalDirection(45);
console.log(direction); // south-east

Or with the crude function:

import { cardinalDirectionCrude } from '@phun-ky/cardinal';

const direction = cardinalDirectionCrude(45);
console.log(direction); // south

Or with the detailed function:

import { cardinalDirectionDetailed } from '@phun-ky/cardinal';

const direction = cardinalDirectionDetailed(56.25);
console.log(direction); // south-south-east

API

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

ParameterTypeDescription
degreesnumberThe angle in degrees.

Returns

CardinalDirectionType

  • 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

ParameterTypeDescription
degreesnumberThe angle in degrees.

Returns

CardinalDirectionCrudeType

  • 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

ParameterTypeDescription
degreesnumberThe angle in degrees.

Returns

CardinalDirectionDetailedType

  • 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)

2.0.8

5 months ago

2.0.7

5 months ago

2.0.6

6 months ago

2.0.5

6 months ago

2.0.4

6 months ago

2.0.3

6 months ago

2.0.2

6 months ago

2.0.1

6 months ago

2.0.0

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago