JSFiddle - React, Tailwind, and code Playground

by Gwyn Milcote

HTML

js test.

JavaScript

var u = function (parameter, context){
  if(!(this instanceof u)){
    return new u(parameter, context);
  }

  if(parameter instanceof u){
    return parameter;
  }

  if (typeof parameter === 'string') {
    parameter = this.select(parameter, context);
  }

  if (parameter && parameter.nodeName) {
    parameter = [parameter];
  }

  this.nodes = this.slice(parameter);
};

u.prototype = {
  get length () {
    return this.nodes.length;
  }
};

u.prototype.nodes = [];


u.prototype.addClass = function () {
  return this.eacharg(arguments, function (el, name) {
    el.classList.add(name);
  });
};




// [INTERNAL USE ONLY]
u.prototype.adjacent = function (html, data, callback) {
  if (typeof data === 'number') {
    if (data === 0) {
      data = [];
    } else {
      data = new Array(data).join().split(',').map(Number.call, Number);
    }
  }

  return this.each(function (node, j){
    var fragment = document.createDocumentFragment();

    // Allow for data to be falsy and still loop once
    u(data || {}).map(function (el, i) {
      // Allow for callbacks that accept some data
      var part = (typeof html === 'function') ? html.call(this, el, i, node, j) : html;

      if (typeof part === 'string') {
        return this.generate(part);
      }

      return u(part);
    }).each(function (n) {
      this.isInPage(n)
        ? fragment.appendChild(u(n).clone().first())
        : fragment.appendChild(n);
    });

    callback.call(this, node, fragment);
  });
};

// Add some html as a sibling after each of the matched elements.
u.prototype.after = function (html, data) {
  return this.adjacent(html, data, function (node, fragment) {
    node.parentNode.insertBefore(fragment, node.nextSibling);
  });
};


// Add some html as a child at the end of each of the matched elements.
u.prototype.append = function (html, data) {
  return this.adjacent(html, data, function (node, fragment) {
    node.appendChild(fragment);
  });
};


// [INTERNAL USE ONLY]

// Normalize...