@bizjs/biz-utils
Version:
The biz utils for web develpoment.
36 lines (34 loc) • 957 B
JavaScript
import { updateUrl } from '@bizjs/biz-utils-common';
function noop() {}
export function _ensureFunction(fn) {
return typeof fn === 'function' ? fn : noop;
}
export function _openUrl(url, options) {
var finalUrl = updateUrl(url, {
query: (options === null || options === void 0 ? void 0 : options.query) || {}
});
// 模拟 a 标签点击跳转
var aEl = document.createElement('a');
aEl.href = finalUrl;
// 是否要新窗口打开
if (options !== null && options !== void 0 && options.newWindow) {
aEl.target = '_blank';
}
// 是否是下载文件
if (options !== null && options !== void 0 && options.download) {
aEl.download = options.download;
}
aEl.rel = 'noopener';
aEl.style.display = 'none';
document.body.appendChild(aEl);
aEl.click();
document.body.removeChild(aEl);
}
/**
* 是否是有效字符串
* @param str
* @returns
*/
export function _isString(str) {
return typeof str === 'string';
}