@fluojs/i18n 1.0.0 → 1.0.2
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.ko.md +3 -3
- package/README.md +3 -3
- package/dist/adapters.d.ts.map +1 -1
- package/dist/adapters.js +4 -3
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +4 -3
- package/dist/locale-resolution.d.ts +10 -2
- package/dist/locale-resolution.d.ts.map +1 -1
- package/dist/locale-resolution.js +18 -3
- package/package.json +4 -4
package/README.ko.md
CHANGED
|
@@ -199,7 +199,7 @@ Adapter는 의도적으로 explicit합니다:
|
|
|
199
199
|
- `setHttpLocale(ctx, locale, metadata)`는 `createContextKey(...)`를 사용해 현재 `RequestContext`에 locale metadata를 저장합니다.
|
|
200
200
|
- `getHttpLocale(ctx)`는 global fallback 없이 metadata를 읽습니다.
|
|
201
201
|
- `parseAcceptLanguage(header)`는 q-value 순서로 valid `Accept-Language` range를 parse하고 invalid 또는 q=0 entry를 무시합니다.
|
|
202
|
-
- `createAcceptLanguageLocaleResolver(...)`는 request header에서 첫 번째 supported locale을
|
|
202
|
+
- `createAcceptLanguageLocaleResolver(...)`는 request header에서 첫 번째 supported locale을 선택하고, language range를 case-insensitive로 match하며, match되면 configured `supportedLocales` spelling을 반환합니다.
|
|
203
203
|
- `createAcceptLanguageLocalePolicyResolver(...)`는 opt-in이며, `en-US` 같은 regional range를 supported `en`으로 normalize하거나 explicit supported range를 모두 확인한 뒤 wildcard fallback을 선택할 수 있습니다.
|
|
204
204
|
- `resolveHttpLocale(ctx, options)`는 application-provided resolver를 배열 순서대로 실행하고 invalid 또는 unsupported resolver output을 무시하며, 아무 resolver도 match하지 않으면 `defaultLocale`을 source `default`로 저장합니다.
|
|
205
205
|
|
|
@@ -264,7 +264,7 @@ Generic adapter contract는 의도적으로 explicit합니다.
|
|
|
264
264
|
- `resolveLocale(context, options)`는 application-provided resolver를 배열 순서대로 실행하고 empty, invalid, unsupported resolver output을 무시하며, 아무 것도 match하지 않으면 `defaultLocale`을 source `default`로 반환합니다.
|
|
265
265
|
- `bindLocale(context, { store, ...options })`는 locale을 resolve한 뒤 application-provided `LocaleAdapterStore`에 immutable metadata를 저장합니다.
|
|
266
266
|
- `createWeakMapLocaleStore()`는 socket, call, session, request object를 mutate하지 않고 per-object metadata storage를 제공합니다.
|
|
267
|
-
- `createHeaderLocaleResolver(...)`는 HTTP adapter와 같은 q-value
|
|
267
|
+
- `createHeaderLocaleResolver(...)`는 HTTP adapter와 같은 q-value, wildcard 동작, case-insensitive matching, supported-locale spelling preservation으로 `Accept-Language` style 값을 parse합니다.
|
|
268
268
|
- `createHeaderLocalePolicyResolver(...)`는 HTTP type을 import하지 않고 동일한 opt-in regional-locale normalization 및 wildcard fallback policy를 제공합니다.
|
|
269
269
|
- `createQueryLocaleResolver(...)`, `createCookieLocaleResolver(...)`, `createStorageLocaleResolver(...)`는 caller-owned abstraction에서 locale candidate를 읽고 browser global이나 framework internal에는 접근하지 않습니다.
|
|
270
270
|
|
|
@@ -420,7 +420,7 @@ typedI18n.translateInNamespace('admin/common', 'dashboard.title', { locale: 'en'
|
|
|
420
420
|
| Export | 설명 |
|
|
421
421
|
|---|---|
|
|
422
422
|
| `I18nModule` | DI 등록을 위한 모듈입니다. |
|
|
423
|
-
| `I18nService` |
|
|
423
|
+
| `I18nService` | Detached option/catalog snapshot을 소유하고 translation을 resolve하며 explicit-locale `Intl` formatting helper(`formatDateTime`, `formatNumber`, `formatCurrency`, `formatPercent`, `formatList`, `formatRelativeTime`)를 제공하는 core service입니다. |
|
|
424
424
|
| `createI18n` | 독립형 서비스를 생성하기 위한 헬퍼입니다. |
|
|
425
425
|
| `I18nError` | 패키지 전용 에러 클래스입니다. |
|
|
426
426
|
|
package/README.md
CHANGED
|
@@ -199,7 +199,7 @@ The adapter is intentionally explicit:
|
|
|
199
199
|
- `setHttpLocale(ctx, locale, metadata)` stores locale metadata on the current `RequestContext` using `createContextKey(...)`.
|
|
200
200
|
- `getHttpLocale(ctx)` reads the metadata without falling back to globals.
|
|
201
201
|
- `parseAcceptLanguage(header)` parses valid `Accept-Language` ranges by q-value and ignores invalid or q=0 entries.
|
|
202
|
-
- `createAcceptLanguageLocaleResolver(...)` selects the first supported locale from the request header.
|
|
202
|
+
- `createAcceptLanguageLocaleResolver(...)` selects the first supported locale from the request header, matches language ranges case-insensitively, and returns the configured `supportedLocales` spelling when a match is found.
|
|
203
203
|
- `createAcceptLanguageLocalePolicyResolver(...)` is opt-in and can normalize regional ranges such as `en-US` to supported `en` or select a wildcard fallback only after explicit supported ranges are exhausted.
|
|
204
204
|
- `resolveHttpLocale(ctx, options)` runs application-provided resolvers in order, ignores invalid or unsupported resolver output, and stores `defaultLocale` with source `default` when nothing matches.
|
|
205
205
|
|
|
@@ -264,7 +264,7 @@ The generic adapter contract is intentionally explicit:
|
|
|
264
264
|
- `resolveLocale(context, options)` runs application-provided resolvers in order, ignores empty, invalid, and unsupported resolver output, and returns `defaultLocale` with source `default` when nothing matches.
|
|
265
265
|
- `bindLocale(context, { store, ...options })` resolves a locale and stores immutable metadata in an application-provided `LocaleAdapterStore`.
|
|
266
266
|
- `createWeakMapLocaleStore()` provides per-object metadata storage for socket, call, session, or request objects without mutating those objects.
|
|
267
|
-
- `createHeaderLocaleResolver(...)` parses `Accept-Language`-style values with the same q-value
|
|
267
|
+
- `createHeaderLocaleResolver(...)` parses `Accept-Language`-style values with the same q-value, wildcard behavior, case-insensitive matching, and supported-locale spelling preservation as the HTTP adapter.
|
|
268
268
|
- `createHeaderLocalePolicyResolver(...)` provides the same opt-in regional-locale normalization and wildcard fallback policy without importing HTTP types.
|
|
269
269
|
- `createQueryLocaleResolver(...)`, `createCookieLocaleResolver(...)`, and `createStorageLocaleResolver(...)` read locale candidates from caller-owned abstractions and never access browser globals or framework internals.
|
|
270
270
|
|
|
@@ -420,7 +420,7 @@ Both helpers deduplicate keys across locales, sort output for stable diffs, reje
|
|
|
420
420
|
| Export | Description |
|
|
421
421
|
|---|---|
|
|
422
422
|
| `I18nModule` | Module facade for registering the core i18n service surface. |
|
|
423
|
-
| `I18nService` | Core service that owns detached options/catalog snapshots and
|
|
423
|
+
| `I18nService` | Core service that owns detached options/catalog snapshots, resolves translations, and exposes explicit-locale `Intl` formatting helpers (`formatDateTime`, `formatNumber`, `formatCurrency`, `formatPercent`, `formatList`, `formatRelativeTime`). |
|
|
424
424
|
| `createI18n(options)` | Creates a standalone `I18nService` without module registration. |
|
|
425
425
|
| `I18nError` | Base i18n package error with a stable error code. |
|
|
426
426
|
|
package/dist/adapters.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapters.d.ts","sourceRoot":"","sources":["../src/adapters.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,iCAAiC,
|
|
1
|
+
{"version":3,"file":"adapters.d.ts","sourceRoot":"","sources":["../src/adapters.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,iCAAiC,EAOvC,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,8CAA8C;IAC9C,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,qFAAqF;IACrF,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B,CAAC,QAAQ;IAClD,uEAAuE;IACvE,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;IAC3B,gGAAgG;IAChG,QAAQ,CAAC,gBAAgB,CAAC,EAAE,SAAS,UAAU,EAAE,CAAC;IAClD,uEAAuE;IACvE,QAAQ,CAAC,aAAa,EAAE,UAAU,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,uCAAuC;IACvC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,4EAA4E;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AAa,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,oBAAoB,CAAC,QAAQ,CAAC,GAAG,oBAAoB,CAsBxH;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,iBAAiB,CAAC,QAAQ,CAAC,GAAG,oBAAoB,CAIlH;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,QAAQ,EACjD,OAAO,EAAE,2BAA2B,CAAC,QAAQ,CAAC,GAC7C,qBAAqB,CAAC,QAAQ,CAAC,CAkBjC;AAED;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAAC,QAAQ,EACvD,OAAO,EAAE,iCAAiC,CAAC,QAAQ,CAAC,GACnD,qBAAqB,CAAC,QAAQ,CAAC,CAiBjC;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAChD,OAAO,EAAE,0BAA0B,CAAC,QAAQ,CAAC,GAC5C,qBAAqB,CAAC,QAAQ,CAAC,CAajC;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,QAAQ,EACjD,OAAO,EAAE,2BAA2B,CAAC,QAAQ,CAAC,GAC7C,qBAAqB,CAAC,QAAQ,CAAC,CAYjC;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,QAAQ,EAClD,OAAO,EAAE,4BAA4B,CAAC,QAAQ,CAAC,GAC9C,qBAAqB,CAAC,QAAQ,CAAC,CAYjC"}
|
package/dist/adapters.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isSupportedLocale, isValidLocale, normalizeLocaleResolverResult, parseLocalePreferences, selectLocaleFromAcceptLanguagePolicy } from './locale-resolution.js';
|
|
1
|
+
import { isSupportedLocale, isValidLocale, normalizeLocaleResolverResult, parseLocalePreferences, resolveSupportedLocale, selectLocaleFromAcceptLanguagePolicy } from './locale-resolution.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Locale metadata resolved for a non-HTTP transport context.
|
|
@@ -160,9 +160,10 @@ export function createHeaderLocaleResolver(options) {
|
|
|
160
160
|
if (preference.locale === '*') {
|
|
161
161
|
continue;
|
|
162
162
|
}
|
|
163
|
-
|
|
163
|
+
const locale = resolveSupportedLocale(preference.locale, supportedLocales);
|
|
164
|
+
if (locale !== undefined) {
|
|
164
165
|
return {
|
|
165
|
-
locale
|
|
166
|
+
locale,
|
|
166
167
|
source
|
|
167
168
|
};
|
|
168
169
|
}
|
package/dist/http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,cAAc,EAEpB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,KAAK,iCAAiC,
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,cAAc,EAEpB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,KAAK,iCAAiC,EAOvC,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,8CAA8C;IAC9C,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,qFAAqF;IACrF,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,mEAAmE;IACnE,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,0CAA0C;IAC1C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,8CAA8C;IAC9C,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,gGAAgG;IAChG,Q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mB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,GAAG,SAAS,GAAG,SAAS,wBAAwB,EAAE,CAEvH;AAED;;;;;GAKG;AACH,wBAAgB,kCAAkC,CAChD,OAAO,GAAE,mCAAwC,GAChD,kBAAkB,CAsBpB;AAED;;;;;GAKG;AACH,wBAAgB,wCAAwC,CACtD,OAAO,GAAE,yCAA8C,GACtD,kBAAkB,CAkBpB;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,wBAAwB,GAAG,iBAAiB,CAwB/G"}
|
package/dist/http.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createContextKey, getContextValue, setContextValue } from '@fluojs/http';
|
|
2
|
-
import { isSupportedLocale, isValidLocale, normalizeLocaleResolverResult, parseLocalePreferences, selectLocaleFromAcceptLanguagePolicy } from './locale-resolution.js';
|
|
2
|
+
import { isSupportedLocale, isValidLocale, normalizeLocaleResolverResult, parseLocalePreferences, resolveSupportedLocale, selectLocaleFromAcceptLanguagePolicy } from './locale-resolution.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Locale metadata stored on a fluo HTTP request context.
|
|
@@ -101,9 +101,10 @@ export function createAcceptLanguageLocaleResolver(options = {}) {
|
|
|
101
101
|
if (preference.locale === '*') {
|
|
102
102
|
continue;
|
|
103
103
|
}
|
|
104
|
-
|
|
104
|
+
const locale = resolveSupportedLocale(preference.locale, supportedLocales);
|
|
105
|
+
if (locale !== undefined) {
|
|
105
106
|
return {
|
|
106
|
-
locale
|
|
107
|
+
locale,
|
|
107
108
|
source
|
|
108
109
|
};
|
|
109
110
|
}
|
|
@@ -43,13 +43,21 @@ export interface AcceptLanguageLocalePolicyOptions {
|
|
|
43
43
|
*/
|
|
44
44
|
export declare function isValidLocale(locale: unknown): locale is I18nLocale;
|
|
45
45
|
/**
|
|
46
|
-
* Checks whether a valid locale
|
|
46
|
+
* Checks whether a valid locale exactly matches an optional supported-locale list.
|
|
47
47
|
*
|
|
48
48
|
* @param locale Locale identifier to check.
|
|
49
49
|
* @param supportedLocales Optional list of supported locale identifiers.
|
|
50
|
-
* @returns Whether the locale is supported, or `true` when no supported-locale list is configured.
|
|
50
|
+
* @returns Whether the locale is supported with identical spelling, or `true` when no supported-locale list is configured.
|
|
51
51
|
*/
|
|
52
52
|
export declare function isSupportedLocale(locale: I18nLocale, supportedLocales: readonly I18nLocale[] | undefined): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Resolves a valid locale candidate to the caller-configured supported locale spelling with case-insensitive matching.
|
|
55
|
+
*
|
|
56
|
+
* @param locale Locale identifier to check.
|
|
57
|
+
* @param supportedLocales Optional list of supported locale identifiers.
|
|
58
|
+
* @returns The matching supported locale spelling, the original locale when no list is configured, or `undefined` when unsupported.
|
|
59
|
+
*/
|
|
60
|
+
export declare function resolveSupportedLocale(locale: I18nLocale, supportedLocales: readonly I18nLocale[] | undefined): I18nLocale | undefined;
|
|
53
61
|
/**
|
|
54
62
|
* Normalizes a valid locale candidate to the configured supported locale surface.
|
|
55
63
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locale-resolution.d.ts","sourceRoot":"","sources":["../src/locale-resolution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,gCAAgC;IAC/C,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,wDAAwD;IACxD,QAAQ,CAAC,aAAa,EAAE,UAAU,CAAC;IACn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UAAU,EAAE,GAAG,SAAS,GAClD,UAAU,GAAG,SAAS,CAOxB;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,UAAU,EAClB,gBAAgB,EAAE,SAAS,UAAU,EAAE,GAAG,SAAS,EACnD,oBAAoB,UAAO,GAC1B,UAAU,GAAG,SAAS,CA4BxB;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,OAAO,GAAG,uBAAuB,GAAG,SAAS,CAoBlG;AA2BD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,GAAG,SAAS,GAAG,SAAS,gCAAgC,EAAE,CA2BlI;AAkBD;;;;;;;;GAQG;AACH,wBAAgB,oCAAoC,CAClD,WAAW,EAAE,SAAS,gCAAgC,EAAE,EACxD,aAAa,EAAE,UAAU,EACzB,gBAAgB,EAAE,SAAS,UAAU,EAAE,GAAG,SAAS,EACnD,OAAO,GAAE,iCAAsC,GAC9C,UAAU,GAAG,SAAS,CA4BxB"}
|
|
@@ -32,16 +32,31 @@ export function isValidLocale(locale) {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
* Checks whether a valid locale
|
|
35
|
+
* Checks whether a valid locale exactly matches an optional supported-locale list.
|
|
36
36
|
*
|
|
37
37
|
* @param locale Locale identifier to check.
|
|
38
38
|
* @param supportedLocales Optional list of supported locale identifiers.
|
|
39
|
-
* @returns Whether the locale is supported, or `true` when no supported-locale list is configured.
|
|
39
|
+
* @returns Whether the locale is supported with identical spelling, or `true` when no supported-locale list is configured.
|
|
40
40
|
*/
|
|
41
41
|
export function isSupportedLocale(locale, supportedLocales) {
|
|
42
42
|
return supportedLocales === undefined || supportedLocales.length === 0 || supportedLocales.includes(locale);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Resolves a valid locale candidate to the caller-configured supported locale spelling with case-insensitive matching.
|
|
47
|
+
*
|
|
48
|
+
* @param locale Locale identifier to check.
|
|
49
|
+
* @param supportedLocales Optional list of supported locale identifiers.
|
|
50
|
+
* @returns The matching supported locale spelling, the original locale when no list is configured, or `undefined` when unsupported.
|
|
51
|
+
*/
|
|
52
|
+
export function resolveSupportedLocale(locale, supportedLocales) {
|
|
53
|
+
if (supportedLocales === undefined || supportedLocales.length === 0) {
|
|
54
|
+
return locale;
|
|
55
|
+
}
|
|
56
|
+
const normalizedLocale = locale.toLowerCase();
|
|
57
|
+
return supportedLocales.find(supportedLocale => supportedLocale.toLowerCase() === normalizedLocale);
|
|
58
|
+
}
|
|
59
|
+
|
|
45
60
|
/**
|
|
46
61
|
* Normalizes a valid locale candidate to the configured supported locale surface.
|
|
47
62
|
*
|
|
@@ -55,7 +70,7 @@ export function normalizeSupportedLocale(locale, supportedLocales, allowBaseLoca
|
|
|
55
70
|
return locale;
|
|
56
71
|
}
|
|
57
72
|
const normalizedLocale = locale.toLowerCase();
|
|
58
|
-
const exact =
|
|
73
|
+
const exact = resolveSupportedLocale(locale, supportedLocales);
|
|
59
74
|
if (exact !== undefined) {
|
|
60
75
|
return exact;
|
|
61
76
|
}
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"localization",
|
|
9
9
|
"translations"
|
|
10
10
|
],
|
|
11
|
-
"version": "1.0.
|
|
11
|
+
"version": "1.0.2",
|
|
12
12
|
"private": false,
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"repository": {
|
|
@@ -63,12 +63,12 @@
|
|
|
63
63
|
"dist"
|
|
64
64
|
],
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@fluojs/core": "^1.0.
|
|
66
|
+
"@fluojs/core": "^1.0.2"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
69
|
"intl-messageformat": "^11.2.4",
|
|
70
70
|
"@fluojs/http": "^1.0.0",
|
|
71
|
-
"@fluojs/validation": "^1.0.
|
|
71
|
+
"@fluojs/validation": "^1.0.3"
|
|
72
72
|
},
|
|
73
73
|
"peerDependenciesMeta": {
|
|
74
74
|
"@fluojs/http": {
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"intl-messageformat": "^11.2.4",
|
|
86
86
|
"vitest": "^3.2.4",
|
|
87
87
|
"@fluojs/http": "^1.0.0",
|
|
88
|
-
"@fluojs/validation": "^1.0.
|
|
88
|
+
"@fluojs/validation": "^1.0.3"
|
|
89
89
|
},
|
|
90
90
|
"scripts": {
|
|
91
91
|
"prebuild": "node ../../tooling/scripts/clean-dist.mjs",
|