wallet-core/node_modules/core-js/modules/es7.string.match-all.js

31 lines
1.0 KiB
JavaScript
Raw Normal View History

2017-05-28 00:38:50 +02:00
'use strict';
// https://tc39.github.io/String.prototype.matchAll/
2017-08-14 05:01:11 +02:00
var $export = require('./_export');
var defined = require('./_defined');
var toLength = require('./_to-length');
var isRegExp = require('./_is-regexp');
var getFlags = require('./_flags');
var RegExpProto = RegExp.prototype;
2017-05-28 00:38:50 +02:00
2017-08-14 05:01:11 +02:00
var $RegExpStringIterator = function (regexp, string) {
2017-05-28 00:38:50 +02:00
this._r = regexp;
this._s = string;
};
2017-08-14 05:01:11 +02:00
require('./_iter-create')($RegExpStringIterator, 'RegExp String', function next() {
2017-05-28 00:38:50 +02:00
var match = this._r.exec(this._s);
2017-08-14 05:01:11 +02:00
return { value: match, done: match === null };
2017-05-28 00:38:50 +02:00
});
$export($export.P, 'String', {
2017-08-14 05:01:11 +02:00
matchAll: function matchAll(regexp) {
2017-05-28 00:38:50 +02:00
defined(this);
2017-08-14 05:01:11 +02:00
if (!isRegExp(regexp)) throw TypeError(regexp + ' is not a regexp!');
var S = String(this);
var flags = 'flags' in RegExpProto ? String(regexp.flags) : getFlags.call(regexp);
var rx = new RegExp(regexp.source, ~flags.indexOf('g') ? flags : 'g' + flags);
2017-05-28 00:38:50 +02:00
rx.lastIndex = toLength(regexp.lastIndex);
return new $RegExpStringIterator(rx, S);
}
2017-08-14 05:01:11 +02:00
});