• Jump To … +
    breakpoints.js date-parse.js jquery.breakpoints.js jquery.calcRestrainedPos.js jquery.clientRect.js jquery.contentSize.js jquery.cookies.js jquery.css.js jquery.customEvent.js jquery.delimitedString.js jquery.disableEvent.js jquery.hostIframe.js jquery.hoverDelay.js jquery.htmlEncode.js jquery.imageSize.js jquery.isVisibleKeyCode.js jquery.menu.js jquery-menu-exampleskin.js jquery.modalDialog.deviceFixes.js jquery.modalDialog.getSettings.js jquery.modalDialog.header.js jquery.modalDialog.history.js jquery.modalDialog.js jquery.modalDialog.unobtrusive.js jquery.modalDialog.userAgent.js jquery.modalDialogContent.header.js jquery.modalDialogContent.js jquery.msAjax.js jquery.ns.js jquery.partialLoad.js jquery.postMessage.js jquery.proxyAll.js jquery.queryString.js jquery.richTooltip.js jquery.scrollAnchor.js jquery.uncomment.js jquery.url.js pointy.gestures.js pointy.js
  • jquery.delimitedString.js

  • ¶
    (function ($) {
  • ¶

    Takes a plain javascript object (key value pairs), and encodes it as a string using the specified delimiters and encoders

        $.encodeDelimitedString = function (data, itemDelimiter, pairDelimiter, keyEncoder, valueEncoder) {
            if (!data) {
                return "";
            }
    
            keyEncoder = keyEncoder || function (s) {
                return s;
            };
            valueEncoder = valueEncoder || keyEncoder;
    
            var sb = [];
    
            for (var key in data) {
                if (data.hasOwnProperty(key)) {
                    sb.push(keyEncoder(key) + pairDelimiter + valueEncoder(data[key]));
                }
            }
    
            return sb.join(itemDelimiter);
        };
  • ¶

    Takes an encoded string, and parses it into a plain javascript object (key value pairs) using the specified delimiters and decoders

        $.parseDelimitedString = function (delimitedString, itemDelimiter, pairDelimiter, keyDecoder, valueDecoder) {
            keyDecoder = keyDecoder || function (s) {
                return s;
            };
            valueDecoder = valueDecoder || keyDecoder;
    
            var ret = {};
    
            if (delimitedString) {
                var pairs = delimitedString.split(itemDelimiter);
                var len = pairs.length;
                for (var i = 0; i < len; i++) {
                    var pair = pairs[i];
    
                    if (pair.length > 0) {
                        var delimIndex = pair.indexOf(pairDelimiter);
                        var key, value;
    
                        if (delimIndex > 0 && delimIndex <= pair.length - 1) {
                            key = pair.substring(0, delimIndex);
                            value = pair.substring(delimIndex + 1);
                        } else {
                            key = pair;
                        }
    
                        ret[keyDecoder(key)] = valueDecoder(value);
                    }
                }
            }
    
            return ret;
        };
    
    })(jQuery);