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.

README.md 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. # regextras
  2. Array extras for regular expressions.
  3. Also provides optional `String` and `RegExp` prototype extensions.
  4. No more writing the implementation-detail-leaking, non-semantic, and
  5. otherwise ugly:
  6. ```js
  7. let matches;
  8. while ((matches = regex.exec(str)) !== null) {
  9. // Do something
  10. if (condition) {
  11. break;
  12. }
  13. }
  14. ```
  15. While all of the array extras could be useful, `some`, might be the most
  16. general purpose as it (as with `every`) allows short-circuiting (breaking).
  17. The following is equivalent to that above (though with `matches` as local):
  18. ```js
  19. RegExtras(regex).some(str, (matches) => {
  20. // Do something
  21. if (condition) {
  22. return true;
  23. }
  24. return false;
  25. });
  26. ```
  27. And if the condition is at the end of the loop, just this:
  28. ```js
  29. RegExtras(regex).some(str, (matches) => {
  30. // Do something
  31. return condition;
  32. });
  33. ```
  34. ## Installation
  35. Node:
  36. ```js
  37. const RegExtras = require('regextras');
  38. ```
  39. Modern browsers:
  40. ```js
  41. import {RegExtras} from './node_modules/regextras/dist/index-es.js';
  42. ```
  43. Older browsers:
  44. ```html
  45. <script src="regextras/dist/index-umd.js"></script>
  46. ```
  47. The prototype versions must be required or included separately.
  48. If you need the generator methods, you should also add the following:
  49. ```html
  50. <script src="regextras/dist/index-generators-umd.js"></script>
  51. ```
  52. ## API
  53. ### Constructor
  54. `new RegExtras(regex, flags, newLastIndex)`
  55. Example:
  56. ```js
  57. const piglatinArray = RegExtras(/\w*w?ay/).reduce('ouyay areway illysay', function (arr, i, word) {
  58. if (word.endsWith('way')) { arr.push(word.replace(/way$/, '')); } else { arr.push(word.slice(-3, -2) + word.slice(0, -3)); }
  59. return arr;
  60. }, []);
  61. ```
  62. All arguments but the first are optional, and the first argument can be
  63. expressed as a string.
  64. The `new` keywords is not required.
  65. ### Instance methods
  66. These methods (and their callbacks) behave like the [array extra](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#Iteration_methods)
  67. to which they correspond with exceptions detailed below.
  68. - ***forEach(str, callback, thisObject)*** - Unlike the other extras, this
  69. method returns the RegExtras object (to enable chaining).
  70. - ***some(str, callback, thisObject)***
  71. - ***every(str, callback, thisObject)***
  72. - ***map(str, callback, thisObject)***
  73. - ***filter(str, callback, thisObject)***
  74. - ***reduce(str, cb, prev, thisObj)*** - Unlike the array extras, allows a
  75. fourth argument to set an alternative value for `this` within the callback.
  76. - ***reduceRight(str, cb, prev, thisObj)*** - Unlike the array extras,
  77. allows a fourth argument to set an alternative value for `this` within
  78. the callback.
  79. - ***find(str, cb, thisObj)***
  80. - ***findIndex(str, cb, thisObj)***
  81. Also adds the following methods:
  82. - ***findExec(str, cb, thisObj)*** - Operates like `find()` except that it
  83. returns the `exec` result array (with `index` and `input` as well as
  84. numeric properties as returned by [RegExp.prototype.exec](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)).
  85. - ***filterExec(str, cb, thisObj)*** - Operates like `filter()` except that
  86. the resulting array will contain the full `exec` results.
  87. If you are using the Node version (or if, for the browser, you add the
  88. `index-generators.js` file and you are only supporting modern browsers), one
  89. can use the following generator methods:
  90. - ***values(str)*** - Returns an iterator with the array of matches (for each
  91. `RegExp.prototype.exec` result)
  92. - ***keys(str)*** - Returns an iterator with 0-based indexes (from
  93. `RegExp.prototype.exec` result)
  94. - ***entries(str)*** - Returns an iterator with an array containing the
  95. key and the array of matches (for each `RegExp.prototype.exec` result)
  96. ### Class methods
  97. - ***mixinRegex(regex, newFlags='', newLastIndex=regex.lastIndex)*** -
  98. Makes a copy of a regular expression.
  99. ### Callbacks
  100. All callbacks follow the signature:
  101. `cb(n1, n2..., i, n0);`
  102. ...except for the `reduce` and `reduceRight` callbacks which follow:
  103. `cb(prev, n1, n2..., i, n0);`
  104. ### Prototype versions
  105. `String` and `RegExp` versions of the above methods are also available.
  106. The `RegExp` prototype version acts in the same way as `RegExtra` just
  107. without the need for a separate constructor call.
  108. The `String` prototype version differs in that instead of the first argument
  109. being a string, it is the regular expression.
  110. ## Todos
  111. 1. Could add [Array accessor methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array#Accessor_methods)
  112. like `slice()`, with an additional supplied regular expression to gather
  113. the `exec` results into an array.
  114. 2. Utilize `nodeunit` browser testing (and add `mixinRegex` tests)
  115. 1. Convert nodeunit tests to ES6 modules running through babel-register?;
  116. streamline as sole set of tests, reconciling `test` with `tests` folder
  117. 3. Add generators for prototype versions