vdo
Advanced tools
Comparing version 3.1.1 to 3.1.2
@@ -1,3 +0,3 @@ | ||
var gulp = require("gulp"); | ||
var mocha = require("gulp-mocha"); | ||
var gulp = require('gulp') | ||
var mocha = require('gulp-mocha') | ||
@@ -7,5 +7,6 @@ /* | ||
*/ | ||
gulp.task("test", function () { | ||
return gulp.src("test/*.js", { read: false }) | ||
.pipe(mocha()); | ||
}); | ||
gulp.task('test', function () { | ||
return gulp.src('test/*.js', { read: false }) | ||
.pipe(mocha()) | ||
.once('end', process.exit) | ||
}) |
@@ -1,9 +0,9 @@ | ||
"use strict"; | ||
'use strict' | ||
var flat = require("flatten"); | ||
var Node = require("./node"); | ||
var Safe = require("./safe"); | ||
var _context; | ||
var flat = require('flatten') | ||
var Node = require('./node') | ||
var Safe = require('./safe') | ||
var _context | ||
module.exports = vdo["default"] = vdo.createElement = vdo; | ||
module.exports = vdo['default'] = vdo.createElement = vdo | ||
@@ -27,19 +27,19 @@ /* | ||
*/ | ||
function vdo (type, attrs /*children...*/) { | ||
attrs = attrs || {}; | ||
function vdo (type, attrs /* children... */) { | ||
attrs = attrs || {} | ||
// Convert child arguments to an array. | ||
var children = new Array(Math.max(arguments.length - 2, 0)); | ||
for (var i = children.length; i--;) children[i] = arguments[i + 2]; | ||
children = flat(children); | ||
// Convert child arguments to an array. | ||
var children = new Array(Math.max(arguments.length - 2, 0)) | ||
for (var i = children.length; i--;) children[i] = arguments[i + 2] | ||
children = flat(children) | ||
switch (typeof type) { | ||
case "string": | ||
return new Node(type, attrs, children); | ||
case "function": | ||
return type(attrs, children, _context); | ||
default: | ||
throw new TypeError("VDO: Invalid virtual node type."); | ||
} | ||
}; | ||
switch (typeof type) { | ||
case 'string': | ||
return new Node(type, attrs, children) | ||
case 'function': | ||
return type(attrs, children, _context) | ||
default: | ||
throw new TypeError('VDO: Invalid virtual node type.') | ||
} | ||
} | ||
@@ -59,4 +59,4 @@ /* | ||
vdo.isElement = function (elem) { | ||
return Boolean(elem && elem.isVirtual); | ||
}; | ||
return Boolean(elem && elem.isVirtual) | ||
} | ||
@@ -69,4 +69,4 @@ /* | ||
* // Using jsx. | ||
* const html = "<span></span>"; | ||
* const node = <body>{vdo.markSafe(html)}</body>; | ||
* const html = "<span></span>" | ||
* const node = <body>{vdo.markSafe(html)}</body> | ||
* String(node) //-> "<body><span></span></body>" | ||
@@ -79,4 +79,4 @@ * ``` | ||
vdo.markSafe = function (html) { | ||
return new Safe(html); | ||
}; | ||
return new Safe(html) | ||
} | ||
@@ -94,4 +94,4 @@ /* | ||
* </body> | ||
* ); | ||
* }; | ||
* ) | ||
* } | ||
* | ||
@@ -101,4 +101,4 @@ * let html = vdo.with({ counter: 1 }, function () { | ||
* <MyCounter/> | ||
* ); | ||
* }); | ||
* ) | ||
* }) | ||
* | ||
@@ -113,9 +113,9 @@ * html; //-> "Counter: 1" | ||
*/ | ||
vdo["with"] = function (context, renderer) { | ||
if (typeof renderer !== "function") throw new TypeError("VDO: renderer should be a function."); | ||
vdo['with'] = function (context, renderer) { | ||
if (typeof renderer !== 'function') throw new TypeError('VDO: renderer should be a function.') | ||
_context = context; | ||
var node = renderer(context); | ||
_context = undefined; | ||
return node; | ||
}; | ||
_context = context | ||
var node = renderer(context) | ||
_context = undefined | ||
return node | ||
} |
100
lib/node.js
@@ -1,25 +0,25 @@ | ||
"use strict"; | ||
'use strict' | ||
var escape = require("escape-html"); | ||
var node = Node.prototype; | ||
var escape = require('escape-html') | ||
var node = Node.prototype | ||
var CLOSED = { | ||
"area": true, | ||
"base": true, | ||
"br": true, | ||
"col": true, | ||
"command": true, | ||
"embed": true, | ||
"hr": true, | ||
"img": true, | ||
"input": true, | ||
"keygen": true, | ||
"link": true, | ||
"meta": true, | ||
"param": true, | ||
"source": true, | ||
"track": true, | ||
"wbr": true | ||
}; | ||
'area': true, | ||
'base': true, | ||
'br': true, | ||
'col': true, | ||
'command': true, | ||
'embed': true, | ||
'hr': true, | ||
'img': true, | ||
'input': true, | ||
'keygen': true, | ||
'link': true, | ||
'meta': true, | ||
'param': true, | ||
'source': true, | ||
'track': true, | ||
'wbr': true | ||
} | ||
module.exports = Node; | ||
module.exports = Node | ||
@@ -37,6 +37,6 @@ /* | ||
function Node (type, attrs, children) { | ||
this.type = type; | ||
this.attrs = attrs; | ||
this.children = CLOSED[this.type] ? false : children; | ||
}; | ||
this.type = type | ||
this.attrs = attrs | ||
this.children = CLOSED[this.type] ? false : children | ||
} | ||
@@ -49,3 +49,3 @@ /* | ||
*/ | ||
node.isVirtual = true; | ||
node.isVirtual = true | ||
@@ -59,28 +59,28 @@ /* | ||
node.toString = function () { | ||
var key, attr; | ||
var attrs = ""; | ||
var children = ""; | ||
var childNodes = this.children; | ||
var key, attr | ||
var attrs = '' | ||
var children = '' | ||
var childNodes = this.children | ||
// Build attrs string. | ||
for (key in this.attrs) { | ||
attr = this.attrs[key]; | ||
if (attr == null || attr === false) continue; | ||
if (attr === true) attrs += " " + key; | ||
else attrs += " " + key + "=\"" + escape(attr) + "\""; | ||
} | ||
// Build attrs string. | ||
for (key in this.attrs) { | ||
attr = this.attrs[key] | ||
if (attr == null || attr === false) continue | ||
if (attr === true) attrs += ' ' + key | ||
else attrs += ' ' + key + '="' + escape(attr) + '"' | ||
} | ||
if (childNodes === false) { | ||
// Self closing nodes will not have children. | ||
return "<" + this.type + attrs + ">"; | ||
} else if (Array.isArray(childNodes)) { | ||
// Cast all children to strings, escaping non vdo nodes. | ||
for (var child, i = 0, len = childNodes.length; i < len; i++) { | ||
child = childNodes[i]; | ||
if (child == null || child === false) continue; | ||
children += child.isVirtual ? child : escape(child); | ||
} | ||
} | ||
if (childNodes === false) { | ||
// Self closing nodes will not have children. | ||
return '<' + this.type + attrs + '>' | ||
} else if (Array.isArray(childNodes)) { | ||
// Cast all children to strings, escaping non vdo nodes. | ||
for (var child, i = 0, len = childNodes.length; i < len; i++) { | ||
child = childNodes[i] | ||
if (child == null || child === false) continue | ||
children += child.isVirtual ? child : escape(child) | ||
} | ||
} | ||
return "<" + this.type + attrs + ">" + children + "</" + this.type + ">"; | ||
}; | ||
return '<' + this.type + attrs + '>' + children + '</' + this.type + '>' | ||
} |
@@ -1,5 +0,5 @@ | ||
"use strict"; | ||
'use strict' | ||
var safe = Safe.prototype; | ||
module.exports = Safe; | ||
var safe = Safe.prototype | ||
module.exports = Safe | ||
@@ -15,5 +15,5 @@ /* | ||
function Safe (html) { | ||
if (html != null) { | ||
this.innerHTML = String(html); | ||
} | ||
if (html != null) { | ||
this.innerHTML = String(html) | ||
} | ||
} | ||
@@ -27,3 +27,3 @@ | ||
*/ | ||
safe.isVirtual = true; | ||
safe.isVirtual = true | ||
@@ -37,3 +37,3 @@ /* | ||
safe.toString = function () { | ||
return this.innerHTML; | ||
}; | ||
return this.innerHTML | ||
} |
{ | ||
"name": "vdo", | ||
"version": "3.1.1", | ||
"description": "Minimal JSX compatible html focused templating engine.", | ||
"version": "3.1.2", | ||
"author": "Dylan Piercey <pierceydylan@gmail.com>", | ||
"main": "lib/index.js", | ||
"license": "MIT", | ||
"scripts": { | ||
"test": "gulp test" | ||
"bugs": "https://github.com/DylanPiercey/vdo/issues", | ||
"dependencies": { | ||
"escape-html": "^1.0.3", | ||
"flatten": "^1.0.2" | ||
}, | ||
"devDependencies": { | ||
"gulp": "^3.9.0", | ||
"gulp-mocha": "^2.1.3", | ||
"snazzy": "^3.0.1", | ||
"standard": "^6.0.8" | ||
}, | ||
"homepage": "https://github.com/DylanPiercey/vdo", | ||
"keywords": [ | ||
"template", | ||
"jsx", | ||
"react", | ||
"render", | ||
"string", | ||
"jsx" | ||
"template" | ||
], | ||
"license": "MIT", | ||
"main": "lib/index.js", | ||
"repository": { | ||
@@ -22,10 +31,15 @@ "type": "git", | ||
}, | ||
"devDependencies": { | ||
"gulp": "^3.9.0", | ||
"gulp-mocha": "^2.1.3" | ||
"scripts": { | ||
"test": "standard --verbose | snazzy && gulp test" | ||
}, | ||
"dependencies": { | ||
"escape-html": "^1.0.3", | ||
"flatten": "^1.0.2" | ||
"standard": { | ||
"globals": [ | ||
"describe", | ||
"it", | ||
"before", | ||
"beforeEach", | ||
"after", | ||
"afterEach" | ||
] | ||
} | ||
} |
@@ -0,1 +1,4 @@ | ||
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/) | ||
![npm](https://img.shields.io/npm/dm/vdo.svg) | ||
# VDO | ||
@@ -6,3 +9,3 @@ | ||
Check out [diffhtml](https://github.com/tbranyen/diffhtml) for React style diffing. | ||
Check out [diffhtml](https://github.com/tbranyen/diffhtml) or [morphdom](https://github.com/patrick-steele-idem/morphdom) for React style diffing. | ||
@@ -106,4 +109,4 @@ # Why | ||
* Use gulp to run tests. | ||
* Use `npm test` to run tests. | ||
Please feel free to create a PR! |
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
29142
222
0
111
4