Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

feature-detect

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

feature-detect

Feature detection library for node environments.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Feature detection

This library is meant to provide feature detection support for Node.js or Io.js compatible environments. It is not intended to provide feature detection support in browser environments, for which there already are numerous alternatives.

Usage

npm install --save feature-detect

To detect features at install time, put an install script similar to the following in package.json:

{ scripts:
  { "install": "feature-detect generators" }
}

In the example above, the feature-detect executable will load the module generators. The module is expected to export a list of tests, like so:

exports.feature = 'Generators'

exports.tests =
[ 'generator syntax'
  , function() {
      return function *() { yield true }
    }
  ]
]

When running npm install in an environment that supports generators, nothing will happen, but if generators aren't supported, the installation will fail and you should see output like the following:

WeakMap is not supported in this environment
├ ✘ basic functionality WeakMap is not defined
├ ✘ constructor arguments WeakMap is not defined
├ ✘ WeakMap.prototype.set returns this WeakMap is not defined
├ ✘ WeakMap.prototype.delete WeakMap is not defined
└ ✘ Support frozen objects as keys WeakMap is not defined

Runtime detection

While installation time detection is recommended, it is possible to do runtime detection:

var detect = require('feature-detect')

var result = detect(
  { feature: 'WeakMap'
  , tests:
    [ [ 'basic functionality', function() {
        var key = {};
        var weakmap = new WeakMap();
        weakmap.set(key, 123);
        return weakmap.has(key) && weakmap.get(key) === 123;
      } ]
    ]
  }
)

result.success? console.log('WeakMap supported!') : console.error('No WeakMap!')

License: MIT

Keywords

FAQs

Package last updated on 07 Feb 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc