export function buildQueryString(params) {
return Object.keys(params).map(key => {
if (Array.isArray(params[key])) {
if (!params[key].length) return '';
console.log(params[key])
return `${encodeURIComponent(key)}=` + params[key].map(value => `${encodeURIComponent(value)}`).join(',');
} else {
return `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`;
}
}).filter(Boolean).join('&');
}
export function dateFormat(date, fmt) {
if (date === null || date === undefined) {
return '';
}
if (!(date instanceof Date)) {
date = new Date(date);
}
if (isNaN(date.getTime())) {
return '';
}
const o = {
'M+': date.getMonth() + 1,
'd+': date.getDate(),
'H+': date.getHours(),
'm+': date.getMinutes(),
's+': date.getSeconds(),
'q+': Math.floor((date.getMonth() + 3) / 3),
'S': date.getMilliseconds()
};
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
}
for (const k in o) {
if (new RegExp('(' + k + ')').test(fmt)) {
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)));
}
}
return fmt;
}
export function extractNumbers(str) {
if (typeof str !== 'string') {
return [];
}
const matches = str.match(/\d+/g);
return matches ? matches.map(Number) : [];
}