Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

camel-case.d.ts 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import {WordSeparators} from '../source/utilities';
  2. /**
  3. Recursively split a string literal into two parts on the first occurence of the given string, returning an array literal of all the separate parts.
  4. */
  5. export type Split<S extends string, D extends string> =
  6. string extends S ? string[] :
  7. S extends '' ? [] :
  8. S extends `${infer T}${D}${infer U}` ? [T, ...Split<U, D>] :
  9. [S];
  10. /**
  11. Step by step takes the first item in an array literal, formats it and adds it to a string literal, and then recursively appends the remainder.
  12. Only to be used by `CamelCaseStringArray<>`.
  13. @see CamelCaseStringArray
  14. */
  15. type InnerCamelCaseStringArray<Parts extends any[], PreviousPart> =
  16. Parts extends [`${infer FirstPart}`, ...infer RemainingParts]
  17. ? FirstPart extends undefined
  18. ? ''
  19. : FirstPart extends ''
  20. ? InnerCamelCaseStringArray<RemainingParts, PreviousPart>
  21. : `${PreviousPart extends '' ? FirstPart : Capitalize<FirstPart>}${InnerCamelCaseStringArray<RemainingParts, FirstPart>}`
  22. : '';
  23. /**
  24. Starts fusing the output of `Split<>`, an array literal of strings, into a camel-cased string literal.
  25. It's separate from `InnerCamelCaseStringArray<>` to keep a clean API outwards to the rest of the code.
  26. @see Split
  27. */
  28. type CamelCaseStringArray<Parts extends string[]> =
  29. Parts extends [`${infer FirstPart}`, ...infer RemainingParts]
  30. ? Uncapitalize<`${FirstPart}${InnerCamelCaseStringArray<RemainingParts, FirstPart>}`>
  31. : never;
  32. /**
  33. Convert a string literal to camel-case.
  34. This can be useful when, for example, converting some kebab-cased command-line flags or a snake-cased database result.
  35. @example
  36. ```
  37. import {CamelCase} from 'type-fest';
  38. // Simple
  39. const someVariable: CamelCase<'foo-bar'> = 'fooBar';
  40. // Advanced
  41. type CamelCasedProps<T> = {
  42. [K in keyof T as CamelCase<K>]: T[K]
  43. };
  44. interface RawOptions {
  45. 'dry-run': boolean;
  46. 'full_family_name': string;
  47. foo: number;
  48. }
  49. const dbResult: CamelCasedProps<ModelProps> = {
  50. dryRun: true,
  51. fullFamilyName: 'bar.js',
  52. foo: 123
  53. };
  54. ```
  55. */
  56. export type CamelCase<K> = K extends string ? CamelCaseStringArray<Split<K, WordSeparators>> : K;