stdlib-js / stdlib

✨ Standard library for JavaScript and Node.js. ✨
https://stdlib.io
Apache License 2.0
4.13k stars 403 forks source link
javascript js lib library math mathematics node node-js nodejs numeric numerical-computing science scientific scientific-computing standard statistics stats stdlib utilities utils

We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib ([/ˈstændərd lɪb/][ipa-english] "standard lib") is a standard library with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js. The library provides a collection of robust, high performance libraries for mathematics, statistics, data processing, streams, and more and includes many of the utilities you would expect from a standard library. What sets stdlib apart is its fully decomposable architecture, which allows you to swap out and mix and match APIs and functionality to cater to your exact preferences and use cases. When you use stdlib, you can be confident that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code available. Want to join us in bringing numerical computing to the web? **Start by starring the project.** :star2: Explore this GitHub repository for stdlib's source code and documentation. For guidance on developing stdlib, refer to the [development guide][stdlib-development]. Thank you for being a part of our community! Your support is invaluable to us! ## Resources - [**Installation**](#installation) - [**Homepage**][stdlib-homepage] - [**Documentation**][stdlib-documentation] - [**Source code**][stdlib-source] - [**Code coverage**][stdlib-code-coverage] - [**FAQ**][stdlib-faq] ### External Resources - [**Open Collective**][open-collective-stdlib] - [**Twitter**][stdlib-twitter] - [**Gitter**][stdlib-gitter] ## Features - 150+ [special math functions][@stdlib/math/base/special].
Demo showcasing special math functions
- 35+ [probability distributions][@stdlib/stats/base/dists], with support for evaluating probability density functions (PDFs), cumulative distribution functions (CDFs), quantiles, moments, and more.
Demo showcasing probability distributions
- 40+ [seedable pseudorandom number generators][@stdlib/random/base] (PRNGs).
Demo showcasing PRNGs
- 200+ general [utilities][@stdlib/utils] for data transformation, functional programming, and asynchronous control flow.
Demo showcasing general utilities
- 200+ [assertion utilities][@stdlib/assert] for data validation and feature detection.
Demo showcasing assertion utilities
- 50+ [sample datasets][@stdlib/datasets] for testing and development.
Demo showcasing sample datasets
- A [plot API][@stdlib/plot/ctor] for data visualization and exploratory data analysis.
Demo showcasing plot API
- Native add-ons for interfacing with BLAS libraries, with pure JavaScript fallbacks.
Demo showcasing BLAS APIs
- A [benchmark framework][@stdlib/bench/harness] supporting TAP.
Demo showcasing benchmark framework
- REPL environment with integrated help and examples.
Demo showcasing REPL environment
- Can be bundled using [Browserify][browserify], [Webpack][webpack], and other bundlers for use in web browsers.
Demo showcasing browser support
- Every function is accompanied by [TypeScript][typescript] declaration files, ensuring type safety and facilitating intelligent code completion in IDEs.
Demo showcasing TypeScript declaration files
* * * ## Installation To accommodate various use cases, stdlib can be used in multiple ways. The preferred method of use depends on your individual use case. We've provided some user stories to help you identify the best approach. 😃 While this project's installation instructions defaults to using [npm][npm] for package management, installation via other package managers, such as [yarn][yarn], should be a matter of simply swapping out [npm][npm] commands with those of the relevant package manager. ### User Stories - I want to perform **data analysis** and **data science** tasks in JavaScript and Node.js, similar to how I might use Python, Julia, R, and MATLAB. - Install the entire project as a [command-line utility](#install_command_line_utility). - I am building a **web application**. - I plan on using [Browserify][browserify], [Webpack][webpack], and other bundlers for use in web browsers. - Install [individual packages](#install_individual_packages). Installing the entire project is likely unnecessary and will lead to slower installation times. - I would like to **vendor** a custom bundle containing various stdlib functionality. - Follow the steps for creating [custom bundles](#install_custom_bundles). - I would like to include stdlib functionality by just using a `script` tag. - I would like to use ES Modules. - Use an individual package's ES Module [build](#install_env_builds_esm). - I would like to use a pre-built bundle (possibly via a CDN, such as [unpkg][unpkg] or [jsDelivr][jsdelivr]). - Install (or consume via a CDN) an individual package's pre-built UMD [browser bundle](#install_env_builds_umd). - I am interested in using a substantial amount of functionality found in a top-level stdlib namespace and don't want to separately install hundreds of individual packages (e.g., if building an on-line calculator application and wanting all of stdlib's math functionality). - Install one or more top-level [namespaces](#install_namespaces). Installing the entire project is likely unnecessary and will lead to slower installation times. Installing a top-level namespace is likely to mean installing functionality which will never be used; however, installing a top-level namespace is likely to be easier and less time-consuming than installing many individual packages separately. When bundling, installing a top-level namespace should not be a concern, as individual functionality can still be independently required/imported. Project installation times may, however, be somewhat slower. - I am building a [Node.js][node-js] **server application**. - I am interested in using various functionality found in stdlib. - Install [individual packages](#install_individual_packages). Installing the entire project is likely unnecessary and will lead to slower installation times. - I would like to **vendor** stdlib functionality and avoid dependency trees. - Install individual package UMD [bundles](#install_env_builds_nodejs). - I am interested in using a _substantial_ amount of functionality found in a top-level stdlib namespace and don't want to separately install hundreds of individual packages. - Install one or more top-level [namespaces](#install_namespaces). Installing the entire project is likely unnecessary and will lead to slower installation times. Installing a top-level namespace is likely to mean installing functionality which will never be used; however, installing a top-level namespace is likely to be easier and less time-consuming than installing many individual packages separately. - I am using **Deno**. - Import [individual packages](#install_env_builds_deno) using pre-built Deno builds. - I would like to use stdlib functionality in an [Observable][observable] notebook. - Consume a pre-built [browser bundles](#install_env_builds_umd) via a CDN, such as [unpkg][unpkg] or [jsDelivr][jsdelivr]. - I want to hack at stdlib, possibly even creating **customized** builds to link to platform-specific native libraries (such as Intel's MKL or some other numerical library). - Install the project as a [system library](#install_system_library) by cloning this repository and following the [installation][stdlib-development] instructions as described in the [development guide][stdlib-development]. ### Complete Library To install the entire project as a library or application dependency, ```bash $ npm install @stdlib/stdlib ``` Once installed, stdlib packages can be individually required/imported to minimize load times and decrease bundle sizes. For example, to use `require` ```javascript var ndarray = require( '@stdlib/ndarray/array' ); var arr = ndarray( [ [ 1, 2 ], [ 3, 4 ] ] ); // returns ``` and to use `import` ```javascript import ndarray from '@stdlib/ndarray/array'; var arr = ndarray( [ [ 1, 2 ], [ 3, 4 ] ] ); // returns ``` ### Individual Packages stdlib is designed to allow decomposition of the main project into individual packages which can be independently consumed. Accordingly, users of the project can avoid installing all project functionality and only install the exact functionality they need. To install individual packages, replace forward slashes `/` after `@stdlib/` with hyphens `-`. For example, ```bash $ npm install @stdlib/ndarray-array ``` Once installed, individual packages can be required/imported. For example, to use `require` ```javascript var ndarray = require( '@stdlib/ndarray-array' ); var arr = ndarray( [ [ 1, 2 ], [ 3, 4 ] ] ); // returns ``` and to use `import` ```javascript import ndarray from '@stdlib/ndarray-array'; var arr = ndarray( [ [ 1, 2 ], [ 3, 4 ] ] ); // returns ``` ### Namespaces stdlib is comprised of various top-level namespaces (i.e., collections of related functionality united by common themes). For example, to install all math functionality found in the top-level `math` namespace, ```bash $ npm install @stdlib/math ``` Once installed, packages within a top-level namespace can be individually required/imported to minimize load times and decrease bundle sizes. For example, to use `require` ```javascript var sin = require( '@stdlib/math/base/special/sin' ); var v = sin( 3.14 ); // returns ``` and to use `import` ```javascript import sin from '@stdlib/math/base/special/sin'; var v = sin( 3.14 ); // returns ``` **Note**: installing nested namespaces found within top-level namespaces (e.g., `math/base`) is **not** supported. Consider installing individual packages or the relevant top-level namespace. ### Command-line Utility To install globally for use as a command-line utility and/or use the [REPL][@stdlib/repl], ```bash $ npm install -g @stdlib/stdlib ``` which will expose the `stdlib` command. For example, to see available sub-commands ```bash $ stdlib help ``` and to run the [REPL][@stdlib/repl] ```bash $ stdlib repl ``` ### Environment Builds #### ES Modules To use ES Modules via a ` ``` #### Deno To use individual packages in Deno, use **Deno builds** available in each package's repository via a dedicated `deno` branch (e.g., see the [`deno`][@stdlib/ndarray-array-deno] branch for [`@stdlib/ndarray-array`][@stdlib/ndarray-array-deno]). For example, ```javascript import ndarray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@deno/mod.js'; var arr = ndarray( [ [ 1, 2 ], [ 3, 4 ] ] ); // returns ```` #### jQuery-like Bundle For those wanting a jQuery-like bundle, one can use pre-built distributable UMD bundles for use in browser environments or as shared ("vendored") libraries in server environments available in each package's repository via a dedicated `umd` branch. See sections [UMD](#install_env_builds_umd) and [Node.js](#install_env_builds_nodejs) for more details. #### UMD To use UMD bundles either via a ` ``` #### Node.js To **vendor** stdlib functionality and avoid installing dependency trees, use UMD **server builds** available in each package's repository via a dedicated `umd` branch (e.g., see the [`umd`][@stdlib/math-base-special-erf-umd] branch for [`@stdlib/math-base-special-erf`][@stdlib/math-base-special-erf-umd]). For example, ```javascript var linspace = require( '/path/to/vendor/umd/@stdlib/array-base-linspace' ); var erf = require( '/path/to/vendor/umd/@stdlib/math-base-special-erf' ); var x = linspace( -10.0, 10.0, 100 ); for ( var i = 0; i < x.length; i++ ) { console.log( 'x: %d, erf(x): %d', x[ i ], erf( x[ i ] ) ); } ``` ### Custom Bundles To create a custom bundle based on project needs, 1. follow the [download][stdlib-development], [configuration][stdlib-development], and [installation][stdlib-development] instructions as described in the [development guide][stdlib-development]. 2. navigate to the local installation directory. 3. run the following command to print help documentation for providing a list of stdlib package names to bundle ```bash $ NODE_PATH=./lib/node_modules node ./bin/cli bundle-pkg-list -- -h ``` 4. modify and run the above command with the list of packages to bundle ```bash $ NODE_PATH=./lib/node_modules node ./bin/cli bundle-pkg-list -- ... ``` Upon generating a bundle, the bundle can be loaded via a ` Githubissues.
  • Githubissues is a development platform for aggregating issues.