Alien-Web-ExtJS-V3

 view release on metacpan or  search on metacpan

share/docs/source/Format.html  view on Meta::CPAN


    return {
<span id='Ext-util-Format-method-ellipsis'>        /**
</span>         * Truncate a string and add an ellipsis ('...') to the end if it exceeds the specified length
         * @param {String} value The string to truncate
         * @param {Number} length The maximum length to allow before truncating
         * @param {Boolean} word True to try to find a common work break
         * @return {String} The converted text
         */
        ellipsis : function(value, len, word) {
            if (value &amp;&amp; value.length &gt; len) {
                if (word) {
                    var vs    = value.substr(0, len - 2),
                        index = Math.max(vs.lastIndexOf(' '), vs.lastIndexOf('.'), vs.lastIndexOf('!'), vs.lastIndexOf('?'));
                    if (index == -1 || index &lt; (len - 15)) {
                        return value.substr(0, len - 3) + &quot;...&quot;;
                    } else {
                        return vs.substr(0, index) + &quot;...&quot;;
                    }
                } else {
                    return value.substr(0, len - 3) + &quot;...&quot;;
                }
            }
            return value;
        },

<span id='Ext-util-Format-method-undef'>        /**
</span>         * Checks a reference and converts it to empty string if it is undefined
         * @param {Mixed} value Reference to check
         * @return {Mixed} Empty string if converted, otherwise the original value
         */
        undef : function(value) {
            return value !== undefined ? value : &quot;&quot;;
        },

<span id='Ext-util-Format-method-defaultValue'>        /**
</span>         * Checks a reference and converts it to the default value if it's empty
         * @param {Mixed} value Reference to check
         * @param {String} defaultValue The value to insert if it's undefined (defaults to &quot;&quot;)
         * @return {String}
         */
        defaultValue : function(value, defaultValue) {
            if (!defaultValue &amp;&amp; defaultValue !== 0) {
                defaultValue = '';
            }
            return value !== undefined &amp;&amp; value !== '' ? value : defaultValue;
        },

<span id='Ext-util-Format-method-htmlEncode'>        /**
</span>         * Convert certain characters (&amp;, &lt;, &gt;, and ') to their HTML character equivalents for literal display in web pages.
         * @param {String} value The string to encode
         * @return {String} The encoded text
         */
        htmlEncode : function(value) {
            return !value ? value : String(value).replace(/&amp;/g, &quot;&amp;amp;&quot;).replace(/&gt;/g, &quot;&amp;gt;&quot;).replace(/&lt;/g, &quot;&amp;lt;&quot;).replace(/&quot;/g, &quot;&amp;quot;&quot;);
        },

<span id='Ext-util-Format-method-htmlDecode'>        /**
</span>         * Convert certain characters (&amp;, &lt;, &gt;, and ') from their HTML character equivalents.
         * @param {String} value The string to decode
         * @return {String} The decoded text
         */
        htmlDecode : function(value) {
            return !value ? value : String(value).replace(/&amp;gt;/g, &quot;&gt;&quot;).replace(/&amp;lt;/g, &quot;&lt;&quot;).replace(/&amp;quot;/g, '&quot;').replace(/&amp;amp;/g, &quot;&amp;&quot;);
        },

<span id='Ext-util-Format-method-trim'>        /**
</span>         * Trims any whitespace from either side of a string
         * @param {String} value The text to trim
         * @return {String} The trimmed text
         */
        trim : function(value) {
            return String(value).replace(trimRe, &quot;&quot;);
        },

<span id='Ext-util-Format-method-substr'>        /**
</span>         * Returns a substring from within an original string
         * @param {String} value The original text
         * @param {Number} start The start index of the substring
         * @param {Number} length The length of the substring
         * @return {String} The substring
         */
        substr : function(value, start, length) {
            return String(value).substr(start, length);
        },

<span id='Ext-util-Format-method-lowercase'>        /**
</span>         * Converts a string to all lower case letters
         * @param {String} value The text to convert
         * @return {String} The converted text
         */
        lowercase : function(value) {
            return String(value).toLowerCase();
        },

<span id='Ext-util-Format-method-uppercase'>        /**
</span>         * Converts a string to all upper case letters
         * @param {String} value The text to convert
         * @return {String} The converted text
         */
        uppercase : function(value) {
            return String(value).toUpperCase();
        },

<span id='Ext-util-Format-method-capitalize'>        /**
</span>         * Converts the first character only of a string to upper case
         * @param {String} value The text to convert
         * @return {String} The converted text
         */
        capitalize : function(value) {
            return !value ? value : value.charAt(0).toUpperCase() + value.substr(1).toLowerCase();
        },

        // private
        call : function(value, fn) {
            if (arguments.length &gt; 2) {
                var args = Array.prototype.slice.call(arguments, 2);
                args.unshift(value);
                return eval(fn).apply(window, args);
            } else {
                return eval(fn).call(window, value);



( run in 0.922 second using v1.01-cache-2.11-cpan-3d66aa2751a )