@fe-free/tool 1.2.3 → 1.3.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @fe-free/tool
2
2
 
3
+ ## 1.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - feat: some
8
+
9
+ ## 1.2.4
10
+
11
+ ### Patch Changes
12
+
13
+ - feat: useGlobalRequest
14
+
3
15
  ## 1.2.3
4
16
 
5
17
  ## 1.2.2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fe-free/tool",
3
- "version": "1.2.3",
3
+ "version": "1.3.0",
4
4
  "description": "",
5
5
  "main": "./src/index.ts",
6
6
  "author": "",
@@ -12,7 +12,9 @@
12
12
  "dependencies": {
13
13
  "lodash-es": "^4.17.21"
14
14
  },
15
- "peerDependencies": {},
15
+ "peerDependencies": {
16
+ "ahooks": "^3.8.4"
17
+ },
16
18
  "scripts": {
17
19
  "test": "echo \"Error: no test specified\" && exit 1"
18
20
  }
package/src/index.ts CHANGED
@@ -2,4 +2,6 @@ export { pinyin, pinyinFilter, pinyinMatch, pinyinMatchWithoutFirstLetter } from
2
2
 
3
3
  export { getDayjs } from './date';
4
4
 
5
+ export { useGlobalRequest } from './use_global_request';
6
+
5
7
  export { buildURL } from './url';
