Comparing version 1.1.2 to 2.0.0
31
crel.js
@@ -47,17 +47,14 @@ //Copyright (C) 2012 Kory Nunn | ||
// based on http://stackoverflow.com/questions/384286/javascript-isdom-how-do-you-check-if-a-javascript-object-is-a-dom-object | ||
var isNode = typeof Node === 'function' | ||
? function (object) { return object instanceof Node; } | ||
: function (object) { | ||
return object | ||
&& typeof object === 'object' | ||
&& typeof object.nodeType === 'number' | ||
&& typeof object.nodeName === 'string'; | ||
var isElement = function (object) { | ||
return object instanceof Element; | ||
}, | ||
isArray = function(a){ | ||
return a instanceof Array; | ||
}, | ||
appendChild = function(element, child) { | ||
if(!isElement(child)){ | ||
child = document.createTextNode(child); | ||
} | ||
element.appendChild(child); | ||
}; | ||
var isArray = function(a){ return a instanceof Array; }; | ||
var appendChild = function(element, child) { | ||
if(!isNode(child)){ | ||
child = document.createTextNode(child); | ||
} | ||
element.appendChild(child); | ||
}; | ||
@@ -75,3 +72,3 @@ | ||
element = isNode(element) ? element : document.createElement(element); | ||
element = isElement(element) ? element : document.createElement(element); | ||
// shortcut | ||
@@ -82,3 +79,3 @@ if(argumentsLength === 1){ | ||
if(typeof settings !== 'object' || isNode(settings) || isArray(settings)) { | ||
if(typeof settings !== 'object' || isElement(settings) || isArray(settings)) { | ||
--childIndex; | ||
@@ -130,5 +127,5 @@ settings = null; | ||
// String referenced so that compilers maintain the property name. | ||
crel["isNode"] = isNode; | ||
crel["isElement"] = isElement; | ||
return crel; | ||
})); |
@@ -1,2 +0,2 @@ | ||
(function(f,d){"object"===typeof exports?module.exports=d():"function"===typeof define&&define.amd?define(d):f.crel=d()})(this,function(){function f(){var a=window.document,c=arguments,b=c[0],e=c[1],g=2,m=c.length,n=f.attrMap,b=d(b)?b:a.createElement(b);if(1===m)return b;if("object"!==typeof e||d(e)||e instanceof Array)--g,e=null;if(1===m-g&&"string"===typeof c[g]&&void 0!==b.textContent)b.textContent=c[g];else for(;g<m;++g)if(a=c[g],null!=a)if(a instanceof Array)for(var k=0;k<a.length;++k){var p= | ||
b,l=a[k];d(l)||(l=document.createTextNode(l));p.appendChild(l)}else k=b,d(a)||(a=document.createTextNode(a)),k.appendChild(a);for(var h in e)n[h]?(c=f.attrMap[h],"function"===typeof c?c(b,e[h]):b.setAttribute(c,e[h])):b.setAttribute(h,e[h]);return b}var d="function"===typeof Node?function(a){return a instanceof Node}:function(a){return a&&"object"===typeof a&&"number"===typeof a.nodeType&&"string"===typeof a.nodeName};f.attrMap={};f.isNode=d;return f}); | ||
(function(f,d){"object"===typeof exports?module.exports=d():"function"===typeof define&&define.amd?define(d):f.crel=d()})(this,function(){function f(){var b=window.document,c=arguments,a=c[0],e=c[1],g=2,m=c.length,n=f.attrMap,a=d(a)?a:b.createElement(a);if(1===m)return a;if("object"!==typeof e||d(e)||e instanceof Array)--g,e=null;if(1===m-g&&"string"===typeof c[g]&&void 0!==a.textContent)a.textContent=c[g];else for(;g<m;++g)if(b=c[g],null!=b)if(b instanceof Array)for(var k=0;k<b.length;++k){var p= | ||
a,l=b[k];d(l)||(l=document.createTextNode(l));p.appendChild(l)}else k=a,d(b)||(b=document.createTextNode(b)),k.appendChild(b);for(var h in e)n[h]?(c=f.attrMap[h],"function"===typeof c?c(a,e[h]):a.setAttribute(c,e[h])):a.setAttribute(h,e[h]);return a}var d=function(b){return b instanceof Element};f.attrMap={};f.isElement=d;return f}); |
@@ -8,3 +8,3 @@ { | ||
], | ||
"version": "1.1.2", | ||
"version": "2.0.0", | ||
"main": "crel.js", | ||
@@ -15,2 +15,5 @@ "dependencies": {}, | ||
}, | ||
"scripts": { | ||
"build": "browserify test/index.js > test/index.browser.js" | ||
}, | ||
"repository": { | ||
@@ -17,0 +20,0 @@ "type": "git", |
@@ -1,4 +0,6 @@ | ||
crel | ||
==== | ||
# crel | ||
![logo](logo.png) | ||
# What # | ||
@@ -27,5 +29,5 @@ | ||
npm i crel | ||
var crel = require('crel'); | ||
For standard script tag style: | ||
@@ -39,35 +41,45 @@ | ||
var element = crel('div', | ||
crel('h1', 'Crello World!'), | ||
crel('p', 'This is crel'), | ||
crel('input', {type: 'number'}) | ||
) | ||
// Do something with 'element' | ||
```javascript | ||
var element = crel('div', | ||
crel('h1', 'Crello World!'), | ||
crel('p', 'This is crel'), | ||
crel('input', {type: 'number'}) | ||
); | ||
// Do something with 'element' | ||
``` | ||
You can create attributes with dashes, or reserved keywords, but using strings for the objects keys: | ||
crel('div', {'class':'thing', 'data-attrubute':'majigger'}); | ||
```javascript | ||
crel('div', {'class':'thing', 'data-attrubute':'majigger'}); | ||
``` | ||
You can pass an already available element to crel, and it will be the target of the attributes/child elements | ||
crel(document.body, | ||
crel('h1', 'Page title') | ||
) | ||
```javascript | ||
crel(document.body, | ||
crel('h1', 'Page title') | ||
) | ||
``` | ||
You can assign child elements to variables during creation: | ||
var button, | ||
wrapper = crel('div', | ||
button = crel('button') | ||
); | ||
```javascript | ||
var button, | ||
wrapper = crel('div', | ||
button = crel('button') | ||
); | ||
``` | ||
You could probably use crel to rearrange existing dom.. | ||
crel(someDiv, | ||
crel(someOtherDiv, anotherOne) | ||
) | ||
```javascript | ||
crel(someDiv, | ||
crel(someOtherDiv, anotherOne) | ||
) | ||
``` | ||
But don't. | ||
# Goals # | ||
@@ -78,3 +90,4 @@ | ||
## Tiny ## | ||
(easily less than 1K minified) | ||
easily less than 1K minified | ||
easily less than 500 bytes gzipped | ||
## Fast ## | ||
@@ -81,0 +94,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
0
165
99
18265