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.

main.js 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /* eslint-disable node/no-unsupported-features/es-syntax,
  2. jsdoc/require-jsdoc */
  3. // We copy the regular expression so as to be able to always ensure the
  4. // exec expression is a global one (and thereby prevent recursion)
  5. import mixinRegex from './mixinRegex.js';
  6. class RegExtras {
  7. constructor (regex, flags, newLastIndex) {
  8. this.regex = mixinRegex(
  9. (typeof regex === 'string' ? new RegExp(regex) : mixinRegex(regex)),
  10. flags || '',
  11. newLastIndex
  12. );
  13. }
  14. forEach (str, cb, thisObj = null) {
  15. const regex = mixinRegex(this.regex, 'g');
  16. let matches, n0, i = 0;
  17. while ((matches = regex.exec(str)) !== null) {
  18. n0 = matches.splice(0, 1);
  19. cb.apply(thisObj, matches.concat(i++, n0));
  20. }
  21. return this;
  22. }
  23. some (str, cb, thisObj = null) {
  24. const regex = mixinRegex(this.regex, 'g');
  25. let matches, ret, n0, i = 0;
  26. while ((matches = regex.exec(str)) !== null) {
  27. n0 = matches.splice(0, 1);
  28. ret = cb.apply(thisObj, matches.concat(i++, n0));
  29. if (ret) {
  30. return true;
  31. }
  32. }
  33. return false;
  34. }
  35. every (str, cb, thisObj = null) {
  36. const regex = mixinRegex(this.regex, 'g');
  37. let matches, ret, n0, i = 0;
  38. while ((matches = regex.exec(str)) !== null) {
  39. n0 = matches.splice(0, 1);
  40. ret = cb.apply(thisObj, matches.concat(i++, n0));
  41. if (!ret) {
  42. return false;
  43. }
  44. }
  45. return true;
  46. }
  47. map (str, cb, thisObj = null) {
  48. const ret = [];
  49. const regex = mixinRegex(this.regex, 'g');
  50. let matches, n0, i = 0;
  51. while ((matches = regex.exec(str)) !== null) {
  52. n0 = matches.splice(0, 1);
  53. ret.push(cb.apply(thisObj, matches.concat(i++, n0)));
  54. }
  55. return ret;
  56. }
  57. filter (str, cb, thisObj = null) {
  58. let matches, n0, i = 0;
  59. const ret = [], regex = mixinRegex(this.regex, 'g');
  60. while ((matches = regex.exec(str)) !== null) {
  61. n0 = matches.splice(0, 1);
  62. matches = matches.concat(i++, n0);
  63. if (cb.apply(thisObj, matches)) {
  64. ret.push(n0[0]);
  65. }
  66. }
  67. return ret;
  68. }
  69. reduce (str, cb, prev, thisObj = null) {
  70. let matches, n0, i = 0;
  71. const regex = mixinRegex(this.regex, 'g');
  72. if (!prev) {
  73. if ((matches = regex.exec(str)) !== null) {
  74. n0 = matches.splice(0, 1);
  75. prev = cb.apply(thisObj, [''].concat(matches.concat(i++, n0)));
  76. }
  77. }
  78. while ((matches = regex.exec(str)) !== null) {
  79. n0 = matches.splice(0, 1);
  80. prev = cb.apply(thisObj, [prev].concat(matches.concat(i++, n0)));
  81. }
  82. return prev;
  83. }
  84. reduceRight (str, cb, prevOrig, thisObjOrig) {
  85. let matches, n0, i, thisObj = thisObjOrig, prev = prevOrig;
  86. const matchesContainer = [],
  87. regex = mixinRegex(this.regex, 'g');
  88. thisObj = thisObj || null;
  89. while ((matches = regex.exec(str)) !== null) {
  90. matchesContainer.push(matches);
  91. }
  92. i = matchesContainer.length;
  93. if (!i) {
  94. if (arguments.length < 3) {
  95. throw new TypeError(
  96. 'reduce of empty matches array with no initial value'
  97. );
  98. }
  99. return prev;
  100. }
  101. if (!prev) {
  102. matches = matchesContainer.splice(-1)[0];
  103. n0 = matches.splice(0, 1);
  104. prev = cb.apply(thisObj, [''].concat(matches.concat(i--, n0)));
  105. }
  106. matchesContainer.reduceRight((container, mtches) => {
  107. n0 = mtches.splice(0, 1);
  108. prev = cb.apply(thisObj, [prev].concat(mtches.concat(i--, n0)));
  109. return container;
  110. }, matchesContainer);
  111. return prev;
  112. }
  113. find (str, cb, thisObj = null) {
  114. let matches, ret, n0, i = 0;
  115. const regex = mixinRegex(this.regex, 'g');
  116. while ((matches = regex.exec(str)) !== null) {
  117. n0 = matches.splice(0, 1);
  118. ret = cb.apply(thisObj, matches.concat(i++, n0));
  119. if (ret) {
  120. return n0[0];
  121. }
  122. }
  123. return false;
  124. }
  125. findIndex (str, cb, thisObj = null) {
  126. const regex = mixinRegex(this.regex, 'g');
  127. let matches, i = 0;
  128. while ((matches = regex.exec(str)) !== null) {
  129. const n0 = matches.splice(0, 1);
  130. const ret = cb.apply(thisObj, matches.concat(i++, n0));
  131. if (ret) {
  132. return i - 1;
  133. }
  134. }
  135. return -1;
  136. }
  137. findExec (str, cb, thisObj = null) {
  138. const regex = mixinRegex(this.regex, 'g');
  139. let matches, i = 0;
  140. while ((matches = regex.exec(str)) !== null) {
  141. const n0 = matches.splice(0, 1);
  142. const ret = cb.apply(thisObj, matches.concat(i++, n0));
  143. if (ret) {
  144. return matches;
  145. }
  146. }
  147. return false;
  148. }
  149. filterExec (str, cb, thisObj = null) {
  150. let matches, n0, i = 0;
  151. const ret = [], regex = mixinRegex(this.regex, 'g');
  152. while ((matches = regex.exec(str)) !== null) {
  153. n0 = matches.splice(0, 1);
  154. matches.push(i++, n0[0]);
  155. if (cb.apply(thisObj, matches)) {
  156. ret.push(matches);
  157. }
  158. }
  159. return ret;
  160. }
  161. }
  162. const _RegExtras = RegExtras;
  163. RegExtras = function (...args) { // eslint-disable-line no-class-assign
  164. return new _RegExtras(...args);
  165. };
  166. RegExtras.prototype = _RegExtras.prototype;
  167. RegExtras.mixinRegex = mixinRegex;
  168. export {mixinRegex, RegExtras};