My current Sencha utilities (ExtJS and Touch)

As a quick note today, here are my current Sencha utilities (most of them being string utilities):

Ext.define('VP.util.Utils', {

    statics : {

        // 'dump' all object details to the console for debugging
        dumpObject: function(obj) {
            var output, property;
            for (property in obj) {
                output += property + ': ' + obj[property] + '; ';
            }
            console.log(output);
        },

        // returns a string with each 'word' in the string capitalized
        capitalizeEachWord: function(str) {
            return str.replace(/\w\S*/g, function(txt) {
                return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
            });
        },

        // returns a string with all blank spaces removed
        removeSpaces: function(str) {
            return str.replace(/ /g, '');
        },

        // removes any character not in [a-zA-Z_0-9]
        stripNonWordCharacters: function(str) {
            return str.replace(/\W/g, '_');
        }

    }
});

Here’s a quick description of each function:

  • dumpObject does what it says, dumping each JavaScript object to the console
  • capitalizeEachWord does what it says
  • removeSpaces removes all blank spaces from a string
  • stripNonWordCharacters removes any character not in the regex [a-zA-Z_0-9]

I’m sure these utilities will grow over time, but that’s where they are today.