Define Base.hyphenate, to hyphenate camelized strings.

This commit is contained in:
Jürg Lehni 2011-06-26 00:47:40 +02:00
parent d6cf11efce
commit fa29686202

View file

@ -128,6 +128,14 @@ this.Base = Base.inject(/** @lends Base# */{
});
},
hyphenate: function(str) {
return str.replace(/[a-z][A-Z0-9]|[0-9][a-zA-Z]|[A-Z]{2}[a-z]/g,
function(match) {
return match.charAt(0) + '-' + match.substring(1);
}
);
},
/**
* Utility function for rendering numbers to strings at a precision of
* up to 5 fractional digits.