• Stars
    star
    3,466
  • Rank 12,305 (Top 0.3 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created about 8 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

✨ Standard library for JavaScript and Node.js. ✨

stdlib (/ˈstændərd lɪb/ "standard lib") is a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing applications. 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.

This is the GitHub repository of stdlib source code and documentation. For help developing stdlib, see the development guide.

Resources

External Resources

Features


Installation

To accommodate various use cases, stdlib can be consumed in multiple ways. The preferred means of consumption 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 for package management, installation via other package managers, such as yarn, should be a matter of simply swapping out 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.

  • I am building a web application.

    • I plan on using Browserify, Webpack, and other bundlers for use in web browsers.

      • 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.

    • 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.
      • I would like to use a pre-built bundle (possibly via a CDN, such as unpkg or jsDelivr).

        • Install (or consume via a CDN) an individual package's pre-built UMD browser bundle.
    • 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. 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 server application.

    • I am interested in using various functionality found in stdlib.

      • 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.
    • 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. 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.

  • I would like to use stdlib functionality in an Observable notebook.

  • 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).

Complete Library

To install the entire project as a library or application dependency,

$ 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

var ndarray = require( '@stdlib/ndarray/array' );

var arr = ndarray( [ [ 1, 2 ], [ 3, 4 ] ] );
// returns <ndarray>

and to use import

import ndarray from '@stdlib/ndarray/array';

var arr = ndarray( [ [ 1, 2 ], [ 3, 4 ] ] );
// returns <ndarray>

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,

$ npm install @stdlib/ndarray-array

Once installed, individual packages can be required/imported. For example, to use require

var ndarray = require( '@stdlib/ndarray-array' );

var arr = ndarray( [ [ 1, 2 ], [ 3, 4 ] ] );
// returns <ndarray>

and to use import

import ndarray from '@stdlib/ndarray-array';

var arr = ndarray( [ [ 1, 2 ], [ 3, 4 ] ] );
// returns <ndarray>

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,

$ 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

var sin = require( '@stdlib/math/base/special/sin' );

var v = sin( 3.14 );
// returns <number>

and to use import

import sin from '@stdlib/math/base/special/sin';

var v = sin( 3.14 );
// returns <number>

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,

$ npm install -g @stdlib/stdlib

which will expose the stdlib command. For example, to see available sub-commands

$ stdlib help

and to run the REPL

$ stdlib repl

Environment Builds

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, see the dist directory and associated guide.

As an example, to include a UMD bundle exposing lower-level special math functions in a webpage, we can first locally install the UMD bundle package using npm

$ npm install @stdlib/dist-math-base-special-flat

and then include the following <script> tag in our HTML document

<script type="text/javascript" src="/path/to/@stdlib/dist-math-base-special-flat/build/bundle.min.js"></script>

making sure to modify the script path based on the local installation directory.

If no recognized module system is present, one can access bundle contents in another <script> tag via the global scope.

<script type="text/javascript">
    // If no recognized module system present, exposed to global scope:
    var erf = stdlib_math_base_special_flat.erf;
    console.log( erf( 0.5 ) );
</script>

For more details and available bundles, see the dist directory and associated guide. The guide includes instructions for consuming via CDNs, such as unpkg.

ES Modules

To use ES Modules via a <script> tag, use ES Module builds available in each package's repository via a dedicated esm branch (e.g., see the esm branch for @stdlib/math-base-special-erf). For example,

<script type="module">
import linspace from 'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-linspace@esm/index.mjs';
import erf from 'https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-erf@esm/index.mjs';

const x = linspace( -10.0, 10.0, 100 );

for ( let i = 0; i < x.length; i++ ) {
    console.log( 'x: %d, erf(x): %d', x[ i ], erf( x[ i ] ) );
}
</script>

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 branch for @stdlib/ndarray-array). For example,

import ndarray from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@deno/mod.js';

var arr = ndarray( [ [ 1, 2 ], [ 3, 4 ] ] );
// returns <ndarray>

UMD

