Sha256: 6f4703e0eecc004f517f77c207ae989fe84a66e6e69eebd9fc585553e4b79be9

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

String::titleize = ->
  @[0].toUpperCase() + @slice(1)


String::toHex = ->
  # todo: we should handle alpha as well
  return @ if @[0] == '#'
  @replace /rgba?\((\d+)[\s|\,]?\s(\d+)[\s|\,]?\s(\d+)\)/gi, (a, r, g, b) ->
    "##{parseInt(r).toHex()}#{parseInt(g).toHex()}#{parseInt(b).toHex()}"


String::singleDiff = (that) ->
  diff = ''
  for char, index in that
    if char != @[index]
      re = new RegExp(@substr(index).regExpEscape().replace(/^\s+|^( )+/g, '') + '$', 'm')
      diff = that.substr(index).replace(re, '')
      break
  return diff


String::regExpEscape = ->
  specials = ['/','.','*','+','?','|','(',')','[',']','{','}','\\']
  escaped = new RegExp('(\\' + specials.join('|\\') + ')', 'g')
  return @replace(escaped, '\\$1')


String::sanitizeHTML = ->
  element = $('<div>').html(@.toString())
  element.find('style').remove()
  content = element.text()
  content = content.replace(/\n+/g, '<br/>').replace(/.*<!--.*-->/g, '').replace(/^(<br\/>)+|(<br\/>\s*)+$/g, '')
  return content


Number::toHex = ->
  result = @toString(16).toUpperCase()
  return if result[1] then result else "0#{result}"


Number::toBytes = ->
  bytes = parseInt(@)
  i = 0
  while 1023 < bytes
    bytes /= 1024
    i += 1
  return if i then "#{bytes.toFixed(2)}#{['', ' kb', ' Mb', ' Gb', ' Tb', ' Pb', ' Eb'][i]}" else "#{bytes} bytes"

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mercury-rails-0.1.1 app/assets/javascripts/mercury/native_extensions.js.coffee
mercury-rails-0.1.0 app/assets/javascripts/mercury/native_extensions.js.coffee