project bootstrap

This commit is contained in:
2023-11-25 18:12:47 -05:00
parent 5cd875ae80
commit 6ef22d88f9
39139 changed files with 4944609 additions and 2 deletions
+26
View File
@@ -0,0 +1,26 @@
'use strict';
var callBound = require('call-bind/callBound');
var GetIntrinsic = require('get-intrinsic');
var SameValue = require('es-abstract/2023/SameValue');
var $TypeError = GetIntrinsic('%TypeError%');
var $filter = callBound('Array.prototype.filter');
var $push = callBound('Array.prototype.push');
module.exports = function AddValueToKeyedGroup(groups, key, value) {
var found = $filter(groups, function (group) {
return SameValue(group['[[Key]]'], key); // eslint-disable-line new-cap
});
if (found.length > 0) {
var g = found[0];
if (found.length !== 1) {
throw new $TypeError('Assertion failed: more than 1 Record inside `groups` has a `[[Key]]` that is SameValue to `key`');
}
$push(g['[[Elements]]'], value); // step 1.a.ii
} else {
var group = { '[[Key]]': key, '[[Elements]]': [value] }; // eslint-disable-line sort-keys
$push(groups, group); // step 3
}
};
+77
View File
@@ -0,0 +1,77 @@
'use strict';
var GetIntrinsic = require('get-intrinsic');
var AddValueToKeyedGroup = require('./AddValueToKeyedGroup');
var Call = require('es-abstract/2023/Call');
var GetIterator = require('es-abstract/2023/GetIterator');
var IsCallable = require('es-abstract/2023/IsCallable');
var IteratorClose = require('es-abstract/2023/IteratorClose');
var IteratorStep = require('es-abstract/2023/IteratorStep');
var IteratorValue = require('es-abstract/2023/IteratorValue');
var RequireObjectCoercible = require('es-abstract/2023/RequireObjectCoercible');
var ThrowCompletion = require('es-abstract/2023/ThrowCompletion');
var ToPropertyKey = require('es-abstract/2023/ToPropertyKey');
var maxSafeInteger = require('es-abstract/helpers/maxSafeInteger');
var $TypeError = GetIntrinsic('%TypeError%');
module.exports = function GroupBy(items, callbackfn, coercion) {
if (coercion !== 'property' && coercion !== 'zero') {
throw new $TypeError('Assertion failed: `coercion` must be `"property"` or `"zero"`');
}
RequireObjectCoercible(items); // step 1
if (!IsCallable(callbackfn)) { // step 2
throw new $TypeError('`callbackfn` must be callable');
}
var groups = []; // step 3
var iteratorRecord = GetIterator(items, 'sync'); // step 4
var k = 0; // step 5
// eslint-disable-next-line no-constant-condition
while (true) { // step 6
if (k >= maxSafeInteger) { // step 6.a
var error = ThrowCompletion(new $TypeError('Iteration count exceeds the max safe integer value')); // step 6.a.i
return IteratorClose(iteratorRecord, error); // step 6.a.ii
}
var next = IteratorStep(iteratorRecord); // step 6.b
if (!next) { // step 6.c
return groups; // step 6.c.i
}
var value = IteratorValue(next); // step 6.d
var key;
try {
key = Call(callbackfn, undefined, [value, k]); // step 6.e
} catch (e) {
IteratorClose(iteratorRecord, ThrowCompletion(e)); // step 6.f
}
if (coercion === 'property') { // step 6.g
try {
key = ToPropertyKey(key); // step 6.g.i
} catch (e) {
IteratorClose(iteratorRecord, ThrowCompletion(e)); // step 6.g.ii
}
} else {
if (coercion !== 'zero') {
throw new $TypeError('Assertion failed: `coercion` should be `"zero"` here'); // step 6.h.i
}
if (key === 0) { // step 6.h.ii
key = 0; // handle negative zero
}
}
AddValueToKeyedGroup(groups, key, value); // step 6.i
k += 1; // step 6.j
}
};