Skip to content

Instantly share code, notes, and snippets.

@jordinebot
Created January 22, 2015 11:29
Show Gist options
  • Save jordinebot/059cd8f63a05cbe156c2 to your computer and use it in GitHub Desktop.
Save jordinebot/059cd8f63a05cbe156c2 to your computer and use it in GitHub Desktop.
CoffeeScript 'contains' String prototype
###*
* String prototype to check the presence of a substring
* @param {String} needle to look for
* @return {Bool} Presence of needle in String
###
if typeof String::contains isnt 'function'
String::contains = (needle) ->
(@.match new RegExp needle.replace(/[-[\](){}*+?.,\\^$|#\s]/g, "\\$&"))?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment