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

momenta

v0.1.4

Published

Basic vector operations

Downloads

6

Readme

momenta

Basic vector operations over the rational numbers.

Support

browser support

Examples

where m.r is the rationals used by momenta

var m = require('momenta');
m([1])[0] === m.r(1); // true

while in the case of rationals it made sense to keep direct equality between the created objects, I think this is not the case with momentai. However this might change some time in the future.

Another issue is that no matter how much I wish, there isn't a good, widely supported way to subclass array (not until es6 is widely supported). The workarounds available kinda create more problems than they solve, so after a day of thinking I went in the minimalist direction. This also means, that while momenta methods expect arrays and scalars with add, sub, scale, disperse, dot methods on them, the module's user should provide these methods.

Probably worth to mention that the API gives you easy solution to this:

var m = require('momenta');
var equal = require('deep-equal');
var r = m.r;
equal(m.disperse(m([1,4,7,9,16]), r(12)), m([r(1,12),r(1,3),r(7,12),r(3,4),r(4,3)])); // true

API

all methods on momenta objects will return an array of rationals with the exception of .dot, which will return a single rational

Casting an array of integers to rationals

momenta()
m([3])[0].toString()  // 3/1

Casting an integer to a rational

momenta.r()
m.r(5).toString()  // 5/1

Scaling up

scale
m.scale(m([1,3,5]), m.r(7))  // [7/1,21/1,35/1]

Scaling down

disperse
m.disperse(m([1,3,5]), m.r(9)) // [1/9,1/3,5/9]

Addition

add
m.add(m([1,3,5]), m([2,4,6])) // [3/1,7/1,11/1]

Subtraction

sub
m.sub(m([3,7,11]), m([2,4,6])) // [1/1,3/1,5/1]

Dot product

dot
m.dot(m([1,3,5]), m([7,11,13])) // 105/1

Cross product

cross
m.cross(m([1,3,5]), m([7,11,13])) // [-16/1, 22/1, -10/1]

Install

npm install momenta

You can use it in the browser with browserify