To use UMD bundles either via a <script> tag or in Observable, use UMD browser builds available in each package's repository via a dedicated umd branch (e.g., see the umd branch for @stdlib/math-base-special-erf). For example,

<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/stdlib-js/array-base-linspace@umd/browser.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-erf@umd/browser.js"></script>
<script type="text/javascript">
(function () {

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 ] ) );
}

})();
</script>

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 branch for @stdlib/math-base-special-erf). For example,

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, configuration, and installation instructions as described in the development guide.

  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

    $ 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

    $ NODE_PATH=./lib/node_modules node ./bin/cli bundle-pkg-list -- <pkg> <pkg> <pkg> ...

Upon generating a bundle, the bundle can be loaded via a <script> tag as described above for pre-built distributable UMD bundles.

System Library

To install as a system library (e.g., for the purposes of creating custom builds), follow the download, configuration, and installation instructions as described in the development guide.


Prerequisites

Installing and running stdlib for use in Node.js requires the following prerequisites:

  • Node.js: JavaScript runtime (version >= 0.10)
  • npm: package manager (version > 2.7.0; if Node < 1.0.0, version > 2.7.0 and < 4.0.0; if Node <= 10.x.x, version > 2.7.0 and < 6.0.0)

Most functionality in stdlib is implemented in JavaScript and no further prerequisites are required to use stdlib (i.e., you can safely avoid installing any additional prerequisites); however, some implementations try to capture performance benefits by using native bindings and/or WebAssembly. While not required to run stdlib, as every stdlib implementation has a JavaScript fallback, the following dependencies are required for building native add-ons, including linking to BLAS and LAPACK libraries:

  • GNU make: development utility and task runner
  • GNU bash: an sh-compatible shell
  • gcc & g++ or Clang: C/C++ compilation and linking (g++ version >= 4.8; clang version >= 3.5, Xcode version >=8.3.1 on OS X)
  • gfortran: Fortran compilation and linking (version >= 4.8)

While not required to run stdlib, the following dependencies are required for automatically downloading external libraries:

  • curl, wget, or fetch (FreeBSD): utilities for downloading remote resources

The following external libraries can be automatically downloaded and compiled from source using make:

  • OpenBLAS: optimized BLAS library
  • Electron: framework for cross-platform desktop applications

Contributing

First time contributor?

Already an expert?

  • Fork the repository.

  • Clone the forked repository

    $ git clone --depth=1 https://github.com/<username>/stdlib.git

    where <username> is your GitHub username.

  • Navigate to the stdlib directory

    $ cd stdlib
  • Install dependencies

    $ make install-node-modules
  • Initialize your stdlib development environment

    $ make init

Sponsors

stdlib development is generously supported by the following sponsors...


Users

The following organizations and key stakeholders trust and depend on stdlib...

Does your organization or company use stdlib? If so, we'd love to hear from you!


Governance

For information about the governance of the stdlib project, see GOVERNANCE.md.

License

See LICENSE.

Copyright

Copyright © 2016-2023. The Stdlib Authors.


Status

stability-experimental

Version

git tag NPM version Node.js version

Community

Chat

More Repositories

1

google-summer-of-code

Google Summer of Code resources.
24
star
2

esm

ES module distribution for stdlib, a standard library for JavaScript and Node.js.
JavaScript
12
star
3

jupyter-stdlib-browser-kernel

Run an in-browser JavaScript Jupyter kernel.
JavaScript
7
star
4

stats-chi2test

Perform a chi-square independence test.
JavaScript
7
star
5

datasets-cmudict

The Carnegie Mellon Pronouncing Dictionary (CMUdict).
JavaScript
7
star
6

nlp-lda

Latent Dirichlet Allocation via collapsed Gibbs sampling.
JavaScript
7
star
7

www-status

Uptime and status monitor for the stdlib website.
Markdown
6
star
8

array-pool

Typed array pool.
JavaScript
5
star
9

stats-lowess

Locally-weighted polynomial regression via the LOWESS algorithm.
JavaScript
5
star
10

stats

