Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Jonas Raoni Soares Silva http://www.jsfromhell.com

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

toStandard //JavaScript Function

This function tries to parse bad html and transform into xhtml, by lower-casing the tags, properties and duplicating single properties (readonly becomes readonly="readonly"), my function is very generic.

example:
s = '<INPUT type=text value="a b c" readonly x="123">blabla<DIV></DIV>';
prompt("", toStandard(s));


code:
//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com

function toStandard(s){
	return s.replace(/<(\/?\w+)([^>]*)>/g, function(s, t, c, d){
		return "<" + t.toLowerCase() + c.replace(/\b(\w+)(?:=((?:(?=(["'])).((?!\3)(?:.|\n))*\3)|\S*))?/g, function(s, p, v, a){
			return (p = p.toLowerCase()) + "=" + (a = a ? "" : '"') + (v || p) + a;
		}) + ">";
	});
};

Generic base conversor //Javascript Object


Minimum Common Multiple

[UPDATED CODE AND HELP CAN BE FOUND HERE]


//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com/number/base-conversor [v1.0]

Conversor = {
	h: '0123456789abcdefghijklmnopqrstuvwxyz',

	int2base: function( n, base ){
		if( base < 2 || base > this.h.length )
			throw new Error( "base inválida" );
		for( var n = parseInt( n ) || 0, result = ""; n; result = this.h.charAt( n % base ) + result, n = Math.floor( n / base ) );
		return result;
	},
	base2int: function( s, base ){
		for( var i = -1, l = s.length, result = 0; ++i < l; result = result * base + this.h.indexOf( s.charAt( i ) ) );
		return result;
	}
}
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS