minutool 1.0.14 → 1.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +41 -13
- package/dist/minutool.js +547 -509
- package/dist/minutool.js.map +1 -1
- package/dist/minutool.umd.cjs +5 -5
- package/dist/minutool.umd.cjs.map +1 -1
- package/package.json +58 -59
package/dist/index.d.ts
CHANGED
|
@@ -174,6 +174,16 @@ export declare const buildHtmlHidden: (maps: Record<string, any>) => string;
|
|
|
174
174
|
*/
|
|
175
175
|
export declare const buildStyleVars: (vars: Record<string, number | string | undefined>) => Record<string, string>;
|
|
176
176
|
|
|
177
|
+
/**
|
|
178
|
+
* 计算剩余时间,单位为毫秒
|
|
179
|
+
* @param progress 当前进度
|
|
180
|
+
* @param total 总进度
|
|
181
|
+
* @param startTime 开始时间(毫秒时间戳)
|
|
182
|
+
* @returns 剩余时间,单位毫秒
|
|
183
|
+
* @description 根据当前进度、总进度和已用时间估算剩余时间。公式为:剩余时间 = (已用时间 / 当前进度) * (总进度 - 当前进度)。如果当前进度为0,则返回Infinity。
|
|
184
|
+
*/
|
|
185
|
+
export declare const calcRemainingMSecs: (progress: number, total: number, startTime: number) => number;
|
|
186
|
+
|
|
177
187
|
/**
|
|
178
188
|
* 驼峰命名转换
|
|
179
189
|
* @param str - 输入字符串
|
|
@@ -203,11 +213,10 @@ export declare function capitalize(str: string): string;
|
|
|
203
213
|
*/
|
|
204
214
|
export declare const cleanNull: (obj: any, recursive?: boolean) => any;
|
|
205
215
|
|
|
216
|
+
export declare const convertMinutesToTimezoneOffsetStr: (offsetMinutes: number) => string;
|
|
217
|
+
|
|
206
218
|
/**
|
|
207
219
|
* 倒计时函数(该方法采用 setTimeout 方式,不够精准)
|
|
208
|
-
* @param {number} timeout - 倒计时总秒数
|
|
209
|
-
* @param {Function} [tickFunc] - 每秒回调函数,接收剩余秒数作为参数
|
|
210
|
-
* @param {Function} [onFinish] - 倒计时结束回调函数
|
|
211
220
|
* @returns {void}
|
|
212
221
|
* @example
|
|
213
222
|
* countDown(10, (sec) => console.log(sec), () => console.log('done'))
|
|
@@ -441,23 +450,17 @@ export declare const fileToBase64DataUri: (file: File | Blob | string) => Promis
|
|
|
441
450
|
|
|
442
451
|
/**
|
|
443
452
|
* 通过选择器查找子节点(强制添加 :scope 来约束必须是子节点)
|
|
444
|
-
* @param {string|HTMLElement|HTMLElement[]|NodeList|HTMLCollection} selector - 选择器或 DOM 元素
|
|
445
|
-
* @param {Document|HTMLElement} [parent=document] - 父节点,默认为 document
|
|
446
|
-
* @returns {HTMLElement[]} 返回查找到的所有元素数组
|
|
447
453
|
* @example
|
|
448
454
|
* findAll('.item', container)
|
|
449
455
|
*/
|
|
450
|
-
export declare const findAll: (selector: string |
|
|
456
|
+
export declare const findAll: (selector: string | Element | Element[], parent?: Document | DocumentFragment | Element) => Element[];
|
|
451
457
|
|
|
452
458
|
/**
|
|
453
459
|
* 通过选择器查找单个节点
|
|
454
|
-
* @param {string|HTMLElement} selector - 选择器,如果是 HTMLElement,则直接返回
|
|
455
|
-
* @param {Document|HTMLElement} [parent=document] - 父节点,默认为 document
|
|
456
|
-
* @returns {HTMLElement} 返回查找到的元素
|
|
457
460
|
* @example
|
|
458
461
|
* findOne('.item')
|
|
459
462
|
*/
|
|
460
|
-
export declare const findOne: (selector: string |
|
|
463
|
+
export declare const findOne: (selector: string | Element, parent?: Document | DocumentFragment | Element) => Element | null;
|
|
461
464
|
|
|
462
465
|
/**
|
|
463
466
|
* 修复基本 URL(将相对路径转换为绝对 URL)
|
|
@@ -537,6 +540,22 @@ export declare const getJson: (url: string, data?: any, option?: RequestOption)
|
|
|
537
540
|
*/
|
|
538
541
|
export declare const getNodeXPath: (el: HTMLElement | null) => string | null;
|
|
539
542
|
|
|
543
|
+
/**
|
|
544
|
+
* 根据时区名称获取该时区相对于 UTC 的分钟偏移量(分钟)
|
|
545
|
+
* @param timeZone - 时区名称(如 "America/New_York")
|
|
546
|
+
* @param date - 可选的日期对象,默认为当前时间
|
|
547
|
+
*/
|
|
548
|
+
export declare const getTimezoneOffsetMinutes: (timeZone: string) => number;
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* 根据时区名称获取该时区相对于 UTC 的偏移字符串(格式为 "+HH:MM" 或 "-HH:MM")
|
|
552
|
+
* @param timeZone - 时区名称(如 "America/New_York")
|
|
553
|
+
* @returns 偏移字符串(如 "-05:00")
|
|
554
|
+
* @example
|
|
555
|
+
* getTimezoneOffsetStr("America/New_York") // "-05:00"
|
|
556
|
+
*/
|
|
557
|
+
export declare const getTimezoneOffsetStr: (timeZone: string) => string;
|
|
558
|
+
|
|
540
559
|
/**
|
|
541
560
|
* 获取 UTF-8 字符串长度(一个中文字按照 3 个字数计算)
|
|
542
561
|
* @param {string} str - 要计算的字符串
|
|
@@ -569,6 +588,7 @@ export declare const guid: (prefix?: string) => string;
|
|
|
569
588
|
|
|
570
589
|
/**
|
|
571
590
|
* 隐藏节点(通过设置 display:none 方式)
|
|
591
|
+
* 注:只有 HTMLElement 才有 style 属性,其他类型的 Node 没有,因此需要断言为 HTMLElement
|
|
572
592
|
* @param {HTMLElement|string} dom - DOM 元素或选择器
|
|
573
593
|
* @returns {void}
|
|
574
594
|
* @example
|
|
@@ -1160,8 +1180,6 @@ export declare const MONTH_NOW: number;
|
|
|
1160
1180
|
|
|
1161
1181
|
/**
|
|
1162
1182
|
* 毫秒转换为“时分秒前”格式
|
|
1163
|
-
* @param {number} ms - 毫秒数
|
|
1164
|
-
* @returns {string} 返回格式化后的字符串
|
|
1165
1183
|
* @example
|
|
1166
1184
|
* msToHMS(3661000) // '1小时0分钟1秒前'
|
|
1167
1185
|
*/
|
|
@@ -1499,6 +1517,7 @@ export declare const setCookie: (name: string, value: string, days: number, path
|
|
|
1499
1517
|
|
|
1500
1518
|
/**
|
|
1501
1519
|
* 显示节点(通过设置 display 为空方式)
|
|
1520
|
+
* 注:只有 HTMLElement 才有 style 属性,其他类型的 Node 没有,因此需要断言为 HTMLElement
|
|
1502
1521
|
* @param {HTMLElement|string} dom - DOM 元素或选择器
|
|
1503
1522
|
* @returns {void}
|
|
1504
1523
|
* @example
|
|
@@ -1603,6 +1622,15 @@ export declare const throttle: (fn: Function, intervalMiSec: number) => Function
|
|
|
1603
1622
|
*/
|
|
1604
1623
|
export declare const throttleEffect: (fn: Function, intervalMiSec: number) => Function;
|
|
1605
1624
|
|
|
1625
|
+
/**
|
|
1626
|
+
* 将时间戳转换为本地时间的日期时间字符串(YYYY-MM-DDTHH:mm),
|
|
1627
|
+
* 一般用于填充到 input[type="datetime-local"] 的 value 属性中
|
|
1628
|
+
* @param timestamp 时间戳,可以是数字、字符串或 Date 对象
|
|
1629
|
+
* @param includeSec 是否包含秒,默认为 false,如果为 true 则返回的字符串格式为 YYYY-MM-DDTHH:mm:ss
|
|
1630
|
+
* @returns 本地时间的日期时间字符串,格式为 YYYY-MM-DDTHH:mm:ss(如果 includeSec 参数为 true 则包含秒)
|
|
1631
|
+
*/
|
|
1632
|
+
export declare const timestampToDateTimeLocal: (timestamp: number | string | Date, includeSec?: boolean) => string;
|
|
1633
|
+
|
|
1606
1634
|
/**
|
|
1607
1635
|
* 禁用启用元素切换
|
|
1608
1636
|
* @param {String|Node} el
|