sync
This commit is contained in:
1 parent
5cb14ffd44
commit
05ce7035dd
15 files changed
+946
-460
No files matched your search
+1
-23
@@ -2,32 +2,10 @@ import { getCookie, setCookie, deleteCookie } from "./utility/cookie";
|
||||
import { domLoad, init, isTag, r, lang } from "./utility/lgres";
|
||||
import { get, post, upload } from "./utility/request";
|
||||
import { nullOrEmpty, contains, endsWith, padStart, formatUrl, escapeHtml, escapeEmoji } from "./utility/strings";
|
||||
import { mergeOptions } from "./functions";
|
||||
|
||||
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}
|
||||
|
||||
Reference in new issue
Block a user