@windrun-huaiin/lib 11.0.0 → 12.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/dist/common-app-config.d.ts +1 -0
- package/dist/common-app-config.d.ts.map +1 -1
- package/dist/common-app-config.js +1 -0
- package/dist/common-app-config.mjs +1 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -1
- package/dist/utils.d.ts +1 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +17 -0
- package/dist/utils.mjs +17 -1
- package/package.json +1 -1
- package/src/common-app-config.ts +1 -0
- package/src/utils.ts +23 -1
|
@@ -47,6 +47,7 @@ export declare function createCommonAppConfig(options?: {
|
|
|
47
47
|
i18n: {
|
|
48
48
|
locales: readonly string[];
|
|
49
49
|
defaultLocale: string;
|
|
50
|
+
localPrefixAsNeeded: boolean;
|
|
50
51
|
localeLabels: {
|
|
51
52
|
[k: string]: "English" | "简体中文" | "日本語" | "한국어" | "Français" | "Deutsch" | "Español" | "Italiano" | "Português" | "Türkçe" | "Polski" | "Русский" | "العربية" | "हिन्दी" | "ไทย" | "Tiếng Việt";
|
|
52
53
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common-app-config.d.ts","sourceRoot":"","sources":["../src/common-app-config.ts"],"names":[],"mappings":"AACA,QAAA,MAAM,iBAAiB;;;;;;;;;;;;;;;;;CAiBb,CAAC;AAEX,MAAM,MAAM,eAAe,GAAG,MAAM,OAAO,iBAAiB,CAAC;AAa7D,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE;IAE9C,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;;;;;;;;;;;;;;;;;;;;;;;;;iBAqByB,SAAS,MAAM,EAAE
|
|
1
|
+
{"version":3,"file":"common-app-config.d.ts","sourceRoot":"","sources":["../src/common-app-config.ts"],"names":[],"mappings":"AACA,QAAA,MAAM,iBAAiB;;;;;;;;;;;;;;;;;CAiBb,CAAC;AAEX,MAAM,MAAM,eAAe,GAAG,MAAM,OAAO,iBAAiB,CAAC;AAa7D,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE;IAE9C,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;;;;;;;;;;;;;;;;;;;;;;;;;iBAqByB,SAAS,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiE1C;AAGD,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,UAAU,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC;gCACzD,MAAM,KAAG,MAAM,IAAI,CAAA,OAAO,UAAU,CAAC,OAAO,EAAC,MAAM,CAAC;6BAIvD,MAAM,KAAG,CAAA,OAAO,UAAU,CAAC,OAAO,EAAC,MAAM,CAAC;;;;;EAc3E;AAGD,eAAO,MAAM,cAAc;;iBAEK,MAAM,EAAE;uBAAyB,MAAM;;;iBAGnC,MAAM,EAAE;uBAAyB,MAAM;;;iBAG5B,MAAM,EAAE;uBAAyB,MAAM;;;iBAG/B,MAAM,EAAE;uBAAyB,MAAM;;;iBAGT,MAAM,EAAE;uBAAyB,MAAM;;;iBAGnG,MAAM,EAAE;uBAAyB,MAAM;;CAC/D,CAAC"}
|
|
@@ -43,6 +43,7 @@ function createCommonAppConfig(options) {
|
|
|
43
43
|
i18n: {
|
|
44
44
|
locales: locales,
|
|
45
45
|
defaultLocale,
|
|
46
|
+
localPrefixAsNeeded: process.env.NEXT_PUBLIC_I18N_LOCALE_PREFIX_AS_NEEDED !== 'false',
|
|
46
47
|
localeLabels: getLocaleLabels(locales),
|
|
47
48
|
detector: {
|
|
48
49
|
storageKey: process.env.NEXT_PUBLIC_I18N_STORAGE_KEY || 'language-preference-status',
|
|
@@ -41,6 +41,7 @@ function createCommonAppConfig(options) {
|
|
|
41
41
|
i18n: {
|
|
42
42
|
locales: locales,
|
|
43
43
|
defaultLocale,
|
|
44
|
+
localPrefixAsNeeded: process.env.NEXT_PUBLIC_I18N_LOCALE_PREFIX_AS_NEEDED !== 'false',
|
|
44
45
|
localeLabels: getLocaleLabels(locales),
|
|
45
46
|
detector: {
|
|
46
47
|
storageKey: process.env.NEXT_PUBLIC_I18N_STORAGE_KEY || 'language-preference-status',
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ var commonAppConfig = require('./common-app-config.js');
|
|
|
8
8
|
|
|
9
9
|
exports.cn = utils.cn;
|
|
10
10
|
exports.formatTimestamp = utils.formatTimestamp;
|
|
11
|
+
exports.getAsNeededLocalizedUrl = utils.getAsNeededLocalizedUrl;
|
|
11
12
|
exports.handlePastePlainText = utils.handlePastePlainText;
|
|
12
13
|
exports.viewLocalTime = utils.viewLocalTime;
|
|
13
14
|
exports.getLLMText = llmUtils.getLLMText;
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { cn, formatTimestamp, handlePastePlainText, viewLocalTime } from './utils.mjs';
|
|
1
|
+
export { cn, formatTimestamp, getAsNeededLocalizedUrl, handlePastePlainText, viewLocalTime } from './utils.mjs';
|
|
2
2
|
export { getLLMText } from './llm-utils.mjs';
|
|
3
3
|
export { LOCALE_PRESETS, createCommonAppConfig, createI18nHelpers } from './common-app-config.mjs';
|
package/dist/utils.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ export declare function cn(...inputs: ClassValue[]): string;
|
|
|
4
4
|
export declare function viewLocalTime(origin: Date | null): string;
|
|
5
5
|
export declare function formatTimestamp(timestamp: string, formatter: string): string;
|
|
6
6
|
export declare function handlePastePlainText(e: React.ClipboardEvent<HTMLElement>): void;
|
|
7
|
+
export declare function getAsNeededLocalizedUrl(locale: string, path: string, localPrefixAsNeeded?: boolean, defaultLocale?: string): string;
|
|
7
8
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;AACpC,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,MAAM,CAAA;AAI5C,wBAAgB,EAAE,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,UAEzC;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,IAAI,GAAG,IAAI,UAEhD;AAED,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,UA4BnE;AAGD,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,QAgBxE"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;AACpC,OAAO,EAAQ,KAAK,UAAU,EAAE,MAAM,MAAM,CAAA;AAI5C,wBAAgB,EAAE,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,UAEzC;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,IAAI,GAAG,IAAI,UAEhD;AAED,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,UA4BnE;AAGD,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,QAgBxE;AAYD,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,mBAAmB,GAAE,OAAc,EACnC,aAAa,GAAE,MAAa,GAC3B,MAAM,CAKR"}
|
package/dist/utils.js
CHANGED
|
@@ -56,8 +56,25 @@ function handlePastePlainText(e) {
|
|
|
56
56
|
selection.removeAllRanges();
|
|
57
57
|
selection.addRange(range);
|
|
58
58
|
}
|
|
59
|
+
// Generates localized URL based on locale and locale prefix configuration
|
|
60
|
+
// Supports both 'as-needed' and 'always' localePrefix configurations
|
|
61
|
+
// @param locale - Current locale (e.g., 'en', 'zh', 'ja')
|
|
62
|
+
// @param path - Base path (e.g., '/blog', '/docs')
|
|
63
|
+
// @param localPrefixAsNeeded - Whether localePrefix is set to 'as-needed' (default: true)
|
|
64
|
+
// @param defaultLocale - The default locale for the application (default: 'en')
|
|
65
|
+
// @example
|
|
66
|
+
// getAsNeededLocalizedUrl('en', '/blog', true, 'en') // Returns '/blog'
|
|
67
|
+
// getAsNeededLocalizedUrl('zh', '/blog', true, 'en') // Returns '/zh/blog'
|
|
68
|
+
// getAsNeededLocalizedUrl('en', '/blog', false, 'en') // Returns '/en/blog'
|
|
69
|
+
function getAsNeededLocalizedUrl(locale, path, localPrefixAsNeeded = true, defaultLocale = 'en') {
|
|
70
|
+
if (localPrefixAsNeeded && locale === defaultLocale) {
|
|
71
|
+
return path;
|
|
72
|
+
}
|
|
73
|
+
return `/${locale}${path}`;
|
|
74
|
+
}
|
|
59
75
|
|
|
60
76
|
exports.cn = cn;
|
|
61
77
|
exports.formatTimestamp = formatTimestamp;
|
|
78
|
+
exports.getAsNeededLocalizedUrl = getAsNeededLocalizedUrl;
|
|
62
79
|
exports.handlePastePlainText = handlePastePlainText;
|
|
63
80
|
exports.viewLocalTime = viewLocalTime;
|
package/dist/utils.mjs
CHANGED
|
@@ -54,5 +54,21 @@ function handlePastePlainText(e) {
|
|
|
54
54
|
selection.removeAllRanges();
|
|
55
55
|
selection.addRange(range);
|
|
56
56
|
}
|
|
57
|
+
// Generates localized URL based on locale and locale prefix configuration
|
|
58
|
+
// Supports both 'as-needed' and 'always' localePrefix configurations
|
|
59
|
+
// @param locale - Current locale (e.g., 'en', 'zh', 'ja')
|
|
60
|
+
// @param path - Base path (e.g., '/blog', '/docs')
|
|
61
|
+
// @param localPrefixAsNeeded - Whether localePrefix is set to 'as-needed' (default: true)
|
|
62
|
+
// @param defaultLocale - The default locale for the application (default: 'en')
|
|
63
|
+
// @example
|
|
64
|
+
// getAsNeededLocalizedUrl('en', '/blog', true, 'en') // Returns '/blog'
|
|
65
|
+
// getAsNeededLocalizedUrl('zh', '/blog', true, 'en') // Returns '/zh/blog'
|
|
66
|
+
// getAsNeededLocalizedUrl('en', '/blog', false, 'en') // Returns '/en/blog'
|
|
67
|
+
function getAsNeededLocalizedUrl(locale, path, localPrefixAsNeeded = true, defaultLocale = 'en') {
|
|
68
|
+
if (localPrefixAsNeeded && locale === defaultLocale) {
|
|
69
|
+
return path;
|
|
70
|
+
}
|
|
71
|
+
return `/${locale}${path}`;
|
|
72
|
+
}
|
|
57
73
|
|
|
58
|
-
export { cn, formatTimestamp, handlePastePlainText, viewLocalTime };
|
|
74
|
+
export { cn, formatTimestamp, getAsNeededLocalizedUrl, handlePastePlainText, viewLocalTime };
|
package/package.json
CHANGED
package/src/common-app-config.ts
CHANGED
|
@@ -58,6 +58,7 @@ export function createCommonAppConfig(options?: {
|
|
|
58
58
|
i18n: {
|
|
59
59
|
locales: locales as readonly string[],
|
|
60
60
|
defaultLocale,
|
|
61
|
+
localPrefixAsNeeded: process.env.NEXT_PUBLIC_I18N_LOCALE_PREFIX_AS_NEEDED !== 'false',
|
|
61
62
|
localeLabels: getLocaleLabels(locales),
|
|
62
63
|
detector: {
|
|
63
64
|
storageKey: process.env.NEXT_PUBLIC_I18N_STORAGE_KEY || 'language-preference-status',
|
package/src/utils.ts
CHANGED
|
@@ -39,7 +39,7 @@ export function formatTimestamp(timestamp: string, formatter: string) {
|
|
|
39
39
|
console.error("Error formatting date:", error);
|
|
40
40
|
return fail;
|
|
41
41
|
}
|
|
42
|
-
}
|
|
42
|
+
}
|
|
43
43
|
|
|
44
44
|
// Only allow pasting plain text, prohibit style content
|
|
45
45
|
export function handlePastePlainText(e: React.ClipboardEvent<HTMLElement>) {
|
|
@@ -58,4 +58,26 @@ export function handlePastePlainText(e: React.ClipboardEvent<HTMLElement>) {
|
|
|
58
58
|
range.collapse(true);
|
|
59
59
|
selection.removeAllRanges();
|
|
60
60
|
selection.addRange(range);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Generates localized URL based on locale and locale prefix configuration
|
|
64
|
+
// Supports both 'as-needed' and 'always' localePrefix configurations
|
|
65
|
+
// @param locale - Current locale (e.g., 'en', 'zh', 'ja')
|
|
66
|
+
// @param path - Base path (e.g., '/blog', '/docs')
|
|
67
|
+
// @param localPrefixAsNeeded - Whether localePrefix is set to 'as-needed' (default: true)
|
|
68
|
+
// @param defaultLocale - The default locale for the application (default: 'en')
|
|
69
|
+
// @example
|
|
70
|
+
// getAsNeededLocalizedUrl('en', '/blog', true, 'en') // Returns '/blog'
|
|
71
|
+
// getAsNeededLocalizedUrl('zh', '/blog', true, 'en') // Returns '/zh/blog'
|
|
72
|
+
// getAsNeededLocalizedUrl('en', '/blog', false, 'en') // Returns '/en/blog'
|
|
73
|
+
export function getAsNeededLocalizedUrl(
|
|
74
|
+
locale: string,
|
|
75
|
+
path: string,
|
|
76
|
+
localPrefixAsNeeded: boolean = true,
|
|
77
|
+
defaultLocale: string = 'en'
|
|
78
|
+
): string {
|
|
79
|
+
if (localPrefixAsNeeded && locale === defaultLocale) {
|
|
80
|
+
return path;
|
|
81
|
+
}
|
|
82
|
+
return `/${locale}${path}`;
|
|
61
83
|
}
|