Utils

The utils service contains a set of helper methods that can be useful for creating your own modules.

Methods #

ucfirst

Arguments
str String

Returns: String

Make the first letter of the string is upper case.

(function($K)
{
    $K.add('module', 'mymodule', {
        init: function(app, context)
        {
            this.app = app;

            // define service
            this.utils = app.utils;
        },
        upString: function()
        {
           var str = this.utils.ucfirst('mystring'); // return 'Mystring'
        }
    });
})(Kube);

parseOptsString

Arguments
str String

Returns: Object

Parse the string like { color: 'red', 'font-weight': 'bold' } to object.

(function($K)
{
    $K.add('module', 'mymodule', {
        init: function(app, context)
        {
            this.app = app;

            // define service
            this.utils = app.utils;
        },
        pasreString: function()
        {
            var str = "{ color: 'red', 'font-weight': 'bold' }";
            var obj = this.utils.parseOptsString(str);
        }
    });
})(Kube);

extendData

Arguments
data String
elements StringObject

Returns: Object

Extend an object with another one or with values from the specified inputs or form data.

(function($K)
{
    $K.add('module', 'mymodule', {
        init: function(app, context)
        {
            this.app = app;

            // define service
            this.utils = app.utils;
        },
        extendFromObject: function()
        {
            var data = { name: 'my-name' };
            var extraData = { id: 10, value: 'add' };

            data = this.utils.extendData(data, extraData);
        },
        extendFromInputs: function()
        {
            var data = { name: 'my-name' };
            var extraData = '#my-input-1, #my-input-2, #my-form';

            data = this.utils.extendData(data, extraData);
        }
    });
})(Kube);

The values of the input and form fields are appended as values: inputname: value.