Standard library statistical functions.
JavaScript
5
star
11

stats-incr-grubbs

Grubbs' test for outliers.
JavaScript
5
star
12

ndarray

Multidimensional arrays.
C
4
star
13

namespace-alias2related

Return aliases related to a specified alias.
JavaScript
4
star
14

repl-help

Return help text associated with a provided alias.
JavaScript
4
star
15

array

Arrays.
JavaScript
4
star
16

iter

Standard library iterator utilities.
JavaScript
4
star
17

random-base-mt19937

A 32-bit Mersenne Twister pseudorandom number generator.
JavaScript
4
star
18

regexp

Standard library regular expressions.
JavaScript
4
star
19

math-base-special-erfcx

Scaled complementary error function.
JavaScript
4
star
20

ml-incr-sgd-regression

Online regression via stochastic gradient descent (SGD).
JavaScript
4
star
21

www

Website for stdlib, a standard library for JavaScript and Node.js.
JavaScript
4
star
22

utils

Standard utilities.
JavaScript
4
star
23

datasets-dale-chall-new

A list of familiar American-English words.
JavaScript
4
star
24

bench

Benchmark.
JavaScript
4
star
25

stats-base-dists

Standard library probability distribution modules.
Makefile
4
star
26

ndarray-base-ind2sub

Convert a linear index to an array of subscripts.
JavaScript
4
star
27

workshops-fullstack-london-2017

Workshop for FullStack London (2017).
JavaScript
3
star
28

ml-incr-kmeans

Incrementally partition data into `k` clusters.
JavaScript
3
star
29

number-uint32-base-rotl

Bitwise rotation to the left.
Makefile
3
star
30

blas-base-scopy

Copy values from x into y.
JavaScript
3
star
31

constants-float32-max

Maximum single-precision floating-point number.
Makefile
3
star
32

stats-wilcoxon

Wilcoxon signed rank test.
JavaScript
3
star
33

constants-path-delimiter-posix

POSIX path delimiter.
Makefile
3
star
34

stats-base-dists-gamma-cdf

Gamma distribution cumulative distribution function (CDF).
JavaScript
3
star
35

utils-async-if-else

If a predicate function returns a truthy value, return `x`; otherwise, return `y`.
Makefile
3
star
36

utils-compact-adjacency-matrix

Compact adjacency matrix.
JavaScript
3
star
37

function

Function.
JavaScript
3
star
38

stats-base-dists-cosine-mgf

Raised cosine distribution moment-generating function (MGF).
JavaScript
3
star
39

utils-function-sequence

Function sequence.
Makefile
3
star
40

assert-is-uppercase

Test if a value is an uppercase string.
JavaScript
3
star
41

stats-ttest

One-sample and paired Student's t-Test.
JavaScript
3
star
42

stats-ttest2

Two-sample Student's t-Test.
JavaScript
3
star
43

stats-ztest2

Two-sample z-Test.
JavaScript
3
star
44

namespace

The standard library namespace.
JavaScript
3
star
45

constants

Standard library constants.
JavaScript
3
star
46

blas

Standard library basic linear algebra subprograms (BLAS).
JavaScript
3
star
47

datasets-afinn-111

A list of English words rated for valence.
JavaScript
3
star
48

datasets-liu-positive-opinion-words-en

A list of positive opinion words.
JavaScript
3
star
49

assert

Standard assertion utilities.
JavaScript
3
star
50

ndarray-base-nonsingleton-dimensions

Return the number of non-singleton dimensions.
Makefile
3
star
51

ml-incr-binary-classification

Incrementally perform binary classification using stochastic gradient descent (SGD).
JavaScript
3
star
52

plot

Standard library plotting.
JavaScript
3
star
53

random-base-uniform

Uniformly distributed pseudorandom numbers.
JavaScript
3
star
54

repl-info

Return abbreviated help text associated with a provided alias.
JavaScript
3
star
55

datasets-savoy-stopwords-ger

A list German stop words.
JavaScript
3
star
56

os-configdir

