@yh-kit/utils 1.1.3 → 1.2.1

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/utils.js CHANGED
@@ -1,37 +1,95 @@
1
- const r = {
2
- // toEnumObj: handleArrTansferEnumObj,
1
+ const n = (e) => {
2
+ if (!e || !e.length) return {};
3
+ const r = {};
4
+ return e.forEach((t) => {
5
+ const o = Object.assign({ label: t.label, text: t.label }, t);
6
+ r[t == null ? void 0 : t.value] = o;
7
+ }), r;
8
+ }, s = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
9
+ __proto__: null,
10
+ toEnumObj: n
11
+ }, Symbol.toStringTag, { value: "Module" })), d = {
12
+ ...s,
3
13
  /**
4
- * 数组转枚举对象
14
+ * 数组去重
5
15
  * @param arr 数组
6
- * @returns
16
+ * @returns 去重后的数组
7
17
  */
8
- toEnumObj: (e) => {
9
- if (!e || !e.length) return {};
10
- const n = {};
11
- return e.forEach((t) => {
12
- const o = Object.assign({ label: t.label, text: t.label }, t);
13
- n[t == null ? void 0 : t.value] = o;
14
- }), n;
18
+ unique: (e) => e ? Array.from(new Set(e)) : [],
19
+ /**
20
+ * 判断某元素是否在数组中
21
+ * @param arr 数组
22
+ * @param element 查询元素
23
+ * @returns 是否存在。true 存在;false 不存在
24
+ */
25
+ isExist(e, r) {
26
+ return !e || !r ? !1 : e.indexOf(r) !== -1;
27
+ },
28
+ /**
29
+ * 统计数组中某元素出现的次数:对于大型数组,手动循环的性能略优于 filter 和 reduce。
30
+ * @param arr 数组
31
+ * @param target 目标元素
32
+ * @returns 出现次数
33
+ */
34
+ countOfAppear(e, r) {
35
+ let t = 0;
36
+ for (const o of e)
37
+ o === r && t++;
38
+ return t;
39
+ },
40
+ /**
41
+ * 数组排序-默认升序
42
+ * @param arr 数组
43
+ * @param order 排序方式:asc 升序;desc 降序
44
+ * @returns 排序后的数组
45
+ */
46
+ sort(e, r = "asc") {
47
+ return e ? e.sort((t, o) => r === "asc" ? t > o ? 1 : -1 : t < o ? 1 : -1) : [];
15
48
  }
16
- }, g = {
17
- ...r
18
- }, s = (e) => e > 25 || e < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e], c = {
19
- toLetter: s
20
- }, l = (e) => e.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","), u = {
21
- toMoney: l
49
+ }, l = (e) => e > 25 || e < 0 ? "" : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e], c = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
50
+ __proto__: null,
51
+ toLetter: l
52
+ }, Symbol.toStringTag, { value: "Module" })), u = (e) => e.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","), i = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
53
+ __proto__: null,
54
+ toMoney: u
55
+ }, Symbol.toStringTag, { value: "Module" })), g = {
56
+ ...c,
57
+ ...i
58
+ }, b = {
59
+ /**
60
+ * 脱敏
61
+ * @param phone 电话号码/手机号码
62
+ * @returns 脱敏后的电话号码/手机号码
63
+ */
64
+ desensitize: (e) => e ? e.replace(/^(\d{3})\d{4}(\d{4})$/, "$1****$2") || e.slice(0, 3) + "****" + e.slice(7) : ""
22
65
  }, y = {
23
- ...u,
24
- ...c
25
- }, a = (e) => {
66
+ /**
67
+ * 判断某元素是否在字符串中
68
+ * @param str 字符串
69
+ * @param element 查询元素
70
+ * @returns 是否存在。true 存在;false 不存在
71
+ */
72
+ isExist(e, r) {
73
+ if (!e || !r)
74
+ return !1;
75
+ const t = e.split(",");
76
+ return console.log("判断某元素是否在字符串中", t.indexOf(r) === -1), t.indexOf(r) !== -1;
77
+ }
78
+ }, f = (e) => {
26
79
  const t = new RegExp("[?&]" + e + "=([^&#]*)", "i").exec(window.location.href);
27
80
  return t ? decodeURIComponent(t[1]) : null;
28
- }, b = {
29
- getQueryInfoByName: a
30
- }, x = {
31
- ...b
81
+ }, a = {
82
+ getQueryInfoByName: f
83
+ }, p = {
84
+ ...a
85
+ }, O = (e, r = 2) => {
86
+ console.log(e, r);
32
87
  };
33
88
  export {
34
- g as arrayUtils,
35
- y as numberUtils,
36
- x as urlUtils
89
+ d as arrayUtils,
90
+ g as numberUtils,
91
+ b as phoneUtils,
92
+ y as stringUtils,
93
+ O as toList,
94
+ p as urlUtils
37
95
  };
