/
drndsv
/
react
Обзор
Документация
Войти
/
drndsv
/
react
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
node_modules/es-abstract/helpers/getIteratorMethod.js
47 строк
1 KB
drndsv
Initial commit
14 апр 2025, 22:53
14 апр 2025, 22:53
641ac8a
Код
Авторство
О чём код?
'use strict'; var hasSymbols = require('has-symbols')(); var GetIntrinsic = require('get-intrinsic'); var callBound = require('call-bind/callBound'); var isString = require('is-string'); var $iterator = GetIntrinsic('%Symbol.iterator%', true); var $stringSlice = callBound('String.prototype.slice'); var $String = GetIntrinsic('%String%'); module.exports = function getIteratorMethod(ES, iterable) { var usingIterator; if (hasSymbols) { usingIterator = ES.GetMethod(iterable, $iterator); } else if (ES.IsArray(iterable)) { usingIterator = function () { var i = -1; var arr = this; // eslint-disable-line no-invalid-this return { next: function () { i += 1; return { done: i >= arr.length, value: arr[i] }; } }; }; } else if (isString(iterable)) { usingIterator = function () { var i = 0; return { next: function () { var nextIndex = ES.AdvanceStringIndex($String(iterable), i, true); var value = $stringSlice(iterable, i, nextIndex); i = nextIndex; return { done: nextIndex > iterable.length, value: value }; } }; }; } return usingIterator; };