Skip to content

Instantly share code, notes, and snippets.

@KoryNunn
Created May 16, 2017 06:12
Show Gist options
  • Save KoryNunn/1582d4524ab8c01fa42fc76e338f4036 to your computer and use it in GitHub Desktop.
Save KoryNunn/1582d4524ab8c01fa42fc76e338f4036 to your computer and use it in GitHub Desktop.
requirebin sketch
var crel = require('crel');
crel(document.body,
crel('div',
crel('h1', 'hello')
)
);
setTimeout(function(){require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({crel:[function(require,module,exports){(function(root,factory){if(typeof exports==="object"){module.exports=factory()}else if(typeof define==="function"&&define.amd){define(factory)}else{root.crel=factory()}})(this,function(){var fn="function",obj="object",nodeType="nodeType",textContent="textContent",setAttribute="setAttribute",attrMapString="attrMap",isNodeString="isNode",isElementString="isElement",d=typeof document===obj?document:{},isType=function(a,type){return typeof a===type},isNode=typeof Node===fn?function(object){return object instanceof Node}:function(object){return object&&isType(object,obj)&&nodeType in object&&isType(object.ownerDocument,obj)},isElement=function(object){return crel[isNodeString](object)&&object[nodeType]===1},isArray=function(a){return a instanceof Array},appendChild=function(element,child){if(!crel[isNodeString](child)){child=d.createTextNode(child)}element.appendChild(child)};function crel(){var args=arguments,element=args[0],child,settings=args[1],childIndex=2,argumentsLength=args.length,attributeMap=crel[attrMapString];element=crel[isElementString](element)?element:d.createElement(element);if(argumentsLength===1){return element}if(!isType(settings,obj)||crel[isNodeString](settings)||isArray(settings)){--childIndex;settings=null}if(argumentsLength-childIndex===1&&isType(args[childIndex],"string")&&element[textContent]!==undefined){element[textContent]=args[childIndex]}else{for(;childIndex<argumentsLength;++childIndex){child=args[childIndex];if(child==null){continue}if(isArray(child)){for(var i=0;i<child.length;++i){appendChild(element,child[i])}}else{appendChild(element,child)}}}for(var key in settings){if(!attributeMap[key]){element[setAttribute](key,settings[key])}else{var attr=attributeMap[key];if(typeof attr===fn){attr(element,settings[key])}else{element[setAttribute](attr,settings[key])}}}return element}crel[attrMapString]={};crel[isElementString]=isElement;crel[isNodeString]=isNode;if(typeof Proxy!=="undefined"){crel.proxy=new Proxy(crel,{get:function(target,key){!(key in crel)&&(crel[key]=crel.bind(null,key));return crel[key]}})}return crel})},{}]},{},[]);var crel=require("crel");crel(document.body,crel("div",crel("h1","hello")))},0);
{
"name": "requirebin-sketch",
"version": "1.0.0",
"dependencies": {
"crel": "3.0.0"
}
}
<!-- contents of this file will be placed inside the <body> -->
<!-- contents of this file will be placed inside the <head> -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment