stdlib JavaScript Standard Library
repository·develop·Indexed 24 days ago
https://github.com/stdlib-js/stdlibA robust, high-performance standard library for numerical and scientific computation in JavaScript and C, targeting Node.js and browser environments. Version 0.4.1 includes tools for NumPy migration, editor configurations for VS Code and Sublime Text, and a comprehensive set of numerical operations.
What's inside stdlib
- stdlib is a standard library designed for numerical and scientific computation in JavaScript and C. It is optimized for execution in both web browsers and Node.js environments. The library features a decomposable architecture, allowing developers to mix and match specific APIs and functionalities to suit their specific use cases.
Understand why JavaScript globals are provided as packages
developThe project wraps built-in JavaScript globals as individual packages rather than relying on the environment's native implementation. This approach is used to:
- Polyfill: Ensure consistent behavior across different platforms and environments by providing implementations for absent or defective globals.
- Document: Provide centralized, consistent documentation for globals.
- Test: Monitor built-in implementations for abnormal behavior via unit testing.
- Mock: Facilitate testing by allowing globals to be mocked via dependency injection without side effects from overwriting the global scope.
- Benchmark: Organize and track environment performance for built-ins.
Why not contribute improvements to existing libraries?
developThe project does not typically submit improvements to external libraries due to:
- Rewrites: Necessary improvements often require drastic architectural shifts or complete rewrites of existing libraries.
- Bandwidth: Core authors lack the resources to maintain both this project and external community libraries.
- Opportunity cost: Engaging with external libraries involves risks and maintenance burdens that detract from project development.
- Priorities: The project focuses on areas where authors have the most control to avoid developer debates (bikeshedding) and maximize development efficiency.
Run unit tests and generate coverage reports using make
developThis directory providesmakerecipes designed to run unit tests for project tools and utilities and to generate test coverage reports.Understand the rationale for using stdlib for numerical computing
developThe
stdlibproject provides numerical and scientific computing capabilities specifically for JavaScript and Node.js environments. Developers choose this project to:- Minimize Context-Switching: Use a single language (JavaScript) for both application logic and heavy computation.
- Enable Web-Based Computation: Perform complex numerical analysis directly in the browser without server-side overhead.
- Leverage Edge Computing: Offload computation to client applications to reduce server costs and latency.
- Simplify Deployment: Avoid the complexities of managing native binaries, compilers (like
gfortran), and platform-specific build tools. - Improve Visualization: Integrate computation and data visualization seamlessly within the JavaScript ecosystem.
- Ensure Portability: Use code that is standards-compliant and works across different environments (Node.js, Browsers) without the breakage often seen in other language ecosystems.
Run stdlib commands and subcommands
developThe
stdlibCLI is organized into several functional groups. Common command categories include:- Commands:
help,datasets,repl,repl-presentation. - Assert: Environment and value assertions (e.g.,
has-wasm-support,is-email-address). - Benchmarking:
bench(run benchmark files) andtimeit(time a snippet). - Filesystem:
exists,read-dir,read-file,write-file, etc. - Random: Pseudorandom number generators (e.g.,
random-mt19937,random-randn). - System: Environment info (e.g.,
arch,cwd,platform). - Utilities: String and numeric manipulations (e.g.,
capitalize,trim,sizeof).
- Commands:
Generate TypeScript declaration coverage reports
developThis directory providesmakecommands used to generate TypeScript declaration coverage reports. These commands are part of the internalmaketooling infrastructure for thestdlibrepository.Understand the vendor dependency directory structure
developThe
depsdirectory is used for managing vendor dependencies (third-party libraries). It is organized into the following subdirectories:deps/checksums: Contains checksums for vendor dependencies to ensure integrity.deps/test: Contains installation tests for vendor dependencies.deps/tmp: A temporary location for storing dependency downloads.deps/build: A location for storing dependency builds.
Important: The
deps/tmpanddeps/builddirectories should not be committed to the project repository.Understand the project's modular decomposition and composability
developThe project follows a modular decomposition philosophy. Every package (core library and tooling) is designed to be consumed and understood independently. Each package maintains its own resource locality, including its own documentation, tests, benchmarks, and examples.
Key principles:
- Independence: You should not need to install the entire project to consume a single part.
- Granularity: Unlike traditional standard libraries (e.g., Python, R, Julia) that require bundling the entire runtime, this project allows you to consume only what you need.
- Composability: The architecture is designed to allow users to fork, customize, and recombine individual parts to build their own custom standard libraries.
Identify official stdlib domains
developTo avoid phishing attempts, only trust the domain names officially affiliated with the project. The following domains are currently active:
- stdlib.io: The official website.
- stdlib.blog: The official development blog.
Relationship between stdlib and WebAssembly
developThe project views WebAssembly (Wasm) as a complementary technology rather than a replacement for JavaScript-based numerical libraries.
stdlibfocuses on providing modular, bundle-friendly, and idiomatic JavaScript implementations that address immediate needs for:- Modular Bundling: Unlike large monolithic libraries (e.g., NumPy) that are difficult to tree-shake,
stdlibis designed to be modular for efficient web bundling. - Developer Experience: Providing libraries in the same idiom as the application code reduces cognitive overhead.
- Immediate Availability: Providing working numerical libraries for the web now, rather than waiting for ubiquitous Wasm development patterns.
- Modular Bundling: Unlike large monolithic libraries (e.g., NumPy) that are difficult to tree-shake,
Explore stdlib features
developstdlib provides a wide range of high-performance tools for scientific computing, including:
- Special Math Functions: 150+ functions available via
@stdlib/math/base/special. - Probability Distributions: 35+ distributions (PDF, CDF, quantiles, moments, etc.) via
@stdlib/stats/base/dists. - Pseudorandom Number Generators (PRNGs): 40+ seedable generators via
@stdlib/random/base. - General Utilities: 200+ utilities for data transformation, functional programming, and async control flow via
@stdlib/utils. - Assertion Utilities: 200+ utilities for data validation and feature detection via
@stdlib/assert. - Sample Datasets: 50+ datasets for testing and development via
@stdlib/datasets. - Plot API: Tools for data visualization and exploratory data analysis via
@stdlib/plot/ctor. - BLAS Interfacing: Native add-ons for BLAS libraries with pure JavaScript fallbacks.
- Benchmark Framework: A framework supporting TAP via
@stdlib/bench/harness. - REPL: An interactive environment with integrated help and examples.
- TypeScript Support: Every function includes TypeScript declaration files for type safety and IDE autocompletion.
- Special Math Functions: 150+ functions available via