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.

array.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. function util() {
  7. const data = _interopRequireWildcard(require('util'));
  8. util = function () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. function _prettyFormat() {
  14. const data = require('pretty-format');
  15. _prettyFormat = function () {
  16. return data;
  17. };
  18. return data;
  19. }
  20. var _interpolation = require('./interpolation');
  21. function _getRequireWildcardCache(nodeInterop) {
  22. if (typeof WeakMap !== 'function') return null;
  23. var cacheBabelInterop = new WeakMap();
  24. var cacheNodeInterop = new WeakMap();
  25. return (_getRequireWildcardCache = function (nodeInterop) {
  26. return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
  27. })(nodeInterop);
  28. }
  29. function _interopRequireWildcard(obj, nodeInterop) {
  30. if (!nodeInterop && obj && obj.__esModule) {
  31. return obj;
  32. }
  33. if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) {
  34. return {default: obj};
  35. }
  36. var cache = _getRequireWildcardCache(nodeInterop);
  37. if (cache && cache.has(obj)) {
  38. return cache.get(obj);
  39. }
  40. var newObj = {};
  41. var hasPropertyDescriptor =
  42. Object.defineProperty && Object.getOwnPropertyDescriptor;
  43. for (var key in obj) {
  44. if (key !== 'default' && Object.prototype.hasOwnProperty.call(obj, key)) {
  45. var desc = hasPropertyDescriptor
  46. ? Object.getOwnPropertyDescriptor(obj, key)
  47. : null;
  48. if (desc && (desc.get || desc.set)) {
  49. Object.defineProperty(newObj, key, desc);
  50. } else {
  51. newObj[key] = obj[key];
  52. }
  53. }
  54. }
  55. newObj.default = obj;
  56. if (cache) {
  57. cache.set(obj, newObj);
  58. }
  59. return newObj;
  60. }
  61. /**
  62. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  63. *
  64. * This source code is licensed under the MIT license found in the
  65. * LICENSE file in the root directory of this source tree.
  66. *
  67. */
  68. const SUPPORTED_PLACEHOLDERS = /%[sdifjoOp]/g;
  69. const PRETTY_PLACEHOLDER = '%p';
  70. const INDEX_PLACEHOLDER = '%#';
  71. const PLACEHOLDER_PREFIX = '%';
  72. const ESCAPED_PLACEHOLDER_PREFIX = /%%/g;
  73. const JEST_EACH_PLACEHOLDER_ESCAPE = '@@__JEST_EACH_PLACEHOLDER_ESCAPE__@@';
  74. var _default = (title, arrayTable) => {
  75. if (isTemplates(title, arrayTable)) {
  76. return arrayTable.map((template, index) => ({
  77. arguments: [template],
  78. title: (0, _interpolation.interpolateVariables)(
  79. title,
  80. template,
  81. index
  82. ).replace(ESCAPED_PLACEHOLDER_PREFIX, PLACEHOLDER_PREFIX)
  83. }));
  84. }
  85. return normaliseTable(arrayTable).map((row, index) => ({
  86. arguments: row,
  87. title: formatTitle(title, row, index)
  88. }));
  89. };
  90. exports.default = _default;
  91. const isTemplates = (title, arrayTable) =>
  92. !SUPPORTED_PLACEHOLDERS.test(interpolateEscapedPlaceholders(title)) &&
  93. !isTable(arrayTable) &&
  94. arrayTable.every(col => col != null && typeof col === 'object');
  95. const normaliseTable = table => (isTable(table) ? table : table.map(colToRow));
  96. const isTable = table => table.every(Array.isArray);
  97. const colToRow = col => [col];
  98. const formatTitle = (title, row, rowIndex) =>
  99. row
  100. .reduce((formattedTitle, value) => {
  101. const [placeholder] = getMatchingPlaceholders(formattedTitle);
  102. const normalisedValue = normalisePlaceholderValue(value);
  103. if (!placeholder) return formattedTitle;
  104. if (placeholder === PRETTY_PLACEHOLDER)
  105. return interpolatePrettyPlaceholder(formattedTitle, normalisedValue);
  106. return util().format(formattedTitle, normalisedValue);
  107. }, interpolateTitleIndex(interpolateEscapedPlaceholders(title), rowIndex))
  108. .replace(new RegExp(JEST_EACH_PLACEHOLDER_ESCAPE, 'g'), PLACEHOLDER_PREFIX);
  109. const normalisePlaceholderValue = value =>
  110. typeof value === 'string'
  111. ? value.replace(
  112. new RegExp(PLACEHOLDER_PREFIX, 'g'),
  113. JEST_EACH_PLACEHOLDER_ESCAPE
  114. )
  115. : value;
  116. const getMatchingPlaceholders = title =>
  117. title.match(SUPPORTED_PLACEHOLDERS) || [];
  118. const interpolateEscapedPlaceholders = title =>
  119. title.replace(ESCAPED_PLACEHOLDER_PREFIX, JEST_EACH_PLACEHOLDER_ESCAPE);
  120. const interpolateTitleIndex = (title, index) =>
  121. title.replace(INDEX_PLACEHOLDER, index.toString());
  122. const interpolatePrettyPlaceholder = (title, value) =>
  123. title.replace(
  124. PRETTY_PLACEHOLDER,
  125. (0, _prettyFormat().format)(value, {
  126. maxDepth: 1,
  127. min: true
  128. })
  129. );