@base-web-kits/base-tools-ts 0.8.18 → 0.9.3
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/README.md +65 -8
- package/base-tools-ts.umd.global.js +55 -2
- package/dist/base-tools-ts.umd.global.js +55 -2
- package/dist/index.cjs +37 -0
- package/dist/index.js +36 -0
- package/package.json +46 -45
package/README.md
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
# Base Tools
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Web前端团队常用工具库,包含`ts`、`web`、`react`、`vue`、`uni`模块。
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## 📖 在线文档
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
[https://gancao-web.github.io/base-tools/](https://gancao-web.github.io/base-tools/)
|
|
8
|
+
|
|
9
|
+
## 🚀 快速开始
|
|
10
|
+
|
|
11
|
+
### 安装
|
|
12
|
+
|
|
13
|
+
- 按需安装即可,模块之间不相互依赖
|
|
14
|
+
- 非ts环境和普通h5也能使用,因为所有函数已编译为es5
|
|
8
15
|
|
|
9
16
|
```js
|
|
10
|
-
// 通用
|
|
17
|
+
// 通用TS/JS模块
|
|
11
18
|
npm i @base-web-kits/base-tools-ts
|
|
12
19
|
|
|
13
20
|
// Web 模块
|
|
@@ -23,14 +30,14 @@ npm i @base-web-kits/base-tools-vue
|
|
|
23
30
|
npm i @base-web-kits/base-tools-uni
|
|
24
31
|
```
|
|
25
32
|
|
|
26
|
-
|
|
33
|
+
### 使用
|
|
27
34
|
|
|
28
35
|
```ts
|
|
29
|
-
// 通用
|
|
36
|
+
// 通用TS/JS模块
|
|
30
37
|
import { toDayjs, getUrlParam, toMaskPhone } from '@base-web-kits/base-tools-ts';
|
|
31
38
|
|
|
32
39
|
// Web 模块
|
|
33
|
-
import { copyText, isPC,
|
|
40
|
+
import { copyText, isPC, setCookie } from '@base-web-kits/base-tools-web';
|
|
34
41
|
|
|
35
42
|
// React 模块
|
|
36
43
|
import { useCountDown } from '@base-web-kits/base-tools-react';
|
|
@@ -39,5 +46,55 @@ import { useCountDown } from '@base-web-kits/base-tools-react';
|
|
|
39
46
|
import { useResizeObserver } from '@base-web-kits/base-tools-vue';
|
|
40
47
|
|
|
41
48
|
// Uni 模块
|
|
42
|
-
import { chooseMedia, toPayWx } from '@base-web-kits/base-tools-uni';
|
|
49
|
+
import { setAppConfig, chooseMedia, toPayWx } from '@base-web-kits/base-tools-uni';
|
|
50
|
+
|
|
51
|
+
setAppConfig({
|
|
52
|
+
pathHome: '/pages/tabbar/home/index',
|
|
53
|
+
pathLogin: '/pages/login/index',
|
|
54
|
+
pathWebview: '/pages/webview/index',
|
|
55
|
+
hostFile: 'https://xx.com/',
|
|
56
|
+
hostIcon: 'https://xx.com/xx/',
|
|
57
|
+
isTabBar: (url) => url.startsWith('/pages/tabbar/'),
|
|
58
|
+
isLogin: () => useUserStore().isLogin,
|
|
59
|
+
log: (level, data) => console.log({ level, data }),
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 普通h5
|
|
64
|
+
|
|
65
|
+
```html
|
|
66
|
+
<!DOCTYPE html>
|
|
67
|
+
<html>
|
|
68
|
+
<head>
|
|
69
|
+
<title>Base Tools 示例</title>
|
|
70
|
+
</head>
|
|
71
|
+
<body>
|
|
72
|
+
<script src="https://cdn.jsdelivr.net/npm/@base-web-kits/base-tools-ts@1.0.0/dist/base-tools-ts.umd.global.js"></script>
|
|
73
|
+
<script src="https://cdn.jsdelivr.net/npm/@base-web-kits/base-tools-web@1.0.0/dist/base-tools-web.umd.global.js"></script>
|
|
74
|
+
|
|
75
|
+
<script>
|
|
76
|
+
// 使用 base-tools-ts 中的函数
|
|
77
|
+
const { createTimeRandId, EventBus } = baseToolsTS;
|
|
78
|
+
|
|
79
|
+
// 使用 base-tools-web 中的函数
|
|
80
|
+
const { getCookie, setCookie } = baseToolsWeb;
|
|
81
|
+
|
|
82
|
+
// 示例:创建随机ID
|
|
83
|
+
const id = createTimeRandId();
|
|
84
|
+
console.log('随机ID:', id);
|
|
85
|
+
|
|
86
|
+
// 示例:使用EventBus
|
|
87
|
+
const emitter = new EventBus();
|
|
88
|
+
emitter.on('test', (data) => {
|
|
89
|
+
console.log('收到事件:', data);
|
|
90
|
+
});
|
|
91
|
+
emitter.emit('test', 'Hello World!');
|
|
92
|
+
|
|
93
|
+
// 示例:操作Cookie
|
|
94
|
+
setCookie('name', 'Base Tools', 7);
|
|
95
|
+
const name = getCookie('name');
|
|
96
|
+
console.log('Cookie值:', name);
|
|
97
|
+
</script>
|
|
98
|
+
</body>
|
|
99
|
+
</html>
|
|
43
100
|
```
|
|
@@ -710,6 +710,7 @@ var baseToolsTS = (() => {
|
|
|
710
710
|
var ts_exports = {};
|
|
711
711
|
__export(ts_exports, {
|
|
712
712
|
BigNumber: () => bignumber_default,
|
|
713
|
+
EventBus: () => EventBus,
|
|
713
714
|
add: () => add_default,
|
|
714
715
|
after: () => after_default,
|
|
715
716
|
appendUrlParam: () => appendUrlParam,
|
|
@@ -1134,6 +1135,58 @@ var baseToolsTS = (() => {
|
|
|
1134
1135
|
}
|
|
1135
1136
|
}
|
|
1136
1137
|
|
|
1138
|
+
// node_modules/.pnpm/mitt@3.0.1/node_modules/mitt/dist/mitt.mjs
|
|
1139
|
+
function mitt_default(n) {
|
|
1140
|
+
return { all: n = n || /* @__PURE__ */ new Map(), on: function(t, e) {
|
|
1141
|
+
var i = n.get(t);
|
|
1142
|
+
i ? i.push(e) : n.set(t, [e]);
|
|
1143
|
+
}, off: function(t, e) {
|
|
1144
|
+
var i = n.get(t);
|
|
1145
|
+
i && (e ? i.splice(i.indexOf(e) >>> 0, 1) : n.set(t, []));
|
|
1146
|
+
}, emit: function(t, e) {
|
|
1147
|
+
var i = n.get(t);
|
|
1148
|
+
i && i.slice().map(function(n2) {
|
|
1149
|
+
n2(e);
|
|
1150
|
+
}), (i = n.get("*")) && i.slice().map(function(n2) {
|
|
1151
|
+
n2(t, e);
|
|
1152
|
+
});
|
|
1153
|
+
} };
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
// src/ts/bean/EventBus.ts
|
|
1157
|
+
var EventBus = class {
|
|
1158
|
+
_emitter = mitt_default();
|
|
1159
|
+
/** 订阅 */
|
|
1160
|
+
on(type, fn) {
|
|
1161
|
+
this._emitter.on(type, fn);
|
|
1162
|
+
return this;
|
|
1163
|
+
}
|
|
1164
|
+
/** 订阅一次 */
|
|
1165
|
+
once(type, fn) {
|
|
1166
|
+
const wrap2 = (event) => {
|
|
1167
|
+
this._emitter.off(type, wrap2);
|
|
1168
|
+
fn(event);
|
|
1169
|
+
};
|
|
1170
|
+
this._emitter.on(type, wrap2);
|
|
1171
|
+
return this;
|
|
1172
|
+
}
|
|
1173
|
+
/** 发布 */
|
|
1174
|
+
emit(type, event) {
|
|
1175
|
+
this._emitter.emit(type, event);
|
|
1176
|
+
return this;
|
|
1177
|
+
}
|
|
1178
|
+
/** 移除 */
|
|
1179
|
+
off(type, fn) {
|
|
1180
|
+
this._emitter.off(type, fn);
|
|
1181
|
+
return this;
|
|
1182
|
+
}
|
|
1183
|
+
/** 清空 */
|
|
1184
|
+
clear() {
|
|
1185
|
+
this._emitter.all.clear();
|
|
1186
|
+
return this;
|
|
1187
|
+
}
|
|
1188
|
+
};
|
|
1189
|
+
|
|
1137
1190
|
// src/ts/day/index.ts
|
|
1138
1191
|
var import_dayjs = __toESM(require_dayjs_min(), 1);
|
|
1139
1192
|
var import_customParseFormat = __toESM(require_customParseFormat(), 1);
|
|
@@ -4367,8 +4420,8 @@ var baseToolsTS = (() => {
|
|
|
4367
4420
|
var ListCache_default = ListCache;
|
|
4368
4421
|
|
|
4369
4422
|
// node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_Map.js
|
|
4370
|
-
var
|
|
4371
|
-
var Map_default =
|
|
4423
|
+
var Map2 = getNative_default(root_default, "Map");
|
|
4424
|
+
var Map_default = Map2;
|
|
4372
4425
|
|
|
4373
4426
|
// node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_mapCacheClear.js
|
|
4374
4427
|
function mapCacheClear() {
|
|
@@ -710,6 +710,7 @@ var baseToolsTS = (() => {
|
|
|
710
710
|
var ts_exports = {};
|
|
711
711
|
__export(ts_exports, {
|
|
712
712
|
BigNumber: () => bignumber_default,
|
|
713
|
+
EventBus: () => EventBus,
|
|
713
714
|
add: () => add_default,
|
|
714
715
|
after: () => after_default,
|
|
715
716
|
appendUrlParam: () => appendUrlParam,
|
|
@@ -1134,6 +1135,58 @@ var baseToolsTS = (() => {
|
|
|
1134
1135
|
}
|
|
1135
1136
|
}
|
|
1136
1137
|
|
|
1138
|
+
// node_modules/.pnpm/mitt@3.0.1/node_modules/mitt/dist/mitt.mjs
|
|
1139
|
+
function mitt_default(n) {
|
|
1140
|
+
return { all: n = n || /* @__PURE__ */ new Map(), on: function(t, e) {
|
|
1141
|
+
var i = n.get(t);
|
|
1142
|
+
i ? i.push(e) : n.set(t, [e]);
|
|
1143
|
+
}, off: function(t, e) {
|
|
1144
|
+
var i = n.get(t);
|
|
1145
|
+
i && (e ? i.splice(i.indexOf(e) >>> 0, 1) : n.set(t, []));
|
|
1146
|
+
}, emit: function(t, e) {
|
|
1147
|
+
var i = n.get(t);
|
|
1148
|
+
i && i.slice().map(function(n2) {
|
|
1149
|
+
n2(e);
|
|
1150
|
+
}), (i = n.get("*")) && i.slice().map(function(n2) {
|
|
1151
|
+
n2(t, e);
|
|
1152
|
+
});
|
|
1153
|
+
} };
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
// src/ts/bean/EventBus.ts
|
|
1157
|
+
var EventBus = class {
|
|
1158
|
+
_emitter = mitt_default();
|
|
1159
|
+
/** 订阅 */
|
|
1160
|
+
on(type, fn) {
|
|
1161
|
+
this._emitter.on(type, fn);
|
|
1162
|
+
return this;
|
|
1163
|
+
}
|
|
1164
|
+
/** 订阅一次 */
|
|
1165
|
+
once(type, fn) {
|
|
1166
|
+
const wrap2 = (event) => {
|
|
1167
|
+
this._emitter.off(type, wrap2);
|
|
1168
|
+
fn(event);
|
|
1169
|
+
};
|
|
1170
|
+
this._emitter.on(type, wrap2);
|
|
1171
|
+
return this;
|
|
1172
|
+
}
|
|
1173
|
+
/** 发布 */
|
|
1174
|
+
emit(type, event) {
|
|
1175
|
+
this._emitter.emit(type, event);
|
|
1176
|
+
return this;
|
|
1177
|
+
}
|
|
1178
|
+
/** 移除 */
|
|
1179
|
+
off(type, fn) {
|
|
1180
|
+
this._emitter.off(type, fn);
|
|
1181
|
+
return this;
|
|
1182
|
+
}
|
|
1183
|
+
/** 清空 */
|
|
1184
|
+
clear() {
|
|
1185
|
+
this._emitter.all.clear();
|
|
1186
|
+
return this;
|
|
1187
|
+
}
|
|
1188
|
+
};
|
|
1189
|
+
|
|
1137
1190
|
// src/ts/day/index.ts
|
|
1138
1191
|
var import_dayjs = __toESM(require_dayjs_min(), 1);
|
|
1139
1192
|
var import_customParseFormat = __toESM(require_customParseFormat(), 1);
|
|
@@ -4367,8 +4420,8 @@ var baseToolsTS = (() => {
|
|
|
4367
4420
|
var ListCache_default = ListCache;
|
|
4368
4421
|
|
|
4369
4422
|
// node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_Map.js
|
|
4370
|
-
var
|
|
4371
|
-
var Map_default =
|
|
4423
|
+
var Map2 = getNative_default(root_default, "Map");
|
|
4424
|
+
var Map_default = Map2;
|
|
4372
4425
|
|
|
4373
4426
|
// node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/_mapCacheClear.js
|
|
4374
4427
|
function mapCacheClear() {
|
package/dist/index.cjs
CHANGED
|
@@ -31,6 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
BigNumber: () => import_bignumber.default,
|
|
34
|
+
EventBus: () => EventBus,
|
|
34
35
|
add: () => add_default,
|
|
35
36
|
after: () => after_default,
|
|
36
37
|
appendUrlParam: () => appendUrlParam,
|
|
@@ -456,6 +457,41 @@ async function toAsync(p) {
|
|
|
456
457
|
}
|
|
457
458
|
}
|
|
458
459
|
|
|
460
|
+
// src/ts/bean/EventBus.ts
|
|
461
|
+
var import_mitt = __toESM(require("mitt"), 1);
|
|
462
|
+
var EventBus = class {
|
|
463
|
+
_emitter = (0, import_mitt.default)();
|
|
464
|
+
/** 订阅 */
|
|
465
|
+
on(type, fn) {
|
|
466
|
+
this._emitter.on(type, fn);
|
|
467
|
+
return this;
|
|
468
|
+
}
|
|
469
|
+
/** 订阅一次 */
|
|
470
|
+
once(type, fn) {
|
|
471
|
+
const wrap2 = (event) => {
|
|
472
|
+
this._emitter.off(type, wrap2);
|
|
473
|
+
fn(event);
|
|
474
|
+
};
|
|
475
|
+
this._emitter.on(type, wrap2);
|
|
476
|
+
return this;
|
|
477
|
+
}
|
|
478
|
+
/** 发布 */
|
|
479
|
+
emit(type, event) {
|
|
480
|
+
this._emitter.emit(type, event);
|
|
481
|
+
return this;
|
|
482
|
+
}
|
|
483
|
+
/** 移除 */
|
|
484
|
+
off(type, fn) {
|
|
485
|
+
this._emitter.off(type, fn);
|
|
486
|
+
return this;
|
|
487
|
+
}
|
|
488
|
+
/** 清空 */
|
|
489
|
+
clear() {
|
|
490
|
+
this._emitter.all.clear();
|
|
491
|
+
return this;
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
|
|
459
495
|
// src/ts/day/index.ts
|
|
460
496
|
var import_dayjs = __toESM(require("dayjs"), 1);
|
|
461
497
|
var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"), 1);
|
|
@@ -8531,6 +8567,7 @@ function isLongitude(s) {
|
|
|
8531
8567
|
// Annotate the CommonJS export names for ESM import in node:
|
|
8532
8568
|
0 && (module.exports = {
|
|
8533
8569
|
BigNumber,
|
|
8570
|
+
EventBus,
|
|
8534
8571
|
add,
|
|
8535
8572
|
after,
|
|
8536
8573
|
appendUrlParam,
|
package/dist/index.js
CHANGED
|
@@ -16,6 +16,41 @@ async function toAsync(p) {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
// src/ts/bean/EventBus.ts
|
|
20
|
+
import mitt from "mitt";
|
|
21
|
+
var EventBus = class {
|
|
22
|
+
_emitter = mitt();
|
|
23
|
+
/** 订阅 */
|
|
24
|
+
on(type, fn) {
|
|
25
|
+
this._emitter.on(type, fn);
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
/** 订阅一次 */
|
|
29
|
+
once(type, fn) {
|
|
30
|
+
const wrap2 = (event) => {
|
|
31
|
+
this._emitter.off(type, wrap2);
|
|
32
|
+
fn(event);
|
|
33
|
+
};
|
|
34
|
+
this._emitter.on(type, wrap2);
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
/** 发布 */
|
|
38
|
+
emit(type, event) {
|
|
39
|
+
this._emitter.emit(type, event);
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
/** 移除 */
|
|
43
|
+
off(type, fn) {
|
|
44
|
+
this._emitter.off(type, fn);
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
/** 清空 */
|
|
48
|
+
clear() {
|
|
49
|
+
this._emitter.all.clear();
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
19
54
|
// src/ts/day/index.ts
|
|
20
55
|
import dayjs from "dayjs";
|
|
21
56
|
import customParseFormat from "dayjs/plugin/customParseFormat";
|
|
@@ -8090,6 +8125,7 @@ function isLongitude(s) {
|
|
|
8090
8125
|
}
|
|
8091
8126
|
export {
|
|
8092
8127
|
BigNumber,
|
|
8128
|
+
EventBus,
|
|
8093
8129
|
add_default as add,
|
|
8094
8130
|
after_default as after,
|
|
8095
8131
|
appendUrlParam,
|
package/package.json
CHANGED
|
@@ -1,45 +1,46 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@base-web-kits/base-tools-ts",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"sideEffects": false,
|
|
5
|
-
"description": "Independent TS utilities package built from src/ts.",
|
|
6
|
-
"keywords": [
|
|
7
|
-
"base-tools",
|
|
8
|
-
"ts",
|
|
9
|
-
"utilities",
|
|
10
|
-
"thin-wrapper"
|
|
11
|
-
],
|
|
12
|
-
"license": "MIT",
|
|
13
|
-
"main": "./index.cjs",
|
|
14
|
-
"module": "./index.js",
|
|
15
|
-
"types": "./index.d.ts",
|
|
16
|
-
"typesVersions": {
|
|
17
|
-
"*": {
|
|
18
|
-
"*": [
|
|
19
|
-
"./dist/*"
|
|
20
|
-
],
|
|
21
|
-
"index": [
|
|
22
|
-
"./dist/index.d.ts"
|
|
23
|
-
]
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
"files": [
|
|
27
|
-
"dist",
|
|
28
|
-
"index.d.ts",
|
|
29
|
-
"index.js",
|
|
30
|
-
"index.cjs",
|
|
31
|
-
"base-tools-ts.umd.global.js",
|
|
32
|
-
"base-tools-ts.umd.global.js.map",
|
|
33
|
-
"README.md"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@base-web-kits/base-tools-ts",
|
|
3
|
+
"version": "0.9.3",
|
|
4
|
+
"sideEffects": false,
|
|
5
|
+
"description": "Independent TS utilities package built from src/ts.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"base-tools",
|
|
8
|
+
"ts",
|
|
9
|
+
"utilities",
|
|
10
|
+
"thin-wrapper"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"main": "./index.cjs",
|
|
14
|
+
"module": "./index.js",
|
|
15
|
+
"types": "./index.d.ts",
|
|
16
|
+
"typesVersions": {
|
|
17
|
+
"*": {
|
|
18
|
+
"*": [
|
|
19
|
+
"./dist/*"
|
|
20
|
+
],
|
|
21
|
+
"index": [
|
|
22
|
+
"./dist/index.d.ts"
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"index.d.ts",
|
|
29
|
+
"index.js",
|
|
30
|
+
"index.cjs",
|
|
31
|
+
"base-tools-ts.umd.global.js",
|
|
32
|
+
"base-tools-ts.umd.global.js.map",
|
|
33
|
+
"README.md",
|
|
34
|
+
"src"
|
|
35
|
+
],
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"lodash-es": "^4.17.21",
|
|
38
|
+
"@types/lodash-es": "^4.17.12",
|
|
39
|
+
"bignumber.js": "^9.1.2",
|
|
40
|
+
"dayjs": "^1.11.19",
|
|
41
|
+
"mitt": "^3.0.1"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"registry": "https://registry.npmjs.org"
|
|
45
|
+
}
|
|
46
|
+
}
|