@fe-free/tool 1.2.4 → 1.3.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/CHANGELOG.md +8 -0
- package/package.json +1 -1
- package/src/pinyin/pinyin.stories.tsx +40 -0
- package/src/url/url.stories.tsx +103 -0
- package/src/pinyin/index.md +0 -63
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -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
|
+
};
|
package/src/pinyin/index.md
DELETED
|
@@ -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
|
-
```
|