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.js 4.5KB

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