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.

string-prototype-es.js 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /* eslint-disable node/no-unsupported-features/es-syntax */
  2. /**
  3. * @param {RegExp} regex
  4. * @param {string} newFlags
  5. * @param {Integer} [newLastIndex=regex.lastIndex]
  6. * @returns {RegExp}
  7. */
  8. function mixinRegex(regex, newFlags) {
  9. var newLastIndex = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : regex.lastIndex;
  10. newFlags = newFlags || '';
  11. regex = new RegExp(regex.source, (newFlags.includes('g') ? 'g' : regex.global ? 'g' : '') + (newFlags.includes('i') ? 'i' : regex.ignoreCase ? 'i' : '') + (newFlags.includes('m') ? 'm' : regex.multiline ? 'm' : '') + (newFlags.includes('u') ? 'u' : regex.unicode ? 'u' : '') + (newFlags.includes('y') ? 'y' : regex.sticky ? 'y' : '') + (newFlags.includes('s') ? 's' : regex.dotAll ? 's' : ''));
  12. regex.lastIndex = newLastIndex;
  13. return regex;
  14. }
  15. // We copy the regular expression so as to be able to always ensure the exec
  16. String.prototype.forEach = function (regex, cb) {
  17. var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  18. var matches,
  19. n0,
  20. i = 0;
  21. regex = mixinRegex(regex, 'g');
  22. while ((matches = regex.exec(this)) !== null) {
  23. n0 = matches.splice(0, 1);
  24. cb.apply(thisObj, matches.concat(i++, n0));
  25. }
  26. return this;
  27. };
  28. String.prototype.some = function (regex, cb) {
  29. var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  30. var matches,
  31. ret,
  32. n0,
  33. i = 0;
  34. regex = mixinRegex(regex, 'g');
  35. while ((matches = regex.exec(this)) !== null) {
  36. n0 = matches.splice(0, 1);
  37. ret = cb.apply(thisObj, matches.concat(i++, n0));
  38. if (ret) {
  39. return true;
  40. }
  41. }
  42. return false;
  43. };
  44. String.prototype.every = function (regex, cb) {
  45. var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  46. var matches,
  47. ret,
  48. n0,
  49. i = 0;
  50. regex = mixinRegex(regex, 'g');
  51. while ((matches = regex.exec(this)) !== null) {
  52. n0 = matches.splice(0, 1);
  53. ret = cb.apply(thisObj, matches.concat(i++, n0));
  54. if (!ret) {
  55. return false;
  56. }
  57. }
  58. return true;
  59. };
  60. String.prototype.map = function (regex, cb) {
  61. var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  62. var matches,
  63. n0,
  64. i = 0;
  65. var ret = [];
  66. regex = mixinRegex(regex, 'g');
  67. while ((matches = regex.exec(this)) !== null) {
  68. n0 = matches.splice(0, 1);
  69. ret.push(cb.apply(thisObj, matches.concat(i++, n0)));
  70. }
  71. return ret;
  72. };
  73. String.prototype.filter = function (regex, cb) {
  74. var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  75. var matches,
  76. n0,
  77. i = 0;
  78. var ret = [];
  79. regex = mixinRegex(regex, 'g');
  80. while ((matches = regex.exec(this)) !== null) {
  81. n0 = matches.splice(0, 1);
  82. matches = matches.concat(i++, n0);
  83. if (cb.apply(thisObj, matches)) {
  84. ret.push(n0[0]);
  85. }
  86. }
  87. return ret;
  88. };
  89. String.prototype.reduce = function (regex, cb, prev) {
  90. var thisObj = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
  91. var matches,
  92. n0,
  93. i = 0;
  94. regex = mixinRegex(regex, 'g');
  95. if (!prev) {
  96. if ((matches = regex.exec(this)) !== null) {
  97. n0 = matches.splice(0, 1);
  98. prev = cb.apply(thisObj, [''].concat(matches.concat(i++, n0)));
  99. }
  100. }
  101. while ((matches = regex.exec(this)) !== null) {
  102. n0 = matches.splice(0, 1);
  103. prev = cb.apply(thisObj, [prev].concat(matches.concat(i++, n0)));
  104. }
  105. return prev;
  106. };
  107. String.prototype.reduceRight = function (regex, cb, prevOrig, thisObjOrig) {
  108. var matches,
  109. n0,
  110. i,
  111. prev = prevOrig,
  112. thisObj = thisObjOrig;
  113. var matchesContainer = [];
  114. regex = mixinRegex(regex, 'g');
  115. thisObj = thisObj || null;
  116. while ((matches = regex.exec(this)) !== null) {
  117. matchesContainer.push(matches);
  118. }
  119. i = matchesContainer.length;
  120. if (!i) {
  121. if (arguments.length < 3) {
  122. throw new TypeError('reduce of empty matches array with no initial value');
  123. }
  124. return prev;
  125. }
  126. if (!prev) {
  127. matches = matchesContainer.splice(-1)[0];
  128. n0 = matches.splice(0, 1);
  129. prev = cb.apply(thisObj, [''].concat(matches.concat(i--, n0)));
  130. }
  131. matchesContainer.reduceRight(function (container, mtches) {
  132. n0 = mtches.splice(0, 1);
  133. prev = cb.apply(thisObj, [prev].concat(mtches.concat(i--, n0)));
  134. return container;
  135. }, matchesContainer);
  136. return prev;
  137. };
  138. String.prototype.find = function (regex, cb) {
  139. var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  140. var matches,
  141. ret,
  142. n0,
  143. i = 0;
  144. regex = mixinRegex(regex, 'g');
  145. while ((matches = regex.exec(this)) !== null) {
  146. n0 = matches.splice(0, 1);
  147. ret = cb.apply(thisObj, matches.concat(i++, n0));
  148. if (ret) {
  149. return n0[0];
  150. }
  151. }
  152. return false;
  153. };
  154. String.prototype.findIndex = function (regex, cb) {
  155. var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  156. var matches,
  157. ret,
  158. n0,
  159. i = 0;
  160. regex = mixinRegex(regex, 'g');
  161. while ((matches = regex.exec(this)) !== null) {
  162. n0 = matches.splice(0, 1);
  163. ret = cb.apply(thisObj, matches.concat(i++, n0));
  164. if (ret) {
  165. return i - 1;
  166. }
  167. }
  168. return -1;
  169. };
  170. String.prototype.findExec = function (regex, cb) {
  171. var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  172. var matches,
  173. ret,
  174. n0,
  175. i = 0;
  176. regex = mixinRegex(regex, 'g');
  177. while ((matches = regex.exec(this)) !== null) {
  178. n0 = matches.splice(0, 1);
  179. ret = cb.apply(thisObj, matches.concat(i++, n0));
  180. if (ret) {
  181. return matches;
  182. }
  183. }
  184. return false;
  185. };
  186. String.prototype.filterExec = function (regex, cb) {
  187. var thisObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
  188. var matches,
  189. n0,
  190. i = 0;
  191. var ret = [];
  192. regex = mixinRegex(regex, 'g');
  193. while ((matches = regex.exec(this)) !== null) {
  194. n0 = matches.splice(0, 1);
  195. matches.push(i++, n0[0]);
  196. if (cb.apply(thisObj, matches)) {
  197. ret.push(matches);
  198. }
  199. }
  200. return ret;
  201. };