Registry / http-networking / capability

capability

JSON →
library0.2.5jsnpmunverified

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.

npm install capability
INSTALL
IMPORT
SIG · CAPABILITY
C
capability
http-networkingjavascriptv0.2.5
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

capability
const capability = require('capability');
import capability from 'capability';
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.
capability.define
const capability = require('capability'); capability.define('myFeature', () => /* test logic */);
Used for defining new capabilities. Access through the main `capability` object.
capability.test
const capability = require('capability'); const isSupported = capability.test('Object.create');
import { test } from 'capability';
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.
es5
require('capability/es5');
import { es5 } from 'capability';
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.

const capability = require('capability'); // Define a custom capability capability.define('XMLHttpRequest', function () { return typeof XMLHttpRequest !== 'undefined'; }); // Test if a capability is supported const hasObjectCreate = capability.test('Object.create'); console.log(`Object.create is supported: ${hasObjectCreate}`); const hasCustomFeature = capability('XMLHttpRequest'); // Shorthand for capability.test console.log(`XMLHttpRequest is supported: ${hasCustomFeature}`); // Enforce a capability (will throw an error if not supported) try { capability.check('Array.prototype.forEach'); console.log('Array.prototype.forEach is available.'); } catch (error) { console.error(`Error: ${error.message}`); } // Load a specific capability group to enforce its requirements try { require('capability/es5'); // This will run checks for all ES5 capabilities defined in the library console.log('Environment meets ES5 requirements (via /es5 module).'); } catch (error) { console.error(`Error loading ES5 capabilities: ${error.message}`); }
Debug
Known issues
gotchaThis library was last updated in 2016 and is likely unmaintained. Use in new projects is not recommended, and direct feature detection or actively maintained polyfill libraries are generally preferred for modern web development.
fix
Consider using native browser APIs for feature detection (e.g., `if (typeof window.fetch === 'function')`), or a modern polyfill solution combined with a bundler.
affects: >=0.1.0
breakingThe library primarily uses CommonJS `require()` syntax. Attempting to use ES module `import` syntax directly will fail in most environments without a build step that handles CommonJS modules.
fix
Ensure your project uses CommonJS `require()` for this package, or configure your build tool (e.g., Webpack, Rollup, Parcel) to correctly bundle CommonJS modules.
affects: >=0.1.0
gotchaFor browser usage, the library explicitly states it requires a 'node module loader' like Browserify or Webpack. It is not designed for direct inclusion via `<script>` tags without a bundling step.
fix
Integrate the package into a JavaScript bundling workflow (e.g., Webpack, Rollup) to ensure it's correctly loaded in a browser environment.
affects: >=0.1.0
Errors
Common errors & fixes
Error: Cannot find module 'capability'
Attempting to `import` 'capability' in a CommonJS-only Node.js environment or without proper bundler configuration for CommonJS modules.
fix
Use `const capability = require('capability');` instead of `import capability from 'capability';` or ensure your build tool correctly processes CommonJS modules for browser/ESM environments.
TypeError: capability.test is not a function
Incorrectly importing the `capability` object, such as attempting a named import `import { test } from 'capability'` when `test` is a method of the default export.
fix
Ensure you are importing the entire module as a default object: `const capability = require('capability');` and then calling `capability.test('feature');`.
Upgrade
Version history
0.2.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
10
Amazon
1
OpenAI (training)
1
Resources
capability — npm install capability · libregistry