-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation, tests, readme
- Loading branch information
Showing
113 changed files
with
3,512 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{ | ||
"root": true, | ||
|
||
"extends": "@ljharb", | ||
|
||
"globals": { | ||
"Iterator": false, | ||
}, | ||
|
||
"rules": { | ||
"array-bracket-newline": 0, | ||
"func-name-matching": 0, | ||
"id-length": 0, | ||
"max-lines-per-function": 0, | ||
"multiline-comment-style": 0, | ||
"new-cap": [2, { | ||
"capIsNewExceptions": [ | ||
"Call", | ||
"CreateIteratorFromClosure", | ||
"CreateIterResultObject", | ||
"GeneratorResume", | ||
"GeneratorResumeAbrupt", | ||
"GeneratorStart", | ||
"GeneratorValidate", | ||
"Get", | ||
"GetIntrinsic", | ||
"GetIterator", | ||
"GetIteratorDirect", | ||
"GetIteratorFlattenable", | ||
"GetMethod", | ||
"IsCallable", | ||
"IteratorClose", | ||
"IteratorComplete", | ||
"IteratorNext", | ||
"IteratorStep", | ||
"IteratorValue", | ||
"NormalCompletion", | ||
"OrdinaryHasInstance", | ||
"OrdinaryObjectCreate", | ||
"PromiseResolve", | ||
"ThrowCompletion", | ||
"ToBoolean", | ||
"ToIntegerOrInfinity", | ||
"ToNumber", | ||
"ToObject", | ||
"Type", | ||
], | ||
}], | ||
"no-negated-condition": 1, | ||
"object-curly-newline": 0, | ||
"sort-keys": 0, | ||
}, | ||
|
||
"overrides": [ | ||
{ | ||
"files": "test/**", | ||
"rules": { | ||
"max-params": 0, | ||
}, | ||
}, | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# These are supported funding model platforms | ||
|
||
github: [ljharb] | ||
patreon: # Replace with a single Patreon username | ||
open_collective: # Replace with a single Open Collective username | ||
ko_fi: # Replace with a single Ko-fi username | ||
tidelift: npm/iterator-helpers | ||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry | ||
liberapay: # Replace with a single Liberapay username | ||
issuehunt: # Replace with a single IssueHunt username | ||
otechie: # Replace with a single Otechie username | ||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: 'Tests: node.js < 10' | ||
|
||
on: [pull_request, push] | ||
|
||
jobs: | ||
tests: | ||
uses: ljharb/actions/.github/workflows/node.yml@main | ||
with: | ||
range: '< 10' | ||
type: minors | ||
command: npm run tests-only | ||
|
||
node: | ||
name: 'node < 10' | ||
needs: [tests] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- run: 'echo tests completed' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
name: 'Tests: pretest/posttest' | ||
|
||
on: [pull_request, push] | ||
|
||
jobs: | ||
tests: | ||
uses: ljharb/actions/.github/workflows/pretest.yml@main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: 'Tests: node.js >= 10' | ||
|
||
on: [pull_request, push] | ||
|
||
jobs: | ||
tests: | ||
uses: ljharb/actions/.github/workflows/node.yml@main | ||
with: | ||
range: '>= 10' | ||
type: minors | ||
command: npm run tests-only | ||
|
||
node: | ||
name: 'node >= 10' | ||
needs: [tests] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- run: 'echo tests completed' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: Automatic Rebase | ||
|
||
on: [pull_request_target] | ||
|
||
jobs: | ||
_: | ||
uses: ljharb/actions/.github/workflows/rebase.yml@main | ||
secrets: | ||
token: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: Require “Allow Edits” | ||
|
||
on: [pull_request_target] | ||
|
||
jobs: | ||
_: | ||
name: "Require “Allow Edits”" | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: ljharb/require-allow-edits@main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,3 +107,5 @@ dist | |
npm-shrinkwrap.json | ||
package-lock.json | ||
yarn.lock | ||
|
||
.npmignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
package-lock=false | ||
allow-same-version=true | ||
message=v%s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"all": true, | ||
"check-coverage": false, | ||
"reporter": ["text-summary", "text", "html", "json"], | ||
"lines": 86, | ||
"statements": 85.93, | ||
"functions": 82.43, | ||
"branches": 76.06, | ||
"exclude": [ | ||
"coverage", | ||
"test" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
require('./shim')(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict'; | ||
|
||
var OrdinaryHasInstance = require('es-abstract/2022/OrdinaryHasInstance'); | ||
var OrdinaryObjectCreate = require('es-abstract/2022/OrdinaryObjectCreate'); | ||
var ToObject = require('es-abstract/2022/ToObject'); | ||
var Type = require('es-abstract/2022/Type'); | ||
|
||
var GetIteratorFlattenable = require('../aos/GetIteratorFlattenable'); | ||
|
||
var $Iterator = require('../Iterator/polyfill')(); | ||
var $WrapForValidIteratorPrototype = require('../WrapForValidIteratorPrototype'); | ||
|
||
var SLOT = require('internal-slot'); | ||
|
||
module.exports = function from(O) { | ||
if (Type(O) === 'String') { | ||
// eslint-disable-next-line no-param-reassign | ||
O = ToObject(O); // step 1 | ||
} | ||
|
||
var iteratorRecord = GetIteratorFlattenable(O, 'sync'); // step 2 | ||
|
||
var hasInstance = OrdinaryHasInstance($Iterator, iteratorRecord['[[Iterator]]']); // step 3 | ||
|
||
if (hasInstance) { // step 4 | ||
return iteratorRecord['[[Iterator]]']; // step 4.a | ||
} | ||
|
||
var wrapper = OrdinaryObjectCreate($WrapForValidIteratorPrototype); // , ['[[Iterated]]']); // step 5 | ||
|
||
SLOT.set(wrapper, '[[Iterated]]', iteratorRecord); // step 6 | ||
|
||
return wrapper; // step 7 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
|
||
var callBind = require('call-bind'); | ||
var define = require('define-properties'); | ||
|
||
var implementation = require('./implementation'); | ||
var getPolyfill = require('./polyfill'); | ||
var shim = require('./shim'); | ||
|
||
var bound = callBind(getPolyfill(), null); | ||
|
||
define(bound, { | ||
getPolyfill: getPolyfill, | ||
implementation: implementation, | ||
shim: shim | ||
}); | ||
|
||
module.exports = bound; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
var implementation = require('./implementation'); | ||
|
||
var $Iterator = require('../Iterator'); | ||
|
||
module.exports = function getPolyfill() { | ||
return typeof $Iterator.from === 'function' ? $Iterator.from : implementation; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
|
||
var getPolyfill = require('./polyfill'); | ||
var define = require('define-properties'); | ||
|
||
var getIteratorPolyfill = require('../Iterator/polyfill'); | ||
|
||
module.exports = function shimIteratorFrom() { | ||
var $Iterator = getIteratorPolyfill(); | ||
var polyfill = getPolyfill(); | ||
define( | ||
$Iterator, | ||
{ from: polyfill }, | ||
{ from: function () { return $Iterator.from !== polyfill; } } | ||
); | ||
|
||
return polyfill; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
require('./shim')(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
var $Iterator = require('../Iterator/polyfill')(); | ||
|
||
module.exports = $Iterator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
|
||
var define = require('define-properties'); | ||
var bind = require('function-bind'); | ||
|
||
var implementation = require('./implementation'); | ||
var getPolyfill = require('./polyfill'); | ||
var shim = require('./shim'); | ||
|
||
var polyfill = bind.call(getPolyfill()); | ||
|
||
define(polyfill, { | ||
getPolyfill: getPolyfill, | ||
implementation: implementation, | ||
shim: shim | ||
}); | ||
|
||
module.exports = polyfill; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
'use strict'; | ||
|
||
var implementation = require('./implementation'); | ||
|
||
module.exports = function getPolyfill() { | ||
return implementation; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
|
||
var define = require('define-properties'); | ||
var getPolyfill = require('./polyfill'); | ||
|
||
var $IteratorPrototype = require('iterator.prototype'); | ||
|
||
var $Iterator = require('./implementation'); | ||
|
||
module.exports = function shimIteratorPrototypeCtor() { | ||
var polyfill = getPolyfill(); | ||
|
||
define( | ||
$IteratorPrototype, | ||
{ constructor: $Iterator }, | ||
{ constructor: function () { return $Iterator.constructor !== polyfill; } } | ||
); | ||
|
||
return polyfill; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
'use strict'; | ||
|
||
require('./shim')(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
'use strict'; | ||
|
||
var GetIntrinsic = require('get-intrinsic'); | ||
|
||
var $RangeError = GetIntrinsic('%RangeError%'); | ||
|
||
var IteratorClose = require('es-abstract/2022/IteratorClose'); | ||
var IteratorStep = require('es-abstract/2022/IteratorStep'); | ||
var IteratorValue = require('es-abstract/2022/IteratorValue'); | ||
var ToIntegerOrInfinity = require('es-abstract/2022/ToIntegerOrInfinity'); | ||
var ToNumber = require('es-abstract/2022/ToNumber'); | ||
|
||
var GetIteratorDirect = require('../aos/GetIteratorDirect'); | ||
var CreateIteratorFromClosure = require('../aos/CreateIteratorFromClosure'); | ||
|
||
var iterHelperProto = require('../IteratorHelperPrototype'); | ||
|
||
var isNaN = require('es-abstract/helpers/isNaN'); | ||
|
||
var SLOT = require('internal-slot'); | ||
|
||
module.exports = function drop(limit) { | ||
var iterated = GetIteratorDirect(this); // step 1 | ||
|
||
var numLimit = ToNumber(limit); // step 2 | ||
if (isNaN(numLimit)) { | ||
throw new $RangeError('`limit` must be a non-NaN number'); // step 3 | ||
} | ||
|
||
var integerLimit = ToIntegerOrInfinity(numLimit); // step 4 | ||
if (integerLimit < 0) { | ||
throw new $RangeError('`limit` must be a >= 0'); // step 5 | ||
} | ||
|
||
var sentinel = {}; | ||
var remaining = integerLimit; // step 6.a | ||
var closure = function () { // step 6 | ||
var next; | ||
while (remaining > 0) { // step 6.b | ||
if (remaining !== Infinity) { // step 6.b.i | ||
remaining -= 1; // step 6.b.i.1 | ||
} | ||
|
||
next = IteratorStep(iterated['[[Iterator]]']); // step 6.b.ii | ||
if (!next) { | ||
// return void undefined; // step 6.b.iii | ||
return sentinel; | ||
} | ||
} | ||
// while (true) { // step 6.c | ||
next = IteratorStep(iterated['[[Iterator]]']); // step 6.c.i | ||
if (!next) { | ||
// return void undefined; // step 6.c.ii | ||
return sentinel; | ||
} | ||
try { | ||
var value = IteratorValue(next); // step 6.c.iii | ||
return value; // step 6.c.iii | ||
} catch (e) { | ||
// close iterator // step 6.c.icv | ||
IteratorClose( | ||
iterated['[[Iterator]]'], | ||
function () { throw e; } | ||
); | ||
} | ||
// } | ||
return void undefined; | ||
}; | ||
SLOT.set(closure, '[[Sentinel]]', sentinel); // for the userland implementation | ||
|
||
return CreateIteratorFromClosure(closure, 'Iterator Helper', iterHelperProto); // step 4 | ||
}; |
Oops, something went wrong.