@@ -1 +1 @@
1
- (function(n,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(n=typeof globalThis<"u"?globalThis:n||self,o(n.yhkitUtils={}))})(this,function(n){"use strict";const s={...{toEnumObj:e=>{if(!e||!e.length)return{};const r={};return e.forEach(t=>{const c=Object.assign({label:t.label,text:t.label},t);r[t==null?void 0:t.value]=c}),r}}},l={...{toMoney:e=>e.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")},...{toLetter:e=>e>25||e<0?"":"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e]}},u={...{getQueryInfoByName:e=>{const t=new RegExp("[?&]"+e+"=([^&#]*)","i").exec(window.location.href);return t?decodeURIComponent(t[1]):null}}};n.arrayUtils=s,n.numberUtils=l,n.urlUtils=u,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
1
+ (function(o,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(o=typeof globalThis<"u"?globalThis:o||self,s(o.yhkitUtils={}))})(this,function(o){"use strict";const l={...Object.freeze(Object.defineProperty({__proto__:null,toEnumObj:e=>{if(!e||!e.length)return{};const n={};return e.forEach(t=>{const r=Object.assign({label:t.label,text:t.label},t);n[t==null?void 0:t.value]=r}),n}},Symbol.toStringTag,{value:"Module"})),unique:e=>e?Array.from(new Set(e)):[],isExist(e,n){return!e||!n?!1:e.indexOf(n)!==-1},countOfAppear(e,n){let t=0;for(const r of e)r===n&&t++;return t},sort(e,n="asc"){return e?e.sort((t,r)=>n==="asc"?t>r?1:-1:t<r?1:-1):[]}},i={...Object.freeze(Object.defineProperty({__proto__:null,toLetter:e=>e>25||e<0?"":"ABCDEFGHIJKLMNOPQRSTUVWXYZ"[e]},Symbol.toStringTag,{value:"Module"})),...Object.freeze(Object.defineProperty({__proto__:null,toMoney:e=>e.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")},Symbol.toStringTag,{value:"Module"}))},u={desensitize:e=>e?e.replace(/^(\d{3})\d{4}(\d{4})$/,"$1****$2")||e.slice(0,3)+"****"+e.slice(7):""},c={isExist(e,n){if(!e||!n)return!1;const t=e.split(",");return console.log("判断某元素是否在字符串中",t.indexOf(n)===-1),t.indexOf(n)!==-1}},f={...{getQueryInfoByName:e=>{const t=new RegExp("[?&]"+e+"=([^&#]*)","i").exec(window.location.href);return t?decodeURIComponent(t[1]):null}}},d=(e,n=2)=>{console.log(e,n)};o.arrayUtils=l,o.numberUtils=i,o.phoneUtils=u,o.stringUtils=c,o.toList=d,o.urlUtils=f,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@yh-kit/utils",
3
3
  "private": false,
4
- "version": "1.1.3",
4
+ "version": "1.2.1",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",
@@ -9,9 +9,9 @@
9
9
  ],
10
10
  "main": "./dist/utils.umd.cjs",
11
11
  "module": "./dist/utils.js",
12
- "types": "./types/index.d.ts",
12
+ "types": "./types/utils/lib/index.d.ts",
13
13
  "exports": {
14
- "types": "./types/index.d.ts",
14
+ "types": "./types/utils/lib/index.d.ts",
15
15
  "import": "./dist/utils.js",
16
16
  "require": "./dist/utils.umd.cjs"
17
17
  },
@@ -27,6 +27,9 @@
27
27
  "typescript": "catalog:",
28
28
  "vite": "catalog:"
29
29
  },
30
+ "peerDependencies": {
31
+ "@yh-kit/types": "workspace:*"
32
+ },
30
33
  "publishConfig": {
31
34
  "main": "dist/utils.js",
32
35
  "access": "public",
@@ -0,0 +1,14 @@
1
+ /**
2
+ * 枚举对象类型
3
+ * @example
4
+ * ```ts
5
+ * const enumObj = {
6
+ * 1: { key: 1, label: '男', text: '男' },
7
+ * 2: { key: 1, label: '女',text: '女' },
8
+ * } as TValueEnum;
9
+ * ```
10
+ */
11
+ export type TValueEnum = Record<string | number | symbol, {
12
+ text: string;
13
+ [key: string]: unknown;
14
+ }>;
@@ -0,0 +1,2 @@
1
+ export type * from "./enum-obj";
2
+ export type * from "./option";
@@ -1,12 +1,5 @@
1
1
  /**
2
- * 枚举对象类型
3
- */
4
- export type TValueEnum = Record<string | number | symbol, {
5
- text: string;
6
- [key: string]: unknown;
7
- }>;
8
- /**
9
- * 枚举对象类型
2
+ * option对象类型
10
3
  */
11
4
  export interface IOptionItem {
12
5
  /** 值 */
@@ -0,0 +1,7 @@
1
+ import { IOptionItem, TValueEnum } from "../../../typings/src";
2
+ /**
3
+ * 数组转枚举对象
4
+ * @param arr 数组
5
+ * @returns 枚举对象
6
+ */
7
+ export declare const toEnumObj: (arr: IOptionItem[]) => TValueEnum;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * 数组相关操作工具函数
3
+ */
4
+ export declare const arrayUtils: {
5
+ /**
6
+ * 数组去重
7
+ * @param arr 数组
8
+ * @returns 去重后的数组
9
+ */
10
+ unique: <T>(arr: T[]) => T[];
11
+ /**
12
+ * 判断某元素是否在数组中
13
+ * @param arr 数组
14
+ * @param element 查询元素
15
+ * @returns 是否存在。true 存在;false 不存在
16
+ */
17
+ isExist<T>(arr: T[], element: T): boolean;
18
+ /**
19
+ * 统计数组中某元素出现的次数:对于大型数组,手动循环的性能略优于 filter 和 reduce。
20
+ * @param arr 数组
21
+ * @param target 目标元素
22
+ * @returns 出现次数
23
+ */
24
+ countOfAppear<T>(arr: T[], target: T): number;
25
+ /**
26
+ * 数组排序-默认升序
27
+ * @param arr 数组
28
+ * @param order 排序方式:asc 升序;desc 降序
29
+ * @returns 排序后的数组
30
+ */
31
+ sort<T>(arr: T[], order?: "asc" | "desc"): T[];
32
+ toEnumObj: (arr: import("@yh-kit/types").IOptionItem[]) => import("@yh-kit/types").TValueEnum;
33
+ };
@@ -0,0 +1,6 @@
1
+ export * from "./array";
2
+ export * from "./number";
3
+ export * from "./phone";
4
+ export * from "./string";
5
+ export * from "./url";
6
+ export * from "./waterfall";
@@ -0,0 +1,12 @@
1
+ /**
2
+ * 数字转字母
3
+ * 例如:
4
+ * 0 => A
5
+ * 1 => B
6
+ * 25 => Z
7
+ * 26 => ""
8
+ * 27 => ""
9
+ * @param num 数字
10
+ * @returns
11
+ */
12
+ export declare const toLetter: (num: number) => string;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * 格式化金额 - 数字千分化,保留两位小数
3
+ * 例如:
4
+ * 123456789 => 123,456,789.00
5
+ * 0 => 0.00
6
+ * 123.456789 => 123.46
7
+ * @param x 数字
8
+ * @returns
9
+ */
10
+ export declare const toMoney: (x: number) => string;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * 电话号码/手机号码相关操作工具函数
3
+ */
4
+ export declare const phoneUtils: {
5
+ /**
6
+ * 脱敏
7
+ * @param phone 电话号码/手机号码
8
+ * @returns 脱敏后的电话号码/手机号码
9
+ */
10
+ desensitize: (phone: string) => string;
11
+ };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * 字符串相关操作工具函数
3
+ */
4
+ export declare const stringUtils: {
5
+ /**
6
+ * 判断某元素是否在字符串中
7
+ * @param str 字符串
8
+ * @param element 查询元素
9
+ * @returns 是否存在。true 存在;false 不存在
10
+ */
11
+ isExist(str: string, element: string): boolean;
12
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * 处理瀑布流数据,使其适合瀑布流布局展示
3
+ * @param list 瀑布流数据-数组
4
+ * @param columnsNum 需要展示的列数
5
+ * @returns 适合瀑布流布局的数组
6
+ */
7
+ export declare const toList: (list: unknown[], columnsNum?: number) => void;
@@ -1,16 +0,0 @@
1
- import { IOptionItem, TValueEnum } from "../typings";
2
- /**
3
- * 数组转枚举对象
4
- * @param arr
5
- * @returns
6
- */
7
- /** 数组转对象 */
8
- declare const _default: {
9
- /**
10
- * 数组转枚举对象
11
- * @param arr 数组
12
- * @returns
13
- */
14
- toEnumObj: (arr: IOptionItem[]) => TValueEnum;
15
- };
16
- export default _default;
@@ -1,6 +0,0 @@
1
- /**
2
- * 数组相关操作工具函数
3
- */
4
- export declare const arrayUtils: {
5
- toEnumObj: (arr: import("../typings").IOptionItem[]) => import("../typings").TValueEnum;
6
- };
package/types/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from "./array";
2
- export * from "./number";
3
- export * from "./url";
@@ -1,4 +0,0 @@
1
- declare const _default: {
2
- toLetter: (num: number) => string;
3
- };
4
- export default _default;
@@ -1,4 +0,0 @@
1
- declare const _default: {
2
- toMoney: (x: number) => string;
3
- };
4
- export default _default;
File without changes
@@ -2,6 +2,6 @@
2
2
  * 数字相关操作工具函数
3
3
  */
4
4
  export declare const numberUtils: {
5
- toLetter: (num: number) => string;
6
5
  toMoney: (x: number) => string;
6
+ toLetter: (num: number) => string;
7
7
  };
File without changes
File without changes