@windrun-huaiin/lib 30.0.0 → 31.0.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/README.md +111 -64
- package/package.json +7 -1
package/README.md
CHANGED
|
@@ -1,92 +1,139 @@
|
|
|
1
1
|
# @windrun-huaiin/lib
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A shared utility package for application configuration, class name composition, date formatting, i18n message handling, server-side locale message loading, and MDX-to-LLM text conversion.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Features
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
pnpm add @windrun-huaiin/lib
|
|
9
|
-
```
|
|
7
|
+
### Application Configuration
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
Create consistent runtime configuration for applications that share site settings, i18n behavior, visual preferences, authentication page URLs, and MDX content directory conventions.
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
Methods:
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
- `createCommonAppConfig`
|
|
14
|
+
- `createI18nHelpers`
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
console.log(appConfig.baseUrl);
|
|
16
|
+
Constants:
|
|
20
17
|
|
|
21
|
-
|
|
22
|
-
const locale = getValidLocale('zh');
|
|
23
|
-
```
|
|
18
|
+
- `LOCALE_PRESETS`
|
|
24
19
|
|
|
25
|
-
|
|
20
|
+
`createCommonAppConfig` builds a complete application config from explicit options, environment variables, and sensible defaults. It returns base site metadata, i18n settings, style settings, Clerk page settings, MDX source directory settings, and convenient shortcut fields for frequently used values.
|
|
26
21
|
|
|
27
|
-
|
|
28
|
-
import { cn, formatTimestamp } from '@windrun-huaiin/lib/utils';
|
|
22
|
+
`createI18nHelpers` creates helpers from an i18n config, including locale validation, fallback locale resolution, and generated locale display data.
|
|
29
23
|
|
|
30
|
-
|
|
31
|
-
const className = cn('text-red-500', 'font-bold');
|
|
24
|
+
`LOCALE_PRESETS` provides ready-made locale sets for common setups such as English-only, English and Chinese, Asian languages, European languages, global language coverage, and no multilingual setup.
|
|
32
25
|
|
|
33
|
-
|
|
34
|
-
const formatted = formatTimestamp('1640995200000', 'yyyy-MM-dd HH:mm:ss');
|
|
35
|
-
```
|
|
26
|
+
### Class Name Composition
|
|
36
27
|
|
|
37
|
-
|
|
28
|
+
Compose conditional class names and resolve Tailwind CSS class conflicts in React components.
|
|
38
29
|
|
|
39
|
-
|
|
40
|
-
import { Search, Check, X } from '@windrun-huaiin/lib/icons';
|
|
30
|
+
Method:
|
|
41
31
|
|
|
42
|
-
|
|
43
|
-
function MyComponent() {
|
|
44
|
-
return (
|
|
45
|
-
<div>
|
|
46
|
-
<Search className="w-4 h-4" />
|
|
47
|
-
<Check className="w-4 h-4 text-green-500" />
|
|
48
|
-
<X className="w-4 h-4 text-red-500" />
|
|
49
|
-
</div>
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
```
|
|
32
|
+
- `cn`
|
|
53
33
|
|
|
54
|
-
|
|
34
|
+
Typical uses:
|
|
55
35
|
|
|
56
|
-
|
|
57
|
-
|
|
36
|
+
- Merge default component styles with a consumer-provided `className`.
|
|
37
|
+
- Add classes conditionally based on component state.
|
|
38
|
+
- Keep the final effective Tailwind class when conflicting utilities are provided.
|
|
58
39
|
|
|
59
|
-
|
|
60
|
-
const result = await getLLMText(mdxContent, 'Title', 'Description');
|
|
61
|
-
```
|
|
40
|
+
### Date And Time Formatting
|
|
62
41
|
|
|
63
|
-
|
|
42
|
+
Format millisecond timestamps or Date objects into user-facing local time strings.
|
|
64
43
|
|
|
65
|
-
|
|
66
|
-
# 开发模式
|
|
67
|
-
pnpm dev
|
|
44
|
+
Methods:
|
|
68
45
|
|
|
69
|
-
|
|
70
|
-
|
|
46
|
+
- `formatTimestamp`
|
|
47
|
+
- `viewLocalTime`
|
|
71
48
|
|
|
72
|
-
|
|
73
|
-
pnpm typecheck
|
|
74
|
-
```
|
|
49
|
+
`formatTimestamp` accepts a millisecond timestamp string and a formatting pattern. It returns an empty string for missing values, invalid timestamps, or invalid dates.
|
|
75
50
|
|
|
76
|
-
|
|
51
|
+
`viewLocalTime` accepts a Date object or an empty value and returns local time in the `yyyy-MM-dd HH:mm:ss` format.
|
|
77
52
|
|
|
78
|
-
|
|
79
|
-
pnpm publish
|
|
80
|
-
```
|
|
53
|
+
### Plain Text Paste Handling
|
|
81
54
|
|
|
55
|
+
Intercept paste events in editable elements and insert only plain text, preventing external styles, rich text structure, or HTML content from being pasted.
|
|
82
56
|
|
|
83
|
-
|
|
57
|
+
Method:
|
|
84
58
|
|
|
85
|
-
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
-
|
|
90
|
-
-
|
|
91
|
-
-
|
|
92
|
-
|
|
59
|
+
- `handlePastePlainText`
|
|
60
|
+
|
|
61
|
+
Typical uses:
|
|
62
|
+
|
|
63
|
+
- Restrict pasted content in rich text editing areas.
|
|
64
|
+
- Keep `contenteditable` fields plain-text only.
|
|
65
|
+
- Prevent copied web content from bringing unwanted formatting into the editor.
|
|
66
|
+
|
|
67
|
+
### Localized URL Generation
|
|
68
|
+
|
|
69
|
+
Generate localized URLs from the current locale, target path, default locale, and locale prefix strategy.
|
|
70
|
+
|
|
71
|
+
Method:
|
|
72
|
+
|
|
73
|
+
- `getAsNeededLocalizedUrl`
|
|
74
|
+
|
|
75
|
+
Typical uses:
|
|
76
|
+
|
|
77
|
+
- Omit the locale prefix for the default locale.
|
|
78
|
+
- Add a locale prefix for non-default locales.
|
|
79
|
+
- Force locale prefixes for every locale.
|
|
80
|
+
- Normalize leading and trailing slashes consistently.
|
|
81
|
+
|
|
82
|
+
Example results:
|
|
83
|
+
|
|
84
|
+
- Default locale home page: `/`
|
|
85
|
+
- Chinese home page: `/zh`
|
|
86
|
+
- Default locale blog page: `/blog`
|
|
87
|
+
- Chinese blog page: `/zh/blog`
|
|
88
|
+
|
|
89
|
+
### I18n Message Merging
|
|
90
|
+
|
|
91
|
+
Identify plain objects and deeply merge multiple i18n message objects. Later values override earlier values, while nested objects are merged recursively.
|
|
92
|
+
|
|
93
|
+
Methods:
|
|
94
|
+
|
|
95
|
+
- `isPlainObject`
|
|
96
|
+
- `deepMergeMessages`
|
|
97
|
+
|
|
98
|
+
Typical uses:
|
|
99
|
+
|
|
100
|
+
- Merge base messages with feature-specific messages.
|
|
101
|
+
- Combine default copy with page-level copy.
|
|
102
|
+
- Compose messages from multiple modules in a larger application.
|
|
103
|
+
|
|
104
|
+
### Server-Side Locale Message Loading
|
|
105
|
+
|
|
106
|
+
Load and merge JSON message files for a locale on the server. It supports both single-file sources and directory sources. Directory sources are collected recursively, filtered by locale-specific file names, sorted, and merged in order.
|
|
107
|
+
|
|
108
|
+
Method:
|
|
109
|
+
|
|
110
|
+
- `loadMergedLocaleMessages`
|
|
111
|
+
|
|
112
|
+
Types:
|
|
113
|
+
|
|
114
|
+
- `RuntimeMessageSource`
|
|
115
|
+
- `RuntimeMessageFileSource`
|
|
116
|
+
- `RuntimeMessageDirectorySource`
|
|
117
|
+
|
|
118
|
+
Typical uses:
|
|
119
|
+
|
|
120
|
+
- Load messages for the active locale in a server-rendered application.
|
|
121
|
+
- Merge shared, page-level, and module-level messages into one object.
|
|
122
|
+
- Split locale messages by directory while exposing a single merged message object at runtime.
|
|
123
|
+
|
|
124
|
+
### MDX To LLM Text
|
|
125
|
+
|
|
126
|
+
Convert MDX content into Markdown text that is easier for language models to consume. Frontmatter is removed, while Markdown, MDX, and GFM content structure is preserved. Optional title and description values can be prepended to the output.
|
|
127
|
+
|
|
128
|
+
Method:
|
|
129
|
+
|
|
130
|
+
- `getLLMText`
|
|
131
|
+
|
|
132
|
+
Typical uses:
|
|
133
|
+
|
|
134
|
+
- Generate LLM-readable text from documentation, blog posts, or MDX pages.
|
|
135
|
+
- Prepare content for search, summarization, question answering, or indexing.
|
|
136
|
+
- Remove frontmatter so models do not read unrelated metadata.
|
|
137
|
+
|
|
138
|
+
## License
|
|
139
|
+
MIT License
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@windrun-huaiin/lib",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "31.0.0",
|
|
4
4
|
"description": "Common utilities and configuration",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -79,6 +79,12 @@
|
|
|
79
79
|
"publishConfig": {
|
|
80
80
|
"access": "public"
|
|
81
81
|
},
|
|
82
|
+
"homepage": "https://d8ger.com",
|
|
83
|
+
"repository": {
|
|
84
|
+
"type": "git",
|
|
85
|
+
"url": "git+https://github.com/caofanCPU/next-ai-build.git",
|
|
86
|
+
"directory": "packages/lib"
|
|
87
|
+
},
|
|
82
88
|
"scripts": {
|
|
83
89
|
"build": "rollup -c rollup.config.mjs",
|
|
84
90
|
"build:prod": "rollup -c rollup.config.mjs",
|