Sha256: 8a12dd7532918cd9cc26edfdb883501a776c0a23e62c6e92e1dc4ae9a1ec9d27

Contents?: true

Size: 1.08 KB

Versions: 9

Compression:

Stored size: 1.08 KB

Contents

Lanes.lib.objToParam = (a) ->
    add = (s, k, v) ->
        v = if _.isFunction(v)
            v()
        else if v == null or v == undefined
            ''
        else
            v
        s[s.length] = k + '=' + encodeURIComponent(v)
        return

    buildParams = (prefix, obj, s) ->
        i = undefined
        len = undefined
        key = undefined
        if _.isArray(obj)
            i = 0
            len = obj.length
            while i < len
                val = (if _.isObject(obj[i]) then i else '')
                buildParams "#{prefix}[#{val}]", obj[i], s
                i++
        else if obj and _.isObject(obj)
            for key, value of obj
                if obj.hasOwnProperty(key)
                    if prefix
                        buildParams "#{prefix}[#{key}]", value, s, add
                    else
                        buildParams key, value, s, add
        else if prefix
            add s, prefix, obj
        else
            for key, value of obj
                add(s, key, value)
        s

    buildParams('', a, []).join('&').replace /%20/g, '+'

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
lanes-0.7.0 client/lanes/lib/objToParam.coffee
lanes-0.6.1 client/lanes/lib/objToParam.coffee
lanes-0.6.0 client/lanes/lib/objToParam.coffee
lanes-0.5.6 client/lanes/lib/objToParam.coffee
lanes-0.5.5 client/lanes/lib/objToParam.coffee
lanes-0.5.0 client/lanes/lib/objToParam.coffee
lanes-0.4.0 client/lanes/lib/objToParam.coffee
lanes-0.3.0 client/lanes/lib/objToParam.coffee
lanes-0.1.9.5 client/lanes/lib/objToParam.coffee