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

simplemathjs

v1.2.0

Published

MathJs is a small javascript library for performing set theory and basic mathematical functions on numbers and arrays.

Downloads

2

Readme

MathJs


MathJs is a small javascript library for performing mundane tasks repeatedly in a easy way. A few of the things that this library is capable of are operations like, rounding a decimal upto 2 decimal places, or trying to find the difference between two arrays.

Read on to find out more features about this library.

Download

You can download this library as an npm module by running the following command

npm install simplemathjs

Once downloaded, you can include in your html file like so

<script type="text/javascript" src="node_modules/dist/math.min.js"></script>

That's it, you can now use this library by referring to the MJ variable within your javascript

MJ.round(3.14159265, 2)
// 3.14

MJ.arrayDiff([1, 2, 3, 4], [1, 4, 2])
// [3]

There functionalities are segrated by primarily three sections

  1. Array Functionalities
  2. Numberic Functionalities
  3. String Functionalities

Arrays

List of Functions that you can operate on Arrays

arrayFlatten

Given an array of arrays, it will flatten hierarchies of arrays and return a single array.

MJ.arrayFlatten([1, 2, [3, 4, [5, 6], [7]], [8, 9]])
// [1, 2, 3, 4, 5, 6, 7, 8, 9]

arrayUnique

Given a list of items in an array, it will returns an array of elements containing all the elements occurring only once, i.e. removes duplicates.

MJ.arrayUnique([1, 1, 'b', false, false, true, 'b', undefined, undefined])
// [1, "b", false, true, undefined]

arrayIntersection

Given two sets of arrays, returns the set of unique elements which are present in both

MJ.arrayIntersection([1, 2, 3, 2], [1, 5, 2, 1])
// [1, 2]

arrayDiff

Given two set of arrays, returns the set of elements present in the left, but not in the right.

MJ.arrayDiff([1, 2, 3, 4], [1, 4, 2])
// [3]
MJ.arrayDiff([1, 423, 64], [1, 64, 23, 521, 423])
// [] since there are no elements on the left which are NOT present on the right

arrayUnion

Given a set of arrays as arguments, returns a single array containing all the elements present in every argument, including duplicates.

NOTE: the arguments for the function always need to be an array

MJ.arrayUnion([1, 5, 5], [2, [2, false], 'abc'], [true, ['another', 5.15], undefined, null])
// [1, 5, 5, 2, [2, false], "abc", true, ['another', 5.15], undefined, null]
MJ.arrayUnion([1], [], [2])
// [1, 2]

arrayMean

Given an array of numbers,

MJ.arrayMean([1, 2, 3, 100, 101, 202])
// 68.16666666666667

MJ.arrayMean([false, 'abc'])
// NaN