New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@bedard/math

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bedard/math

[![Build status](https://img.shields.io/github/workflow/status/scottbedard/math/Test)](https://github.com/scottbedard/math/actions) [![Codecov](https://img.shields.io/codecov/c/github/scottbedard/math)](https://codecov.io/gh/scottbedard/math) [![Dependenc

  • 0.5.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

@bedard/math

Build status Codecov Dependencies Dev dependencies NPM Bundle size License

This library exists to help me avoid duplicate code between projects. My goal is to expose small, well tested, and tree-shakeable utility functions. Given the simplicity of these, I do not anticipate breaking changes. But be warned, this project is not following semantic versioning.

Installation

The recommended installation method is via NPM.

npm install @bedard/math

Alternatively, these functions maybe be accessed via a CDN. When using a CDN, the library will be exposed globally as BedardMath.

<script src="https://unpkg.com/@bedard/math"></script>

Functions

angleFrom

Calculate angled distance from a vector. An angle of 0 degrees will track along the X axis, with positive angles rotating counter-clockwise.

import { angleFrom } from '@bedard/math'

angleFrom([0, 0], 90, 1) // [0, 1] (approximate)

bilerp

Bi-linear interpolation between vectors.

import { bilerp } from '@bedard/math'

bilerp([0, 0], [10, 10], 0.5) // [5, 5]

degreesToRadians

Convert degrees to radians.

import { degreesToRadians } from '@bedard/math'

degreesToRadians(180) // 3.141592653589793

intersect

Intersect two-dimensional lines. Returns undefined if lines are parellel.

import { intersect } from '@bedard/math'

intersect([[-1, 0], [1, 0]], [[0, 1], [0, -1]]) // [0, 0]

isEven

Test if a number is even.

import { isEven } from '@bedard/math'

isEven(2) // true

lerp

Linear interpolation between numbers.

import { lerp } from '@bedard/math'

lerp(0, 10, 0.5) // 5

measure

Measure the distance between two vectors.

import { measure } from '@bedard/math'

// arguments can be provided as a pair of vectors
measure([0, 0], [3, 4]) // 5

// or as a single line argument
measure([[0, 0], [3, 4]]) // 5

radiansToDegrees

Convert radians to degrees.

import { radiansToDegrees } from '@bedard/math'

radiansToDegrees(Math.PI) // 180

rotate

Rotate a vector counter-clockwise around the origin.

import { rotate } from '@bedard/math'

rotate([0, 1], 90) // [-1, 0] (approximate)

slope

Calculate the slope of a line.

import { slope } from '@bedard/math'

// arguments can be provided as a pair of vectors
slope([0, 0], [1, 1]) // 1

// or as a single line argument
slope([[0, 0], [1, 1]]) // 1

License

MIT

Copyright (c) 2021-present, Scott Bedard

FAQs

Package last updated on 28 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc