@snack-uikit/locale 0.7.0 → 0.7.1-preview-c1f980c6.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.
@@ -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
- export type PathsToStringProps<T> = T extends string ? [] : {
27
- [K in Extract<keyof T, string>]: [K, ...PathsToStringProps<T[K]>];
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 { Join, PartialDeep, PathsToStringProps } from './typeUtils';
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 string ? Join<PathsToStringProps<LocaleDictionary[C]>, '.'> : Join<PathsToStringProps<LocaleDictionary>, '.'>;
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-c1f980c6.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": "bf1e1f3cfabccc1ee288c18722e33009bd001798"
40
+ "gitHead": "3ec993f2aba85ac8111cb418ef4161ffa8038efc"
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
- export type PathsToStringProps<T> = T extends string
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>]: [K, ...PathsToStringProps<T[K]>];
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 { Join, PartialDeep, PathsToStringProps } from './typeUtils';
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> = C extends string
15
- ? Join<PathsToStringProps<LocaleDictionary[C]>, '.'>
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>;