minutool 1.0.16 → 1.0.18

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 CHANGED
@@ -213,6 +213,8 @@ export declare function capitalize(str: string): string;
213
213
  */
214
214
  export declare const cleanNull: (obj: any, recursive?: boolean) => any;
215
215
 
216
+ export declare const COMMON_DPI = 96;
217
+
216
218
  export declare const convertMinutesToTimezoneOffsetStr: (offsetMinutes: number) => string;
217
219
 
218
220
  /**
@@ -331,7 +333,7 @@ export declare const detectedPrecision: (...numbers: number[]) => number;
331
333
  * @example
332
334
  * detectLanguage(['en', 'zh-CN', 'zh']) // '根据浏览器语言返回匹配的语言'
333
335
  */
334
- export declare const detectLanguage: (supportedLngs: string[]) => any;
336
+ export declare const detectLanguage: (supportedLngs: string[]) => string;
335
337
 
336
338
  /**
337
339
  * 计算数字位数
@@ -474,10 +476,11 @@ export declare const fixBaseUrl: (url: string, baseUrl: string) => string;
474
476
 
475
477
  /**
476
478
  * 将字符串转换为浮点数
477
- * @param {string} str - 要转换的字符串
479
+ * @param {*} str - 要转换的字符串
478
480
  * @param {number} [defaultVal=0] - 转换失败时的默认值
481
+ * @returns {number} 返回转换后的浮点数,如果转换失败则返回默认值
479
482
  */
480
- export declare const floatVal: (str: string, defaultVal?: number) => number;
483
+ export declare const floatVal: (str: any, defaultVal?: number) => number;
481
484
 
482
485
  /**
483
486
  * 格式化日期(以 PHP 方式格式化)
@@ -712,6 +715,15 @@ export declare const isJSON: (json: string) => boolean;
712
715
  */
713
716
  export declare const isJson: (json: string) => boolean;
714
717
 
718
+ export declare const isLandscape: () => boolean;
719
+
720
+ /**
721
+ * 判断一个值是否为数字
722
+ * @param val - 要判断的值
723
+ * @returns 如果是数字返回 true,否则返回 false
724
+ */
725
+ export declare const isNumberic: (val: any) => boolean;
726
+
715
727
  /**
716
728
  * 检测目标是否为 Object(非数组的对象)
717
729
  * @param {any} item - 要检测的对象
@@ -722,6 +734,8 @@ export declare const isJson: (json: string) => boolean;
722
734
  */
723
735
  export declare const isObject: (item: any) => boolean;
724
736
 
737
+ export declare const isPortrait: () => boolean;
738
+
725
739
  /**
726
740
  * 检测对象是否为 Promise 对象
727
741
  * @param {any} obj - 要检测的对象
@@ -1226,7 +1240,14 @@ export declare function objectGet<T = any>(obj: any, path: string, defaultValue?
1226
1240
  * @example
1227
1241
  * objectKeyMapping({a: 1, b: 2}, {a: 'x'}) // {x: 1, b: 2}
1228
1242
  */
1229
- export declare const objectKeyMapping: (obj: Record<string, any>, mapping: Record<string, string>) => Record<string, any>;
1243
+ export declare const objectKeyReplace: (obj: Record<string, any>, mapping: Record<string, string>) => Record<string, any>;
1244
+
1245
+ /**
1246
+ * 交换对象中的键值对
1247
+ * @param {Object} obj
1248
+ * @returns
1249
+ */
1250
+ export declare const objectKeyValSwap: (obj: object) => any;
1230
1251
 
1231
1252
  /**
1232
1253
  * 合并对象
@@ -1295,8 +1316,11 @@ export declare const ONE_YEAR366: number;
1295
1316
  * 订阅事件,event 可以是字符串或 Symbol,handler 是事件处理函数
1296
1317
  * @param {string | symbol} event 事件名称
1297
1318
  * @param {Function} handler 事件处理函数
1319
+ * @return {Function} 返回一个取消订阅的函数
1298
1320
  */
1299
- export declare const onEvent: (event: string | symbol, handler: EventListenerOrEventListenerObject) => void;
1321
+ export declare const onEvent: (event: string | symbol, handler: EventListenerOrEventListenerObject) => () => void;
1322
+
1323
+ export declare const onEvents: (events: (string | symbol)[], handler: EventListenerOrEventListenerObject) => () => void;
1300
1324
 
1301
1325
  export declare const onHover: (el: HTMLElement | string, onHoverIn: () => void, onHoverOut: () => void) => void;
1302
1326
 
@@ -1307,6 +1331,14 @@ export declare const onHover: (el: HTMLElement | string, onHoverIn: () => void,
1307
1331
  */
1308
1332
  export declare const PAIR_TAGS: string[];
1309
1333
 
1334
+ /**
1335
+ * 解析带单位的值,返回数值和单位
1336
+ */
1337
+ export declare const parseUnit: (value: string | number, defaultUnit?: string) => {
1338
+ val: number;
1339
+ unit: string;
1340
+ } | null;
1341
+
1310
1342
  /**
1311
1343
  * 上传文件
1312
1344
  * @param {string} url - 请求 URL
@@ -1495,6 +1527,8 @@ export declare const round: (num: number, precision?: number) => number;
1495
1527
  */
1496
1528
  export declare const sanitizeFileName: (name: string) => string;
1497
1529
 
1530
+ export declare const SCREEN_DPI: number;
1531
+
1498
1532
  /**
1499
1533
  * 自关闭标签
1500
1534
  * @type {string[]}
@@ -1527,13 +1561,13 @@ export declare const show: (dom: HTMLElement | string) => void;
1527
1561
 
1528
1562
  /**
1529
1563
  * 通过图片 URL 获取 Base64(网络请求模式)
1530
- * @param {string} src - 图片 URL
1564
+ * @param {string} url - 图片 URL
1531
1565
  * @param {boolean} [cache=false] - 是否缓存结果
1532
1566
  * @returns {Promise<unknown>} 返回 Base64 Data URL 的 Promise
1533
1567
  * @example
1534
1568
  * srcToBase64('https://example.com/image.png').then(base64 => console.log(base64))
1535
1569
  */
1536
- export declare const srcToBase64: (src: string, cache?: boolean) => Promise<unknown>;
1570
+ export declare const srcToBase64: (url: string, cache?: boolean) => Promise<unknown>;
1537
1571
 
1538
1572
  export declare const STAND_DPI = 96;
1539
1573
 
@@ -1590,6 +1624,36 @@ export declare const stripSlashes: (str: string) => string;
1590
1624
  */
1591
1625
  export declare const strToPascalCase: (str: string, capitalize_first?: boolean) => string;
1592
1626
 
1627
+ /**
1628
+ * 兼容方式获取svg的BBox,避免Firefox获取svg尺寸时,额外考虑了父容器的zoom
1629
+ * @param {SVGSVGElement} svg
1630
+ * @returns {DOMRect}
1631
+ * @returns {DOMRect.width} 单位px
1632
+ * @returns {DOMRect.height} 单位px
1633
+ * @see https://stackoverflow.com/questions/60814803/getboundingbox-of-svg-element-in-firefox
1634
+ */
1635
+ export declare const svgGetBBox: (svg: SVGSVGElement) => DOMRect;
1636
+
1637
+ /**
1638
+ * svg 对象转换为图片对象
1639
+ * @returns
1640
+ */
1641
+ export declare const svgToImg: (svg: SVGSVGElement) => Promise<HTMLImageElement>;
1642
+
1643
+ /**
1644
+ * svg 对象转换为图片数据
1645
+ * @param {SVGSVGElement} svg
1646
+ * @param {String} format
1647
+ * @param {number} quality
1648
+ * @returns
1649
+ */
1650
+ export declare const svgToImgData: (svg: SVGSVGElement, format?: string | null, quality?: number | null) => Promise<string>;
1651
+
1652
+ /**
1653
+ * svg 对象转换为图片数据
1654
+ */
1655
+ export declare const svgToSrc: (svg: SVGSVGElement) => string;
1656
+
1593
1657
  /**
1594
1658
  * 将纯文本转换为 HTML(转义特殊字符并处理换行)
1595
1659
  * @param {string} text - 纯文本字符串