mirror of
https://github.com/wezm/wezm.net.git
synced 2024-11-14 03:18:02 +00:00
58 lines
No EOL
1.2 KiB
JavaScript
58 lines
No EOL
1.2 KiB
JavaScript
|
|
// Mojo - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
|
|
|
|
;(function(){
|
|
Mojo = {
|
|
|
|
// --- Version
|
|
|
|
version: '0.2.0',
|
|
|
|
/**
|
|
* Escape HTML.
|
|
*
|
|
* @param {string} html
|
|
* @return {string}
|
|
* @api public
|
|
*/
|
|
|
|
escape : function(html) {
|
|
if (!html) return
|
|
return html.toString()
|
|
.replace(/&/gmi, '&')
|
|
.replace(/"/gmi, '"')
|
|
.replace(/>/gmi, '>')
|
|
.replace(/</gmi, '<')
|
|
},
|
|
|
|
/**
|
|
* Normalize _object_ for output.
|
|
*
|
|
* @param {object}object
|
|
* @return {mixed}
|
|
* @api public
|
|
*/
|
|
|
|
normalize: function(object) {
|
|
return typeof object == 'function' ? object() : object
|
|
},
|
|
|
|
/**
|
|
* 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(' ')
|
|
}
|
|
}
|
|
})() |