JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q36825F
  • License MIT

DOM mutator for A/B experiments.

Package Exports

  • mutate-dom

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (mutate-dom) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

mutate-dom

DOM mutator for A/B experiments.

Installation

npm i --save mutate-dom

Usage example

The HTML to mutate.

<div class="user">
  <div class="name">John</div>
  <div class="ava-container">
    <img src="http://api.randomuser.me/portraits/thumb/men/39.jpg"/>
  </div>
</div>

The code that mutates the HTML.

var mu = require('mutate-dom');

function toJQuery(fn) {
  return function(selector) {
    var $el = $(selector);
    return fn($el);
  };
}

mu.addClass = function(newClass) {
  return toJQuery(function($el) {
    $el.addClass(newClass);
  });
};

mu.src = function(src) {
  return toJQuery(function($el) {
    $el.attr('src', src);
  });
};

mu({
  '.user': {
    '.name': 'Bill',
    '.ava-container': [{
        'img': mu.src('http://api.randomuser.me/portraits/thumb/men/59.jpg')
      },
      mu.addClass('awesome-ava-container')
    ]
  }
});

License

MIT