@@ -0,0 +1,40 @@
1
+ import { pinyin, pinyinFilter, pinyinMatch } from '@fe-free/tool';
2
+ import type { Meta, StoryObj } from '@storybook/react';
3
+
4
+ const meta: Meta = {
5
+ title: '@fe-free/tool/Pinyin',
6
+ tags: ['autodocs'],
7
+ };
8
+
9
+ export default meta;
10
+ type Story = StoryObj;
11
+
12
+ // 基础拼音转换
13
+ export const Basic: Story = {
14
+ render: () => <div>{pinyin('你好')}</div>,
15
+ };
16
+
17
+ // 首字母拼音
18
+ export const FirstLetter: Story = {
19
+ render: () => <div>{pinyin('你好', 'first_letter')}</div>,
20
+ };
21
+
22
+ // 拼音匹配
23
+ export const PinyinMatch: Story = {
24
+ render: () => (
25
+ <>
26
+ <div>匹配结果: {pinyinMatch('你好', 'nh') + ''}</div>
27
+ <div>不匹配结果: {pinyinMatch('你好', 'wo') + ''}</div>
28
+ </>
29
+ ),
30
+ };
31
+
32
+ // 拼音过滤
33
+ export const PinyinFilter: Story = {
34
+ render: () => (
35
+ <>
36
+ <div>过滤结果: {pinyinFilter(['你好', '我们'], 'nh')}</div>
37
+ <div>过滤结果: {pinyinFilter(['你好', '我们'], 'wo')}</div>
38
+ </>
39
+ ),
40
+ };
@@ -0,0 +1,103 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { buildURL } from './index';
3
+
4
+ const meta: Meta = {
5
+ title: '@fe-free/tool/URL',
6
+ tags: ['autodocs'],
7
+ };
8
+
9
+ export default meta;
10
+ type Story = StoryObj;
11
+
12
+ // 基础 URL 构建
13
+ export const Basic: Story = {
14
+ render: () => {
15
+ const url = 'https://example.com/path';
16
+ const result = buildURL(url);
17
+ return (
18
+ <div>
19
+ <p>原始 URL: {url}</p>
20
+ <p>构建后: {result}</p>
21
+ </div>
22
+ );
23
+ },
24
+ };
25
+
26
+ // 添加查询参数
27
+ export const WithSearchParams: Story = {
28
+ render: () => {
29
+ const url = 'https://example.com/path';
30
+ const result = buildURL(url, {
31
+ searchParams: {
32
+ name: 'test',
33
+ age: 18,
34
+ },
35
+ });
36
+ return (
37
+ <div>
38
+ <p>原始 URL: {url}</p>
39
+ <p>添加查询参数后: {result}</p>
40
+ </div>
41
+ );
42
+ },
43
+ };
44
+
45
+ // 合并查询参数
46
+ export const MergeSearchParams: Story = {
47
+ render: () => {
48
+ const url = 'https://example.com/path?existing=value';
49
+ const result = buildURL(url, {
50
+ searchParams: {
51
+ newParam: 'newValue',
52
+ },
53
+ });
54
+ return (
55
+ <div>
56
+ <p>原始 URL: {url}</p>
57
+ <p>合并查询参数后: {result}</p>
58
+ </div>
59
+ );
60
+ },
61
+ };
62
+
63
+ // 添加 hash 查询参数
64
+ export const WithHashSearchParams: Story = {
65
+ render: () => {
66
+ const url = 'https://example.com/path#section';
67
+ const result = buildURL(url, {
68
+ hashSearchParams: {
69
+ tab: 'details',
70
+ view: 'list',
71
+ },
72
+ });
73
+ return (
74
+ <div>
75
+ <p>原始 URL: {url}</p>
76
+ <p>添加 hash 查询参数后: {result}</p>
77
+ </div>
78
+ );
79
+ },
80
+ };
81
+
82
+ // 复杂场景:同时处理查询参数和 hash 查询参数
83
+ export const Complex: Story = {
84
+ render: () => {
85
+ const url = 'https://example.com/path?page=1#section?tab=main';
86
+ const result = buildURL(url, {
87
+ searchParams: {
88
+ sort: 'desc',
89
+ filter: 'active',
90
+ },
91
+ hashSearchParams: {
92
+ view: 'grid',
93
+ theme: 'dark',
94
+ },
95
+ });
96
+ return (
97
+ <div>
98
+ <p>原始 URL: {url}</p>
99
+ <p>复杂处理后: {result}</p>
100
+ </div>
101
+ );
102
+ },
103
+ };
@@ -0,0 +1,26 @@
1
+ import { useRequest } from 'ahooks';
2
+ import type { Options, Plugin, Service } from 'ahooks/es/useRequest/src/types';
3
+
4
+ function useGlobalRequest<TData, TParams extends any[]>(
5
+ service: Service<TData, TParams>,
6
+ options?: Options<TData, TParams>,
7
+ plugins?: Plugin<TData, TParams>[]
8
+ ) {
9
+ return useRequest(
10
+ service,
11
+ {
12
+ onError: (error) => {
13
+ // 全局抛出错误
14
+ setTimeout(() => {
15
+ throw error;
16
+ }, 0);
17
+ },
18
+ ...options,
19
+ // @ts-ignore
20
+ __ignore: true,
21
+ },
22
+ plugins
23
+ );
24
+ }
25
+
26
+ export { useGlobalRequest };
@@ -1,63 +0,0 @@
1
- ---
2
- nav:
3
- title: '组件'
4
- order: 15
5
- group: 'tool'
6
- toc: content
7
- ---
8
-
9
- # pinyin
10
-
11
- 将汉字转换为拼音
12
-
13
- ## 场景
14
-
15
- 输出拼音
16
-
17
- ```tsx
18
- import { pinyin } from '@fe-free/tool';
19
-
20
- export default () => {
21
- return <div>{pinyin('你好')}</div>;
22
- };
23
- ```
24
-
25
- 输出首拼音
26
-
27
- ```tsx
28
- import { pinyin } from '@fe-free/tool';
29
-
30
- export default () => {
31
- return <div>{pinyin('你好', 'first_letter')} </div>;
32
- };
33
- ```
34
-
35
- 匹配
36
-
37
- ```tsx
38
- import { pinyinMatch } from '@fe-free/tool';
39
-
40
- export default () => {
41
- return (
42
- <>
43
- <div>{pinyinMatch('你好', 'nh') + ''}</div>
44
- <div>{pinyinMatch('你好', 'wo') + ''} </div>
45
- </>
46
- );
47
- };
48
- ```
49
-
50
- 过滤
51
-
52
- ```tsx
53
- import { pinyinFilter } from '@fe-free/tool';
54
-
55
- export default () => {
56
- return (
57
- <>
58
- <div>{pinyinFilter(['你好', ' 我们'], 'nh')} </div>
59
- <div>{pinyinFilter(['你好', ' 我们'], 'wo')} </div>
60
- </>
61
- );
62
- };
63
- ```