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 🙏

© 2024 – Pkg Stats / Ryan Hefner

direction.js

v2.0.0

Published

2D and 3D vectors library

Downloads

4

Readme

Direction.js

A simple 2D and 3D vectors library for JavaScript

Generic badge MIT license contributions welcome

Direction.js is a small JavaScript library that helps you to use Vectors in JavaScript. It comes built in with vector math (addition, subtract, multiplication, division and the dot product), and your able to get properties f the vector (equals, opposite, parallel, anti-parallel and normalize).

Installing

To install, you can use NPM, Yarn or a CDN.

<script src="https://unpkg.com/direction.js/lib/Direction.min.js"></script>
npm install direction.js

or

yarn add direction.js

Getting Started

// require module
const Vector = require('direction.js');

// create either a 2d or 3d vector
const vector2D = new Vector(10, 10);
const vector3D = new Vector(20, 1.2, 2);

const pos1 = new Vector(2, 2, 1);
const pos2 = new Vector(4, 4, 1)

console.log(pos1.equals(pos2)); // --> false

console.log(pos1.opposite(pos2)); // --> false

console.log(pos1.parallel(pos2)); // --> true

console.log(pos1.antiParallel(pos2)); // --> false

console.log(pos1.normalize()); // --> Vector { x: 0.6666666666666666, y: 0.6666666666666666, z: 0.3333333333333333, length: 1 }

console.log(pos1.add(pos2)); // --> Vector { x: 6, y: 6, z: 2, length: 8.717797887081348 }

console.log(pos1.subtract(pos2)); // --> Vector { x: -2, y: -2, z: 0, length: 2.8284271247461903 }

console.log(pos1.multiply(pos2)); // --> Vector { x: 8, y: 8, z: 1, length: 11.357816691600547 }

console.log(pos1.divide(pos2)); // --> Vector { x: 0.5, y: 0.5, z: 1, length: 1.224744871391589 }

console.log(pos1.dotProduct(pos2)); // --> 35.4742021358683

Developing

Setting up Dev

Here's a brief intro about what a developer must do in order to start developing the project further:

git clone https://github.com/sidnand/Direction.js.git
cd Direction.js/
yarn install
  1. Clone the repo
  2. cd into the new folder
  3. Install the dependencies

Versioning

I'm using SemVer for versioning.

Tests

I'm using mocha and chai.assert to test. Go into test/Direction.test.js and add your test.

yarn test

API

.equals([new Vector()])

.opposite([new Vector()])

.parallel([new Vector()])

.antiParallel([new Vector()])

.normalize()

.add([new Vector()])

.subtract([new Vector()])

.multiply([new Vector()])

.divide([new Vector()])

.dotProduct([new Vector()])

Style Guide

JavaScript Style Guide

I'm using JavaScript Standard Style.

Eslint:

yarn run lint <file>

License

Licensed under MIT License