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

module.exports = Sign;