有关于URI编解码
/**
* Created by sinweng on 2018.05.24.
* author: sinweng12138@163.com
* this library created for uricomponents
* @function: w_encodeURIComponent
* @function: w_decodeURIComponent
*/
/**
* w_encodeURIComponent
* @param: json
* @param: jsonType : {
* a: *,
* b: *
*}
* @param: return String
* @param: StringType: www.xxxx.com?a=*&b=*;
*/
export function w_encodeURIComponent(json) {
if (!json) return ''
return cleanArray(Object.keys(json).map(key => {
if (json[key] === undefined) return ''
return encodeURIComponent(key) + '=' +
encodeURIComponent(json[key])
})).join('&')
}
/**
* w_decodeURIComponent
* @param: return String
* @param: StringType: www.xxxx.com?a=*&b=*;
* @param: return json
* @param: jsonType : {
* a: *,
* b: *
*}
*/
export function w_decodeURIComponent(url) {
const search = url.split('?')[1]
if (!search) {
return {}
}
return JSON.parse('{"' + decodeURIComponent(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}')
}