@snack-uikit/locale 0.7.0 → 0.7.1-preview-dad52704.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/typeUtils.d.ts +6 -3
- package/dist/types.d.ts +2 -2
- package/package.json +2 -2
- package/src/typeUtils.ts +8 -13
- package/src/types.ts +3 -4
package/dist/typeUtils.d.ts
CHANGED
|
@@ -23,8 +23,11 @@ type PartialReadonlySetDeep<T> = unknown & ReadonlySet<PartialDeep<T>>;
|
|
|
23
23
|
type PartialObjectDeep<ObjectType extends object> = {
|
|
24
24
|
[KeyType in keyof ObjectType]?: PartialDeep<ObjectType[KeyType]>;
|
|
25
25
|
};
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
/**
|
|
27
|
+
* https://stackoverflow.com/a/73179989
|
|
28
|
+
*/
|
|
29
|
+
type Dot<T extends string, U extends string> = '' extends U ? T : `${T}.${U}`;
|
|
30
|
+
export type PathsToProps<T, V> = T extends V ? '' : {
|
|
31
|
+
[K in Extract<keyof T, string>]: Dot<K, PathsToProps<T[K], V>>;
|
|
28
32
|
}[Extract<keyof T, string>];
|
|
29
|
-
export type Join<T extends string[], D extends string> = T extends [] ? never : T extends [infer F] ? F : T extends [infer F, ...infer R] ? F extends string ? `${F}${D}${Join<Extract<R, string[]>, D>}` : never : string;
|
|
30
33
|
export {};
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LOCALES } from './locales';
|
|
2
|
-
import {
|
|
2
|
+
import { PartialDeep, PathsToProps } from './typeUtils';
|
|
3
3
|
export type KnownLocaleLang = keyof typeof LOCALES;
|
|
4
4
|
export type LocaleLang = KnownLocaleLang | string;
|
|
5
5
|
export type LocaleDictionary = typeof LOCALES.en_GB;
|
|
6
6
|
export type OverrideLocales = PartialDeep<Record<LocaleLang, LocaleDictionary>>;
|
|
7
|
-
export type DottedTranslationKey<C extends keyof LocaleDictionary | undefined = undefined> = C extends
|
|
7
|
+
export type DottedTranslationKey<C extends keyof LocaleDictionary | undefined = undefined> = C extends keyof LocaleDictionary ? PathsToProps<LocaleDictionary[C], string> : PathsToProps<LocaleDictionary, string>;
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "Locale",
|
|
7
|
-
"version": "0.7.0",
|
|
7
|
+
"version": "0.7.1-preview-dad52704.0",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/lodash.merge": "4.6.9"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "044e260103d8d8f51f9bea645ae81adac31683ce"
|
|
41
41
|
}
|
package/src/typeUtils.ts
CHANGED
|
@@ -47,18 +47,13 @@ type PartialObjectDeep<ObjectType extends object> = {
|
|
|
47
47
|
[KeyType in keyof ObjectType]?: PartialDeep<ObjectType[KeyType]>;
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
/**
|
|
51
|
+
* https://stackoverflow.com/a/73179989
|
|
52
|
+
*/
|
|
53
|
+
type Dot<T extends string, U extends string> = '' extends U ? T : `${T}.${U}`;
|
|
54
|
+
|
|
55
|
+
export type PathsToProps<T, V> = T extends V
|
|
56
|
+
? ''
|
|
52
57
|
: {
|
|
53
|
-
[K in Extract<keyof T, string>]:
|
|
58
|
+
[K in Extract<keyof T, string>]: Dot<K, PathsToProps<T[K], V>>;
|
|
54
59
|
}[Extract<keyof T, string>];
|
|
55
|
-
|
|
56
|
-
export type Join<T extends string[], D extends string> = T extends []
|
|
57
|
-
? never
|
|
58
|
-
: T extends [infer F]
|
|
59
|
-
? F
|
|
60
|
-
: T extends [infer F, ...infer R]
|
|
61
|
-
? F extends string
|
|
62
|
-
? `${F}${D}${Join<Extract<R, string[]>, D>}`
|
|
63
|
-
: never
|
|
64
|
-
: string;
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LOCALES } from './locales';
|
|
2
|
-
import {
|
|
2
|
+
import { PartialDeep, PathsToProps } from './typeUtils';
|
|
3
3
|
|
|
4
4
|
export type KnownLocaleLang = keyof typeof LOCALES;
|
|
5
5
|
|
|
@@ -11,6 +11,5 @@ export type LocaleDictionary = typeof LOCALES.en_GB;
|
|
|
11
11
|
// export type OverrideLocales = PartialDeep<Record<KnownLocaleLang, LocaleDictionary>> | Record<string, LocaleDictionary>;
|
|
12
12
|
export type OverrideLocales = PartialDeep<Record<LocaleLang, LocaleDictionary>>;
|
|
13
13
|
|
|
14
|
-
export type DottedTranslationKey<C extends keyof LocaleDictionary | undefined = undefined> =
|
|
15
|
-
?
|
|
16
|
-
: Join<PathsToStringProps<LocaleDictionary>, '.'>;
|
|
14
|
+
export type DottedTranslationKey<C extends keyof LocaleDictionary | undefined = undefined> =
|
|
15
|
+
C extends keyof LocaleDictionary ? PathsToProps<LocaleDictionary[C], string> : PathsToProps<LocaleDictionary, string>;
|