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.

es.string.match-all.js 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. 'use strict';
  2. /* eslint-disable es/no-string-prototype-matchall -- safe */
  3. var $ = require('../internals/export');
  4. var createIteratorConstructor = require('../internals/create-iterator-constructor');
  5. var requireObjectCoercible = require('../internals/require-object-coercible');
  6. var toLength = require('../internals/to-length');
  7. var aFunction = require('../internals/a-function');
  8. var anObject = require('../internals/an-object');
  9. var classof = require('../internals/classof-raw');
  10. var isRegExp = require('../internals/is-regexp');
  11. var getRegExpFlags = require('../internals/regexp-flags');
  12. var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
  13. var fails = require('../internals/fails');
  14. var wellKnownSymbol = require('../internals/well-known-symbol');
  15. var speciesConstructor = require('../internals/species-constructor');
  16. var advanceStringIndex = require('../internals/advance-string-index');
  17. var InternalStateModule = require('../internals/internal-state');
  18. var IS_PURE = require('../internals/is-pure');
  19. var MATCH_ALL = wellKnownSymbol('matchAll');
  20. var REGEXP_STRING = 'RegExp String';
  21. var REGEXP_STRING_ITERATOR = REGEXP_STRING + ' Iterator';
  22. var setInternalState = InternalStateModule.set;
  23. var getInternalState = InternalStateModule.getterFor(REGEXP_STRING_ITERATOR);
  24. var RegExpPrototype = RegExp.prototype;
  25. var regExpBuiltinExec = RegExpPrototype.exec;
  26. var nativeMatchAll = ''.matchAll;
  27. var WORKS_WITH_NON_GLOBAL_REGEX = !!nativeMatchAll && !fails(function () {
  28. 'a'.matchAll(/./);
  29. });
  30. var regExpExec = function (R, S) {
  31. var exec = R.exec;
  32. var result;
  33. if (typeof exec == 'function') {
  34. result = exec.call(R, S);
  35. if (typeof result != 'object') throw TypeError('Incorrect exec result');
  36. return result;
  37. } return regExpBuiltinExec.call(R, S);
  38. };
  39. // eslint-disable-next-line max-len -- ignore
  40. var $RegExpStringIterator = createIteratorConstructor(function RegExpStringIterator(regexp, string, global, fullUnicode) {
  41. setInternalState(this, {
  42. type: REGEXP_STRING_ITERATOR,
  43. regexp: regexp,
  44. string: string,
  45. global: global,
  46. unicode: fullUnicode,
  47. done: false
  48. });
  49. }, REGEXP_STRING, function next() {
  50. var state = getInternalState(this);
  51. if (state.done) return { value: undefined, done: true };
  52. var R = state.regexp;
  53. var S = state.string;
  54. var match = regExpExec(R, S);
  55. if (match === null) return { value: undefined, done: state.done = true };
  56. if (state.global) {
  57. if (String(match[0]) == '') R.lastIndex = advanceStringIndex(S, toLength(R.lastIndex), state.unicode);
  58. return { value: match, done: false };
  59. }
  60. state.done = true;
  61. return { value: match, done: false };
  62. });
  63. var $matchAll = function (string) {
  64. var R = anObject(this);
  65. var S = String(string);
  66. var C, flagsValue, flags, matcher, global, fullUnicode;
  67. C = speciesConstructor(R, RegExp);
  68. flagsValue = R.flags;
  69. if (flagsValue === undefined && R instanceof RegExp && !('flags' in RegExpPrototype)) {
  70. flagsValue = getRegExpFlags.call(R);
  71. }
  72. flags = flagsValue === undefined ? '' : String(flagsValue);
  73. matcher = new C(C === RegExp ? R.source : R, flags);
  74. global = !!~flags.indexOf('g');
  75. fullUnicode = !!~flags.indexOf('u');
  76. matcher.lastIndex = toLength(R.lastIndex);
  77. return new $RegExpStringIterator(matcher, S, global, fullUnicode);
  78. };
  79. // `String.prototype.matchAll` method
  80. // https://tc39.es/ecma262/#sec-string.prototype.matchall
  81. $({ target: 'String', proto: true, forced: WORKS_WITH_NON_GLOBAL_REGEX }, {
  82. matchAll: function matchAll(regexp) {
  83. var O = requireObjectCoercible(this);
  84. var flags, S, matcher, rx;
  85. if (regexp != null) {
  86. if (isRegExp(regexp)) {
  87. flags = String(requireObjectCoercible('flags' in RegExpPrototype
  88. ? regexp.flags
  89. : getRegExpFlags.call(regexp)
  90. ));
  91. if (!~flags.indexOf('g')) throw TypeError('`.matchAll` does not allow non-global regexes');
  92. }
  93. if (WORKS_WITH_NON_GLOBAL_REGEX) return nativeMatchAll.apply(O, arguments);
  94. matcher = regexp[MATCH_ALL];
  95. if (matcher === undefined && IS_PURE && classof(regexp) == 'RegExp') matcher = $matchAll;
  96. if (matcher != null) return aFunction(matcher).call(regexp, O);
  97. } else if (WORKS_WITH_NON_GLOBAL_REGEX) return nativeMatchAll.apply(O, arguments);
  98. S = String(O);
  99. rx = new RegExp(regexp, 'g');
  100. return IS_PURE ? $matchAll.call(rx, S) : rx[MATCH_ALL](S);
  101. }
  102. });
  103. IS_PURE || MATCH_ALL in RegExpPrototype || createNonEnumerableProperty(RegExpPrototype, MATCH_ALL, $matchAll);