Sha256: edc5ee89234ca00cccf1f501954a3d77035db29600a53434df38175f1dfc00aa
Contents?: true
Size: 1.33 KB
Versions: 6
Compression:
Stored size: 1.33 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"
Version data entries
6 entries across 6 versions & 2 rubygems