sync
This commit is contained in:
1 parent
a0fe4cb7b1
commit
5cb14ffd44
11 files changed
+157
-96
No files matched your search
@@ -5,6 +5,29 @@ import { nullOrEmpty, contains, endsWith, padStart, formatUrl, escapeHtml, escap
|
||||
|
||||
const g = typeof window !== 'undefined' ? window : self;
|
||||
|
||||
/** @import { MarkRequired } from './types' */
|
||||
|
||||
/**
|
||||
* 合并参数
|
||||
* @template {object} T 可选参数类型
|
||||
* @template {Partial<T>} D 部分缺省值的选项类型
|
||||
* @param {D} defaults 默认参数
|
||||
* @param {T} opts 传入的待合并参数
|
||||
* @returns {MarkRequired<T, Extract<keyof D, keyof T>>} 返回已合并的拥有默认值的参数
|
||||
*/
|
||||
function mergeOptions(defaults, opts) {
|
||||
/** @type {Record<string, unknown>} */
|
||||
const result = { ...defaults };
|
||||
if (opts) {
|
||||
for (const [key, value] of Object.entries(opts)) {
|
||||
if (value !== undefined) {
|
||||
result[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
return /** @type {MarkRequired<T, Extract<keyof D, keyof T>>} */ (result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} n
|
||||
* @returns {n is number}
|
||||
@@ -157,6 +180,7 @@ export {
|
||||
isPositive,
|
||||
isMobile,
|
||||
// functions
|
||||
mergeOptions,
|
||||
throttle,
|
||||
debounce,
|
||||
truncate,
|
||||
|
||||
Reference in new issue
Block a user