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.

index.d.ts 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. declare namespace mapObject {
  2. type Mapper<
  3. SourceObjectType extends {[key: string]: any},
  4. MappedObjectKeyType extends string,
  5. MappedObjectValueType
  6. > = (
  7. sourceKey: keyof SourceObjectType,
  8. sourceValue: SourceObjectType[keyof SourceObjectType],
  9. source: SourceObjectType
  10. ) => [
  11. targetKey: MappedObjectKeyType,
  12. targetValue: MappedObjectValueType,
  13. mapperOptions?: mapObject.MapperOptions
  14. ];
  15. interface Options {
  16. /**
  17. Recurse nested objects and objects in arrays.
  18. @default false
  19. */
  20. deep?: boolean;
  21. /**
  22. Target object to map properties on to.
  23. @default {}
  24. */
  25. target?: {[key: string]: any};
  26. }
  27. interface DeepOptions extends Options {
  28. deep: true;
  29. }
  30. interface TargetOptions<TargetObjectType extends {[key: string]: any}> extends Options {
  31. target: TargetObjectType;
  32. }
  33. interface MapperOptions {
  34. /**
  35. Whether `targetValue` should be recursed. Requires `deep: true`.
  36. @default true
  37. */
  38. shouldRecurse?: boolean;
  39. }
  40. }
  41. /**
  42. Map object keys and values into a new object.
  43. @param source - Source object to copy properties from.
  44. @param mapper - Mapping function.
  45. @example
  46. ```
  47. import mapObject = require('map-obj');
  48. const newObject = mapObject({foo: 'bar'}, (key, value) => [value, key]);
  49. //=> {bar: 'foo'}
  50. const newObject = mapObject({FOO: true, bAr: {bAz: true}}, (key, value) => [key.toLowerCase(), value]);
  51. //=> {foo: true, bar: {bAz: true}}
  52. const newObject = mapObject({FOO: true, bAr: {bAz: true}}, (key, value) => [key.toLowerCase(), value], {deep: true});
  53. //=> {foo: true, bar: {baz: true}}
  54. ```
  55. */
  56. declare function mapObject<
  57. SourceObjectType extends object,
  58. TargetObjectType extends {[key: string]: any},
  59. MappedObjectKeyType extends string,
  60. MappedObjectValueType
  61. >(
  62. source: SourceObjectType,
  63. mapper: mapObject.Mapper<
  64. SourceObjectType,
  65. MappedObjectKeyType,
  66. MappedObjectValueType
  67. >,
  68. options: mapObject.DeepOptions & mapObject.TargetOptions<TargetObjectType>
  69. ): TargetObjectType & {[key: string]: unknown};
  70. declare function mapObject<
  71. SourceObjectType extends object,
  72. MappedObjectKeyType extends string,
  73. MappedObjectValueType
  74. >(
  75. source: SourceObjectType,
  76. mapper: mapObject.Mapper<
  77. SourceObjectType,
  78. MappedObjectKeyType,
  79. MappedObjectValueType
  80. >,
  81. options: mapObject.DeepOptions
  82. ): {[key: string]: unknown};
  83. declare function mapObject<
  84. SourceObjectType extends {[key: string]: any},
  85. TargetObjectType extends {[key: string]: any},
  86. MappedObjectKeyType extends string,
  87. MappedObjectValueType
  88. >(
  89. source: SourceObjectType,
  90. mapper: mapObject.Mapper<
  91. SourceObjectType,
  92. MappedObjectKeyType,
  93. MappedObjectValueType
  94. >,
  95. options: mapObject.TargetOptions<TargetObjectType>
  96. ): TargetObjectType & {[K in MappedObjectKeyType]: MappedObjectValueType};
  97. declare function mapObject<
  98. SourceObjectType extends {[key: string]: any},
  99. MappedObjectKeyType extends string,
  100. MappedObjectValueType
  101. >(
  102. source: SourceObjectType,
  103. mapper: mapObject.Mapper<
  104. SourceObjectType,
  105. MappedObjectKeyType,
  106. MappedObjectValueType
  107. >,
  108. options?: mapObject.Options
  109. ): {[K in MappedObjectKeyType]: MappedObjectValueType};
  110. export = mapObject;