Sha256: 56069253aebadd97c5f3a8a798fc90bed5dace59a7c16cb2f209eb50ce96f9f8

Contents?: true

Size: 1.57 KB

Versions: 26

Compression:

Stored size: 1.57 KB

Contents

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


String::toHex = ->
  return @ if @[0] == '#'
  @replace /rgb(a)?\(([0-9|%]+)[\s|,]?\s?([0-9|%]+)[\s|,]?\s?([0-9|%]+)[\s|,]?\s?([0-9|.|%]+\s?)?\)/gi, (x, alpha, r, g, b, a) ->
    "##{parseInt(r).toHex()}#{parseInt(g).toHex()}#{parseInt(b).toHex()}"


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


String::printf = ->
  chunks = @split('%')
  result = chunks[0]
  re = /^([sdf])([\s\S%]*)$/
  offset = 0
  for chunk, index in chunks
    p = re.exec(chunk)
    if index == 0 || !p || arguments[index] == null
      if index > 1
        offset += 2
        result += "%#{chunk}"
      continue
    arg = arguments[(index - 1) - offset]
    switch p[1]
      when 's' then result += arg
      when 'd', 'i' then result += parseInt(arg.toString(), 10)
      when 'f' then result += parseFloat(arg)
    result += p[2]
  return result


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"


# make setTimeout not suck for coffeescript
window.originalSetTimeout = window.setTimeout
window.setTimeout = (arg1, arg2) ->
  if typeof(arg1) == 'number' then window.originalSetTimeout(arg2, arg1) else window.originalSetTimeout(arg1, arg2)

Version data entries

26 entries across 26 versions & 3 rubygems

Version Path
kiteditor-1.0.25 vendor/assets/javascripts/mercury/native_extensions.js.coffee
kiteditor-1.0.24 vendor/assets/javascripts/mercury/native_extensions.js.coffee
kiteditor-1.0.23 vendor/assets/javascripts/mercury/native_extensions.js.coffee
kiteditor-1.0.22 vendor/assets/javascripts/mercury/native_extensions.js.coffee
kiteditor-1.0.21 vendor/assets/javascripts/mercury/native_extensions.js.coffee
kiteditor-1.0.20 vendor/assets/javascripts/mercury/native_extensions.js.coffee
kiteditor-1.0.19 vendor/assets/javascripts/mercury/native_extensions.js.coffee
kiteditor-1.0.18 vendor/assets/javascripts/mercury/native_extensions.js.coffee
kiteditor-1.0.17 vendor/assets/javascripts/mercury/native_extensions.js.coffee
kiteditor-1.0.16 vendor/assets/javascripts/mercury/native_extensions.js.coffee
kiteditor-1.0.14 vendor/assets/javascripts/mercury/native_extensions.js.coffee
kiteditor-1.0.13 vendor/assets/javascripts/mercury/native_extensions.js.coffee
kiteditor-1.0.11 vendor/assets/javascripts/mercury/native_extensions.js.coffee
kiteditor-1.0.10 vendor/assets/javascripts/mercury/native_extensions.js.coffee
kiteditor-1.0.9 vendor/assets/javascripts/mercury/native_extensions.js.coffee
kiteditor-1.0.8 vendor/assets/javascripts/mercury/native_extensions.js.coffee
kiteditor-1.0.7 vendor/assets/javascripts/mercury/native_extensions.js.coffee
kiteditor-1.0.6 vendor/assets/javascripts/mercury/native_extensions.js.coffee
kiteditor-1.0.5 vendor/assets/javascripts/mercury/native_extensions.js.coffee
kiteditor-1.0.4 vendor/assets/javascripts/mercury/native_extensions.js.coffee