mithril-node-render
Advanced tools
Comparing version 0.1.8 to 0.2.0
29
index.js
@@ -15,2 +15,13 @@ 'use strict'; | ||
// shameless stolen from https://github.com/punkave/sanitize-html | ||
function escapeHtml(s) { | ||
if (s === 'undefined') { | ||
s = ''; | ||
} | ||
if (typeof(s) !== 'string') { | ||
s = s + ''; | ||
} | ||
return s.replace(/\&/g, '&').replace(/</g, '<').replace(/\>/g, '>').replace(/\"/g, '"'); | ||
} | ||
function createAttrString(attrs) { | ||
@@ -41,11 +52,2 @@ if (!attrs || !Object.keys(attrs).length) { | ||
function createTrustedContent(view) { | ||
return Object.keys(view).map(function(key) { | ||
if (key === '$trusted') { | ||
return ''; | ||
} | ||
return view[key]; | ||
}).join(''); | ||
} | ||
function createChildrenContent(view) { | ||
@@ -61,3 +63,8 @@ if(isArray(view.children) && !view.children.length) { | ||
var type = typeof view; | ||
if (type === 'string' || type === 'number' || type === 'boolean') { | ||
if (type === 'string') { | ||
return escapeHtml(view); | ||
} | ||
if(type === 'number' || type === 'boolean') { | ||
return view; | ||
@@ -75,3 +82,3 @@ } | ||
if (view.$trusted) { | ||
return createTrustedContent(view); | ||
return '' + view; | ||
} | ||
@@ -78,0 +85,0 @@ var children = createChildrenContent(view); |
{ | ||
"name": "mithril-node-render", | ||
"version": "0.1.8", | ||
"version": "0.2.0", | ||
"description": "Node rending of mithril views", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -21,2 +21,3 @@ mithril-node-render | ||
[Blog post](https://gist.github.com/StephanHoyer/bddccd9e159828867d2a) about isomorphic mithril applications. | ||
* [Blog post](https://gist.github.com/StephanHoyer/bddccd9e159828867d2a) about isomorphic mithril applications | ||
* [Usage Example](https://github.com/StephanHoyer/mithril-isomorphic-example/blob/master/README.md) |
@@ -41,3 +41,5 @@ 'use strict'; | ||
t.equal(render(m('div', { a: false})), '<div></div>'); | ||
t.equal(render(m('div', m.trust('<foo></foo>'))), '<div><foo></foo></div>'); | ||
t.equal(render(m('div', '<foo></foo>')), '<div><foo></foo></div>'); | ||
t.end(); | ||
}); |
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
6613
119
23