capability.js is a lightweight JavaScript library designed for detecting specific environmental capabilities, primarily focusing on browser features. Released in 2016, its current stable version is 0.2.5, indicating it has not seen significant development since its initial release. The library allows developers to define custom capability tests using a simple API and then query or enforce these capabilities. Unlike comprehensive feature detection libraries like Modernizr, `capability.js` provides a minimalist approach for defining and checking individual features such as `Object.create`, `Array.prototype.forEach`, or `Function.prototype.bind`. Its release cadence appears to be inactive, with no recent updates. It relies on CommonJS modules and requires a bundler like Webpack or Browserify for use in browser environments, as native ES modules were not widely supported when it was developed. This makes it less suitable for modern projects that typically use native ES modules and rely on built-in browser feature detection or more actively maintained polyfill solutions.
Verified import paths — ran on the pinned version, not inferred.
The library primarily uses CommonJS `require()` syntax as it was released in 2016. Direct ESM `import` is not supported without a CommonJS-to-ESM transpilation step.
Used for defining new capabilities. Access through the main `capability` object.
The `test` function is a method of the main `capability` object, not a named export. It can also be invoked as `capability(name)` for brevity.
Specific capability groups (like ES5 features) can be 'required' as sub-modules to automatically run their `check` functions, throwing an error if requirements are not met.
Demonstrates how to define, test, and enforce capabilities, including using the shorthand `capability()` and loading specific capability modules.
Breaking-change detection hasn't run for this library yet.
CVE tracking and dependency tree are planned for a later release.