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

jsmaths

v1.0.5

Published

JSMaths is an statistics math library written in TypeScript for JavaScript and Node.js

Downloads

111

Readme

jsMaths is an extended math library written in Typescript, for JavaScript and Node.js. I miss statistics operations in the native maths library, so this package offers to you a simple and elegant way to work with statistics functions. Powerful and easy to use.

Features

  • Supports mean, median, mode, percentile and range.
  • Is compatible with JavaScript's built-in Math library.
  • Written in Typescript
  • Runs on any JavaScript engine.
  • Is easily extensible.
  • Open source.

Usage

jsMaths can be used in both node.js and in the browser.

Install jsMatsh using npm:

npm install jsmaths

Percentile

A percentile (or a centile) is a measure used in statistics indicating the value below which a given percentage of observations in a group of observations falls. You can calculate the percentile of an array of numbers.

import { percentile } from 'jsmaths';

// Percentile 30th from an array of numbers
const percentile = percentile([35, 20, 15, 50, 40], 30) // 20 is the 30th percentile

Exceptions The percentile function return an exception when:

  • Array is empty
  • Percentile is less than 0 or greater than 100

Median

A median is a value separating the higher half from the lower half of a data sample, a population or a probability distribution. For a data set, it may be thought of as "the middle" value. You can execute the median function passing an array of numbers. The median can be one or two numbers, so the function return an array with one or two numbers, depending on the source array.

import { median } from 'jsmaths';

const medianOne = median([35, 20, 15, 50, 40]) // [35] is the median
const medianTwo = median([3, 6, 7, 8, 8, 10, 13, 15, 16, 20]) // [8, 10] are the median

Exceptions The median function return an exception when:

  • Array is empty

Mean (Average)

For a data set, the arithmetic mean, also called the expected value or average, is the central value of a discrete set of numbers: specifically, the sum of the values divided by the number of values. You can execute the mean function passing an array of numbers. It returns a number indicates the mean.

import { mean } from 'jsmaths';

const meanOne = mean([35, 20, 15, 50, 40]) // 32 is the mean
const meanTwo = mean([3, 6, 7, 8, 8, 10, 13, 15, 16, 20]) // 10.6 is the mean

Exceptions The mean function return an exception when:

  • Array is empty

Mode

The mode is the value that appears most often in a set of data values. In other words, it is the value that is most likely to be sampled. When none of the values are repeated, it is said that there is no mode. You can calculate the mode of an array using the mode function. It returns and array with modes, or an empty array if there is no mode.

import { mode } from 'jsmaths';

const modeOne = mode([35, 20, 15, 50, 40]) // [] empty array, no mode exists
const modeTwo = mode([3, 6, 7, 8, 8, 10, 13, 15, 16, 20]) // [8] is the mode
const modeThree = mode([3, 6, 7, 8, 8, 9, 9, 10, 10, 13, 15, 16, 20]) // [8, 9, 10] are the modes

Range

The range of a set of data is the difference between the largest and smallest values. You can calculate a range of an array using the range function. It returns an array with two number. The 0 index is the smallest value. The 1 index is the largest value.

import { range } from 'jsmaths';

const rangeOne = range([35, 20, 15, 50, 40]) // [15, 20] 15 is the smallest and 20 is the largest
const rangeTwo = range([3, 6, 7, 8, 8, 10, 13, 15, 16, 20]) // [3, 20]
const rangeThree = range([3]) // [3, 3] are the modes

Exceptions The range function return an exception when:

  • Array is empty

Browser support

jsMaths works on any ES5 compatible JavaScript engine: node.js, Chrome, Firefox, Safari, Edge, and IE11.

Test

To execute tests for the library, install the project dependencies once:

npm install

Then, the tests can be executed:

npm test

To test code coverage of the tests:

npm run coverage

Continuous integration testing

Continuous integration tests are run on Travis CI and Cocecov every time a commit is pushed to github. The test results can be checked on https://travis-ci.org/juanm4/jsmaths. Travis CI runs the tests for different versions of node.js.

License

Copyright (C) 2020-2021 Juanma Molina [email protected]

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.