sign.js 724 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 + '=' + encodeURI(args[k]);
        }).join('&');
    }
};

module.exports = Sign;