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.

collections.js 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.printIteratorEntries = printIteratorEntries;
  6. exports.printIteratorValues = printIteratorValues;
  7. exports.printListItems = printListItems;
  8. exports.printObjectProperties = printObjectProperties;
  9. /**
  10. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  11. *
  12. * This source code is licensed under the MIT license found in the
  13. * LICENSE file in the root directory of this source tree.
  14. *
  15. */
  16. const getKeysOfEnumerableProperties = object => {
  17. const keys = Object.keys(object).sort();
  18. if (Object.getOwnPropertySymbols) {
  19. Object.getOwnPropertySymbols(object).forEach(symbol => {
  20. if (Object.getOwnPropertyDescriptor(object, symbol).enumerable) {
  21. keys.push(symbol);
  22. }
  23. });
  24. }
  25. return keys;
  26. };
  27. /**
  28. * Return entries (for example, of a map)
  29. * with spacing, indentation, and comma
  30. * without surrounding punctuation (for example, braces)
  31. */
  32. function printIteratorEntries(
  33. iterator,
  34. config,
  35. indentation,
  36. depth,
  37. refs,
  38. printer, // Too bad, so sad that separator for ECMAScript Map has been ' => '
  39. // What a distracting diff if you change a data structure to/from
  40. // ECMAScript Object or Immutable.Map/OrderedMap which use the default.
  41. separator = ': '
  42. ) {
  43. let result = '';
  44. let current = iterator.next();
  45. if (!current.done) {
  46. result += config.spacingOuter;
  47. const indentationNext = indentation + config.indent;
  48. while (!current.done) {
  49. const name = printer(
  50. current.value[0],
  51. config,
  52. indentationNext,
  53. depth,
  54. refs
  55. );
  56. const value = printer(
  57. current.value[1],
  58. config,
  59. indentationNext,
  60. depth,
  61. refs
  62. );
  63. result += indentationNext + name + separator + value;
  64. current = iterator.next();
  65. if (!current.done) {
  66. result += ',' + config.spacingInner;
  67. } else if (!config.min) {
  68. result += ',';
  69. }
  70. }
  71. result += config.spacingOuter + indentation;
  72. }
  73. return result;
  74. }
  75. /**
  76. * Return values (for example, of a set)
  77. * with spacing, indentation, and comma
  78. * without surrounding punctuation (braces or brackets)
  79. */
  80. function printIteratorValues(
  81. iterator,
  82. config,
  83. indentation,
  84. depth,
  85. refs,
  86. printer
  87. ) {
  88. let result = '';
  89. let current = iterator.next();
  90. if (!current.done) {
  91. result += config.spacingOuter;
  92. const indentationNext = indentation + config.indent;
  93. while (!current.done) {
  94. result +=
  95. indentationNext +
  96. printer(current.value, config, indentationNext, depth, refs);
  97. current = iterator.next();
  98. if (!current.done) {
  99. result += ',' + config.spacingInner;
  100. } else if (!config.min) {
  101. result += ',';
  102. }
  103. }
  104. result += config.spacingOuter + indentation;
  105. }
  106. return result;
  107. }
  108. /**
  109. * Return items (for example, of an array)
  110. * with spacing, indentation, and comma
  111. * without surrounding punctuation (for example, brackets)
  112. **/
  113. function printListItems(list, config, indentation, depth, refs, printer) {
  114. let result = '';
  115. if (list.length) {
  116. result += config.spacingOuter;
  117. const indentationNext = indentation + config.indent;
  118. for (let i = 0; i < list.length; i++) {
  119. result += indentationNext;
  120. if (i in list) {
  121. result += printer(list[i], config, indentationNext, depth, refs);
  122. }
  123. if (i < list.length - 1) {
  124. result += ',' + config.spacingInner;
  125. } else if (!config.min) {
  126. result += ',';
  127. }
  128. }
  129. result += config.spacingOuter + indentation;
  130. }
  131. return result;
  132. }
  133. /**
  134. * Return properties of an object
  135. * with spacing, indentation, and comma
  136. * without surrounding punctuation (for example, braces)
  137. */
  138. function printObjectProperties(val, config, indentation, depth, refs, printer) {
  139. let result = '';
  140. const keys = getKeysOfEnumerableProperties(val);
  141. if (keys.length) {
  142. result += config.spacingOuter;
  143. const indentationNext = indentation + config.indent;
  144. for (let i = 0; i < keys.length; i++) {
  145. const key = keys[i];
  146. const name = printer(key, config, indentationNext, depth, refs);
  147. const value = printer(val[key], config, indentationNext, depth, refs);
  148. result += indentationNext + name + ': ' + value;
  149. if (i < keys.length - 1) {
  150. result += ',' + config.spacingInner;
  151. } else if (!config.min) {
  152. result += ',';
  153. }
  154. }
  155. result += config.spacingOuter + indentation;
  156. }
  157. return result;
  158. }