cross platform way to retrieve experimental features

npm install experimental
3 downloads in the last week
12 downloads in the last month


cross platform way to retrieve experimental features


It's quite straight forward:

  object:Object,    // generic Object to check
  property:string   // generic property to check
    assign:boolean  // optional flag to set the value
):string            // the found property or undefined

The function returns the found string, if any, or undefined.

The Difference Using The Third Argument

By default, if we check experimental(window, "requestAnimationFrame") nothing will happen to the window object and, as example in Webkit browsers, the "webkitRequestAnimationFrame" string will be returned.

If we use the third argument, not only that string is returned, but the property is attached with the desired name if not already attached before (avoids pointless getters/setters).

// check if present and use it
if (experimental(window, "requestAnimationFrame", true)) {
  // in this case attached directly to the global
  // so we can just use it all over
} else {
  setTimeout(callback, 10);

Without the third argument if there's nothing to attach since we are not looking for a method. An example could be some CSS property or an event type.

this.onload = function () {
  //* add just a slash before this line ..
  var body = document.body,
      TRANSITION = experimental(body.style, "transition"),
      TRANSITION_END = experimental(window, "transitionEnd");
      // please note it's camelCase, most likely
      // will be webkitTransitionEnd

    // property found, this could be
    // mozTransition or webkitTransition, etc
    body.style[TRANSITION] = "background-color 1s ease-out";

  // we can set this regardless
  // in the worst case scenario it will never be fired
  // however, Firefox does not behave properly
  // so "transitionend" exists but it's hard to tell
    TRANSITION_END || // webkit wants camelCase, so does opera
    function (e) {

  // later on ...
  setTimeout(function () {
    body.style.backgroundColor = "blue";
  }, 1000);

Some Generic Example

  // new stuff, if present
  experimental(window, "indexedDB"),
  experimental(window, "URL"),
  experimental(window, "performance"),
  experimental(window, "performance") &&
      experimental(window, "performance")
  // direct method
  experimental(window, "requestAnimationFrame", true),
  experimental(document, "readyStateChange"),
  experimental(window, "transitionEnd"),
  experimental(document.documentElement.style, "transition")


npm install experimental -g

Then in any JS file ...

var experimental = require('experimental').experimental;

That's pretty much it.

npm loves you