1
0
Fork 1
mirror of https://github.com/wezm/wezm.net.git synced 2024-12-26 22:19:53 +00:00
wezm.net/output/js/mojo.js

61 lines
1.3 KiB
JavaScript
Raw Normal View History

// Mojo - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
;(function(){
Mojo = {
// --- Version
2010-09-24 08:09:39 +00:00
version: '0.3.0',
/**
* Escape HTML.
*
* @param {string} html
* @return {string}
* @api public
*/
escape : function(html) {
if (!html) return
return html.toString()
.replace(/&/gmi, '&amp;')
.replace(/"/gmi, '&quot;')
.replace(/>/gmi, '&gt;')
.replace(/</gmi, '&lt;')
},
/**
* Normalize _object_ for output.
*
* @param {object}object
* @return {mixed}
* @api public
*/
2010-09-24 08:09:39 +00:00
normalize: function(object, property) {
if(property === undefined)
return typeof object == 'function' ? object() : object
else
return typeof object[property] == 'function' ? object[property]() : object[property]
},
/**
* Enumerate _object_'s _prop_, buffering _fn_'s
* return value.
*
* @param {object} object
* @param {object} prop
* @return {string}
* @api private
*/
enumerate: function(object, prop, fn) {
if (!prop) return ''
if (!(prop instanceof Array)) return fn(object)
for (var buf = [], i = 0, len = prop.length; i < len; ++i)
buf.push(fn(prop[i]))
return buf.join(' ')
}
}
})()