{"id":11189,"library":"jstat","title":"jStat: JavaScript Statistical Library","description":"jStat is a comprehensive JavaScript library providing native implementations of statistical functions, suitable for both browser and Node.js environments. It stands out for offering a wide array of functions for various probability distributions, including Weibull, Cauchy, Poisson, Hypergeometric, and Beta, which are often not found in other similar libraries. For most distributions, jStat includes functions for PDF, CDF, inverse CDF, mean, mode, variance, and sampling. The current stable version is 1.9.6, last published four years ago, indicating a slower release cadence and suggesting potential abandonment. A key point of confusion is its module export structure, exposing `jStat` and `j$` properties within an object rather than as direct exports, which requires specific handling for module loaders like CommonJS and for ESM interoperability. The library also emphasizes browser usage, making the `jStat` object globally available.","status":"abandoned","version":"1.9.6","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/jstat/jstat","tags":["javascript"],"install":[{"cmd":"npm install jstat","lang":"bash","label":"npm"},{"cmd":"yarn add jstat","lang":"bash","label":"yarn"},{"cmd":"pnpm add jstat","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The `jstat` module exports an object containing `jStat` and `j$` properties. Destructure or access them explicitly in CommonJS.","wrong":"const jStat = require('jstat');","symbol":"jStat","correct":"const { jStat } = require('jstat');"},{"note":"When loaded via a script tag in a browser, `jStat` becomes a global property on the `window` object.","wrong":"import { jStat } from 'jstat';","symbol":"jStat","correct":"// <script src='path/to/jstat.min.js'></script>\nconst jstat = window.jStat;"},{"wrong":"import jStat from 'jstat';","symbol":"jStat","correct":"import * as jStatModule from 'jstat';\nconst jStat = jStatModule.jStat;"},{"note":"An alias for `jStat`, also exported from the module object for CommonJS.","symbol":"j$","correct":"const { j$ } = require('jstat');"}],"quickstart":{"code":"import * as jStatModule from 'jstat';\nconst jStat = jStatModule.jStat;\n\n// Define a dataset\nconst dataset = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\n\n// Calculate mean and standard deviation\nconst mean = jStat(dataset).mean();\nconst stdev = jStat(dataset).stdev();\n\nconsole.log(`Dataset: [${dataset.join(', ')}]`);\nconsole.log(`Mean: ${mean}`);\nconsole.log(`Standard Deviation: ${stdev}`);\n\n// Example of using a distribution function: Normal CDF\nconst normalDist = jStat.normal(mean, stdev);\nconst cdfAt7 = normalDist.cdf(7);\nconsole.log(`CDF at x=7 for Normal(${mean.toFixed(2)}, ${stdev.toFixed(2)}): ${cdfAt7.toFixed(4)}`);\n\n// Example of generating a sample\nconst sample = normalDist.sample(5);\nconsole.log(`Random sample of 5 from Normal(${mean.toFixed(2)}, ${stdev.toFixed(2)}): [${sample.map(s => s.toFixed(2)).join(', ')}]`);","lang":"typescript","description":"Demonstrates importing jStat, calculating basic statistics (mean, standard deviation) from a dataset, using a normal distribution's CDF, and generating a random sample."},"warnings":[{"fix":"Always use `npm install jstat` (lowercase) for installation.","message":"The npm package name changed from the case-sensitive `jStat` to the all-lowercase `jstat`. Installing `jStat` will lead to an outdated or non-existent package.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Access the `jStat` (or `j$`) property from the imported module object, e.g., `const { jStat } = require('jstat');` for CommonJS or `import * as jStatModule from 'jstat'; const jStat = jStatModule.jStat;` for ESM.","message":"The `jstat` module does not export its main functionality directly. Instead, it exports an object containing `jStat` and `j$` properties. Direct `require('jstat')` or ESM `import jStat from 'jstat'` will result in an object, not the callable function.","severity":"gotcha","affected_versions":"*"},{"fix":"Evaluate alternatives if active maintenance, modern features, or ongoing support are critical for your project. Be prepared to fork or maintain it yourself if necessary.","message":"The library appears to be largely unmaintained. The last release was over four years ago, and there has been no significant activity on its GitHub repository. This suggests potential risks for security patches, bug fixes, or compatibility with newer JavaScript environments.","severity":"gotcha","affected_versions":"1.9.6"},{"fix":"Consider using a module bundler (like Webpack or Rollup) to encapsulate the library, or rename the global variable immediately after loading if conflicts are expected.","message":"When used in a browser via a script tag, `jStat` pollutes the global `window` object by adding `window.jStat` and `window.j$`. This can lead to naming conflicts in environments with many global scripts.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"The `jstat` module exports an object. You need to access its `jStat` property: `const { jStat } = require('jstat');`","cause":"Attempting to call `require('jstat')` directly as a function in CommonJS.","error":"TypeError: require(...) is not a function"},{"fix":"Ensure `jStat` is correctly destructured from the module import: `const { jStat } = require('jstat');` for CJS, or `import * as jStatModule from 'jstat'; const jStat = jStatModule.jStat;` for ESM.","cause":"`jStat` was not correctly imported or accessed, leading to `jStat` being `undefined` or the wrong object when trying to call a method like `normal()`.","error":"TypeError: Cannot read properties of undefined (reading 'normal')"},{"fix":"Install using the correct, all-lowercase package name: `npm install jstat`.","cause":"Using the incorrect, case-sensitive package name `jStat` instead of `jstat` during installation.","error":"npm ERR! 404 Not Found - GET https://registry.npmjs.org/jStat - Not found"}],"ecosystem":"npm"}