String.Extras

docs

MooTools extends Strings in its Native group of code. We've got a few more extensions of our own.

docs

stripTags

Removes all html tags from a string:

"<p>I\'m a <b>string</b> with a bunch of <i>tags</i></p>".stripTags();
//returns: I'm a string with a bunch of tags
execute this code

cleanQueryString

Removes from a query string any keys that have empty values.

var cleaned = "a=b&x=&z=123&e=".cleanQueryString();
//cleaned = "a=b&z=123"
execute this code

You can pass in a custom function to use instead of the default:

var noNumberValues = "a=b&x=y&z=123&e=".cleanQueryString(function(set){
    //set is "a=b", "x=y", "z=123", "e="
    return !set.split("=")[1].match(/[0-9]/);
});
//noNumberValues = "a=b&x=y&e="
execute this code

findAllEmails

Finds all the valid email addresses in a string.

"Fred's email is fred@flintstone.com and Barney's is barney@rubble.com".findAllEmails();
//returns ['fred@flintstone.com', 'barney@rubble.com']
execute this code

parseQuery

This takes a url query string and returns an object of name/value pairs to you.

"apple=red&lemon=yellow".parseQuery();
//returns: {apple: 'red', lemon:'yellow'}
execute this code

tidy

Removes MS-Word style non-ASCI characters (curly quotes, elipse, etc). See also Element.tidy.

"“‘…’”".tidy();
//returns "'...'"
execute this code

cnet-libraries/03-native/03-string.extras.txt · Last modified: 2008/11/18 00:07 by aaron-n