mozilla
Your Search Results

    Template:DekiScript:String

    <% module.exports = buildAPI({
       
        StartsWith: function (str, sub_str) {
            return (''+str).indexOf(sub_str) === 0;
        },
     
        EndsWith: function (str, suffix) {
            str = (''+str);
            return str.indexOf(suffix, str.length - suffix.length) !== -1;
        },
     
        Contains: function (str, sub_str) {
            return (''+str).indexOf(sub_str) !== -1;
        },
         
        Compare: function (first, second, ignorecase) {
            if (ignorecase) {
                first = first.toLowerCase();
                second = second.toLowerCase();
            }
            if (first < second) { return -1; }
            else if (first > second) { return 1; }
            else { return 0; }
        },
    
        // http://developer.mindtouch.com/en/docs/DekiScript/Reference/DekiScript_Functions_and_Variables/String.Deserialize
        Deserialize: function (str) {
            return JSON.parse(str);        
        },
        
        // http://developer.mindtouch.com/en/docs/DekiScript/Reference/DekiScript_Functions_and_Variables/String.IndexOf
        IndexOf: function (first, second) {
            return first.indexOf(second);        
        },
        
        /* Check if first character in string is a decimal digit. */
        IsDigit: function (str) {
            return (/^\d/.test(''+str));
        },
        
        /* Check if first character in string is an alphabetic character. */
        IsLetter: function (str) {
            return (/^[a-zA-Z]/.test(''+str));
        },
     
        // http://developer.mindtouch.com/en/docs/DekiScript/Reference/DekiScript_Functions_and_Variables/String.Serialize
        Serialize: function (val) {
            return JSON.stringify(val);
        },
    
        // http://developer.mindtouch.com/en/docs/DekiScript/Reference/DekiScript_Functions_and_Variables/String.Substr
        Substr: function (str, start, length) {
            if (length) {
                return (''+str).substr(start, length);
            } else {
                return (''+str).substr(start);
            }
        },
     
        toLower: function (str) {
            return (''+str).toLowerCase();
        },
    
        // http://developer.mindtouch.com/en/docs/DekiScript/Reference/DekiScript_Functions_and_Variables/String.ToUpperFirst
        ToUpperFirst: function (str) {
            return (''+str).charAt(0).toUpperCase() + (''+str).slice(1);
        },
         
        Trim: function (str) {
            return (''+str).trim();
        },
    
        // http://developer.mindtouch.com/en/docs/DekiScript/Reference/DekiScript_Functions_and_Variables/String.Remove
        Remove: function (str, index, count) {
            var out = ''+str.substring(0, Number(index));
            if (count) {
                out += ''+str.substring(Number(index) + Number(count));
            }
            return out;
        },
    
        Replace: function (str, from, to) {
            return (''+str).replace(RegExp(from,'g'),to);
        },
         
        Join: function (list, sep) {
            return list.join(sep);
        },
        
        Length: function (str) {
            return (''+str).length;
        }
     
    }); %>
    Search for pages that use Template:DekiScript:String to see example use cases and how many pages use this macro.

    Document Tags and Contributors

    Tags: 
    Contributors to this page: lmorchard, trevorh
    Last updated by: trevorh,