Skip to content

Instantly share code, notes, and snippets.

@zackdever
Created September 18, 2012 07:54
Show Gist options
  • Save zackdever/3741880 to your computer and use it in GitHub Desktop.
Save zackdever/3741880 to your computer and use it in GitHub Desktop.
small collection of string/object coffeescript utilities
String::endswith = (str) -> @match new RegExp "#{str}$"
String::startswith = (str) -> @match new RegExp "^#{str}"
String::splitLines = () -> @split /\r\n|\r|\n/
# not unlike jQuery.extend.
# adds new properties in object to target.
# does not override anything any target properties.
# TODO: test!
exports.extend = (target, object) ->
for key, val of object
target[key] ?= object[key]
exports.objectKeySize = (obj) ->
size = 0
size++ for key of obj when obj.hasOwnProperty key
size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment