minutool 1.0.18 → 1.0.19
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 +54 -19
- package/dist/minutool.js +678 -625
- 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 +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -721,6 +721,11 @@ export declare const isLandscape: () => boolean;
|
|
|
721
721
|
* 判断一个值是否为数字
|
|
722
722
|
* @param val - 要判断的值
|
|
723
723
|
* @returns 如果是数字返回 true,否则返回 false
|
|
724
|
+
* @example
|
|
725
|
+
* isNumberic(123) // true
|
|
726
|
+
* isNumberic('123.45') // true
|
|
727
|
+
* isNumberic('-123') // true
|
|
728
|
+
* isNumberic('210mm') // false
|
|
724
729
|
*/
|
|
725
730
|
export declare const isNumberic: (val: any) => boolean;
|
|
726
731
|
|
|
@@ -1220,6 +1225,24 @@ export declare const mutationEffective: (dom: HTMLElement, option: MutationObser
|
|
|
1220
1225
|
*/
|
|
1221
1226
|
export declare const nodeIndex: (node: HTMLElement) => number;
|
|
1222
1227
|
|
|
1228
|
+
/**
|
|
1229
|
+
* 获取对象的键值对数组,代替 Object.entries,如果key是数字,则转换为数字类型
|
|
1230
|
+
* @param obj - 要获取键值对的对象
|
|
1231
|
+
* @returns 键值对数组
|
|
1232
|
+
* @example
|
|
1233
|
+
* objectEntries({ a: 1, b: 2 }) // [['a', 1], ['b', 2]]
|
|
1234
|
+
*/
|
|
1235
|
+
export declare const objectEntries: <T extends Record<string | number | symbol, any>>(obj: T) => [keyof T, T[keyof T]][];
|
|
1236
|
+
|
|
1237
|
+
/**
|
|
1238
|
+
* 从键值对数组创建对象,代替 Object.fromEntries,如果key是数字字符串,则转换为数字类型
|
|
1239
|
+
* @param entries - 键值对数组
|
|
1240
|
+
* @returns 创建的对象
|
|
1241
|
+
* @example
|
|
1242
|
+
* objectFromEntries([['a', 1], ['b', 2]]) // { a: 1, b: 2 }
|
|
1243
|
+
*/
|
|
1244
|
+
export declare const objectFromEntries: <T extends Record<string | number | symbol, any>>(entries: Iterable<readonly [string | number, T[keyof T]]>) => T;
|
|
1245
|
+
|
|
1223
1246
|
/**
|
|
1224
1247
|
* 获取对象指定路径的值
|
|
1225
1248
|
* @param obj - 对象
|
|
@@ -1233,22 +1256,15 @@ export declare const nodeIndex: (node: HTMLElement) => number;
|
|
|
1233
1256
|
export declare function objectGet<T = any>(obj: any, path: string, defaultValue?: T): T;
|
|
1234
1257
|
|
|
1235
1258
|
/**
|
|
1236
|
-
*
|
|
1237
|
-
* @param
|
|
1238
|
-
* @param {
|
|
1239
|
-
* @returns
|
|
1259
|
+
* 根据映射关系替换对象的键
|
|
1260
|
+
* @param obj - 要替换键的对象
|
|
1261
|
+
* @param mapping - 键映射关系,例如 { oldKey: 'newKey' }
|
|
1262
|
+
* @returns 替换键后的新对象
|
|
1240
1263
|
* @example
|
|
1241
|
-
*
|
|
1264
|
+
* objectKeyReplace({ a: 1, b: 2 }, { a: 'x' }) // { x: 1, b: 2 }
|
|
1242
1265
|
*/
|
|
1243
1266
|
export declare const objectKeyReplace: (obj: Record<string, any>, mapping: Record<string, string>) => Record<string, any>;
|
|
1244
1267
|
|
|
1245
|
-
/**
|
|
1246
|
-
* 交换对象中的键值对
|
|
1247
|
-
* @param {Object} obj
|
|
1248
|
-
* @returns
|
|
1249
|
-
*/
|
|
1250
|
-
export declare const objectKeyValSwap: (obj: object) => any;
|
|
1251
|
-
|
|
1252
1268
|
/**
|
|
1253
1269
|
* 合并对象
|
|
1254
1270
|
* @param target - 目标对象
|
|
@@ -1269,6 +1285,15 @@ export declare function objectMerge<T extends object>(target: T, ...sources: Par
|
|
|
1269
1285
|
*/
|
|
1270
1286
|
export declare function objectSet(obj: any, path: string, value: any): void;
|
|
1271
1287
|
|
|
1288
|
+
/**
|
|
1289
|
+
* 交换对象中的键值对
|
|
1290
|
+
* @param obj - 要交换键值对的对象
|
|
1291
|
+
* @returns 交换后的对象
|
|
1292
|
+
* @example
|
|
1293
|
+
* objectSwitchKV({a: 1, b: 2}) // {1: 'a', 2: 'b'}
|
|
1294
|
+
*/
|
|
1295
|
+
export declare const objectSwitchKV: (obj: object) => any;
|
|
1296
|
+
|
|
1272
1297
|
/**
|
|
1273
1298
|
* 将对象转换为 URL 查询字符串
|
|
1274
1299
|
* @param {Record<string, any>} data - 数据对象
|
|
@@ -1625,14 +1650,14 @@ export declare const stripSlashes: (str: string) => string;
|
|
|
1625
1650
|
export declare const strToPascalCase: (str: string, capitalize_first?: boolean) => string;
|
|
1626
1651
|
|
|
1627
1652
|
/**
|
|
1628
|
-
*
|
|
1629
|
-
*
|
|
1630
|
-
* @
|
|
1631
|
-
* @returns {DOMRect
|
|
1632
|
-
* @returns {DOMRect.
|
|
1633
|
-
* @
|
|
1653
|
+
* 获取 SVG 的尺寸(像素单位)
|
|
1654
|
+
* 优先级:width/height 属性 > viewBox > getBoundingClientRect
|
|
1655
|
+
* @param {SVGSVGElement} svg - SVG 元素
|
|
1656
|
+
* @returns {DOMRect} 返回包含像素单位的尺寸对象
|
|
1657
|
+
* @returns {number} DOMRect.width - 宽度(像素)
|
|
1658
|
+
* @returns {number} DOMRect.height - 高度(像素)
|
|
1634
1659
|
*/
|
|
1635
|
-
export declare const
|
|
1660
|
+
export declare const svgGetDimension: (svg: SVGSVGElement) => [number, number];
|
|
1636
1661
|
|
|
1637
1662
|
/**
|
|
1638
1663
|
* svg 对象转换为图片对象
|
|
@@ -1749,6 +1774,16 @@ export declare function truncate(str: string, length: number, suffix?: string):
|
|
|
1749
1774
|
*/
|
|
1750
1775
|
export declare const unescapeHtml: (html: string) => string;
|
|
1751
1776
|
|
|
1777
|
+
/**
|
|
1778
|
+
* 单位转换工具,支持px、mm、cm、in等常见单位之间的转换
|
|
1779
|
+
* @returns {Number} 转换后的数值(以目标单位为准)
|
|
1780
|
+
*/
|
|
1781
|
+
export declare const unitConvert: (value: string | number, toUnit: string, extOption?: {
|
|
1782
|
+
dpi?: number;
|
|
1783
|
+
fontSize?: number | null;
|
|
1784
|
+
lineHeight?: number | null;
|
|
1785
|
+
}) => number;
|
|
1786
|
+
|
|
1752
1787
|
/**
|
|
1753
1788
|
* URL 转 Base64 Data URL 数据缓存
|
|
1754
1789
|
* @param {string} url - 文件 URL
|