Return a directory for user-specific configuration files.
JavaScript
3
star
57

utils-linked-list

Linked list.
JavaScript
3
star
58

assert-is-current-year

Test if a value is the current year.
JavaScript
3
star
59

math-base-special-minmax

Return the minimum and maximum values.
JavaScript
3
star
60

assert-is-gzip-buffer

Test if a value is a gzip buffer.
Makefile
3
star
61

utils-from-entries

Create an object from key-value pairs.
Makefile
3
star
62

stats-base-dists-normal-cdf

Normal distribution cumulative distribution function (CDF).
JavaScript
3
star
63

math-base-special-minabs

Return the minimum absolute value.
Makefile
3
star
64

stats-base-dists-normal-pdf

Normal distribution probability density function (PDF).
JavaScript
3
star
65

assert-is-prime

Test if a value is a prime number.
JavaScript
3
star
66

constants-float64-ln-two-pi

Natural logarithm of 2π.
Makefile
3
star
67

stats-base-stdevwd

Calculate the standard deviation of a strided array using Welford's algorithm.
JavaScript
3
star
68

strided

Strided.
C
3
star
69

utils-identity-function

Identity function.
Makefile
3
star
70

assert-is-duration-string

Test if a value is a duration string.
JavaScript
3
star
71

namespace-pkg2related

Return package names related to a specified package name.
JavaScript
3
star
72

function-ctor

Function constructor.
Makefile
3
star
73

streams-node-debug

Transform stream for debugging stream pipelines.
JavaScript
3
star
74

number-float32-base-to-binary-string

Return a string giving the literal bit representation of a single-precision floating-point number.
JavaScript
3
star
75

random-base-binomial

Binomial distributed pseudorandom numbers.
JavaScript
3
star
76

console

Debugger console.
JavaScript
3
star
77

math-base-special-round2

Round a numeric value to the nearest power of two on a linear scale.
Makefile
3
star
78

utils-prepend

Add elements from one collection to the beginning of another collection.
JavaScript
3
star
79

stats-base-dists-lognormal

Lognormal distribution.
Makefile
3
star
80

utils-move-property

Move a property from one object to another object.
Makefile
3
star
81

utils-try-require

Wrap `require` in a try/catch block.
Makefile
3
star
82

object

Object.
Makefile
3
star
83

stats-incr-nansum

Compute a sum incrementally, ignoring NaN values.
Makefile
3
star
84

math-base-special-rad2deg

Convert an angle from radians to degrees.
Makefile
3
star
85

stats-incr-mean

Compute an arithmetic mean incrementally.
Makefile
3
star
86

stats-base-dists-lognormal-mode

Lognormal distribution mode.
Makefile
3
star
87

utils-append

Add elements from one collection to the end of another collection.
JavaScript
3
star
88

math-iter-special-besselj1

Create an iterator which evaluates the Bessel function of the first kind of order one for each iterated value.
Makefile
3
star
89

assert-is-ascii

Test whether a character belongs to the ASCII character set and whether this is true for all characters in a provided string.
JavaScript
3
star
90

nlp

Standard library natural language processing.
JavaScript
3
star
91

math-iter-special-expit

Create an iterator which evaluates the standard logistic function for each iterated value.
Makefile
3
star
92

assert-is-empty-string

Test if a value is an empty string.
JavaScript
3
star
93

utils-compose

Function composition.
Makefile
3
star
94

namespace-alias2pkg

Return the package name associated with a specified alias.
JavaScript
3
star
95

stats-base-dists-weibull-mean

Weibull distribution expected value.
Makefile
3
star
96

math-base-special-cphase

Compute the argument of a complex number in radians.
Makefile
3
star
97

regexp-eol

Return a regular expression to match a newline character sequence.
JavaScript
3
star
98

repl-code-blocks

Return an example associated with a provided alias.
JavaScript
3
star
99

utils-convert-path

Convert between POSIX and Windows paths.
JavaScript
3
star
100

regexp-regexp

Return a regular expression to parse a regular expression string.
Makefile
3
star