       date.format("M/D/YY#{if time then ' h:mm A' else ''}")
 
   @label: (text, type) ->
-    type = if type then "#{type} " else ''
+    css_classes = ['label', text.replace(/\s+/g, '-'), type].compact()
 
     $('<span>')
       .text(text)
-      .prop('class', "label #{type}#{text}".toLowerCase().dasherize())
+      .prop('class', css_classes.join(' ').toLowerCase().dasherize())
 
   @icon: (types) ->
     classes = ("fa-#{type}" for type in types.split(' ')).join(' ')
 
     "<i class=\"fa #{classes}\"></i>"
+
+  @escapeHtml: (string) ->
+    return '' if string is null or string is undefined
+
+    String(string).replace /[&<>"'`=\/]/g, (s) -> Fustrate.entityMap[s]
+
+  @multilineEscapeHtml: (string) ->
+    return '' if string is null or string is undefined
+
+    String(string)
+      .split(/\r?\n/)
+      .map (line) -> Fustrate.escapeHtml(line)
+      .join '<br />'
 
 # Replicate a few common prototype methods on String and Array
 String::titleize = ->

  @VERSION: '0.4.1.1'
  @libs: {}

  constructor: ->
    lib.init() for own name, lib of @constructor.libs


Function::define = (name, methods) ->
  Object.defineProperty @::, name, methods

Function::debounce = (delay = 250) ->
  timeout = null
  self = @

  (args...) ->
    context = @

    delayedFunc = ->
      self.apply(context, args)
      timeout = null

    clearTimeout(timeout) if timeout

    timeout = setTimeout delayedFunc, delay

Object.defineProperty Object.prototype, 'tap',
  enumerable: false
  value: (func) ->
    if typeof func is 'function'
      func.apply(@)
    else
      @[func].apply(@, Array::slice.call(arguments).slice(1))

    @

Number::bytesToString = ->
  return "#{@} B" if @ < 1000

  return "#{(@ / 1000).toFixed(2).replace(/[0.]+$/, '')} kB" if @ < 1000000

  if @ < 1000000000
    return "#{(@ / 1000000).toFixed(2).replace(/[0.]+$/, '')} MB"

  "#{(@ / 1000000000).toFixed(2).replace(/[0.]+$/, '')} GB"

String::isBlank = ->
  @.trim() is ''

String::strip = ->
  @.replace(/^\s+|\s+$/g, '')

jQuery.fn.outerHTML = ->
  return '' unless @length

  return @[0].outerHTML if @[0].outerHTML

  $('<div>').append(@[0].clone()).remove().html()

moment.fn.toHumanDate = (time = false) ->
  year = if @year() isnt moment().year() then '/YY' else ''

  @format("M/D#{year}#{if time then ' h:mm A' else ''}")
