Created
January 22, 2015 11:29
-
-
Save jordinebot/059cd8f63a05cbe156c2 to your computer and use it in GitHub Desktop.
CoffeeScript 'contains' String prototype
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###* | |
* 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