sign.js 727 Bytes
/**
 *
 * @author: jiangfeng<jeff.jiang@yoho.cn>
 * @date: 16/7/22
 */
'use strict';

const Sign = {
    raw(args) {
        let keys = Object.keys(args);

        keys = keys.filter(k => {
            return args[k] === '' || args[k] === 'undefined' ? false : true;
        }).sort();

        return keys.map(k => {
            return k + '=' + decodeURI(args[k]);
        }).join('&');
    },

    rawUncode(args) {
        let keys = Object.keys(args);

        keys = keys.filter(k => {
            return args[k] === '' || args[k] === 'undefined' ? false : true;
        }).sort();

        return keys.map(k => {
            return k.toLowerCase() + '=' + args[k];
        }).join('&');
    }
};

module.exports = Sign;