🆙 Add cms i using 🆙

This commit is contained in:
Remco
2025-11-25 22:42:56 +01:00
parent 94704e0925
commit d44196149e
35591 changed files with 3601123 additions and 0 deletions
@@ -0,0 +1,33 @@
'use strict';
const queue = Array(8);
let len = 0;
let ticked = false;
function tick() {
let i = -1;
while (++i < len) {
const promise = queue[i];
queue[i] = undefined;
switch (promise._resolved) {
case 1:
promise._callResolve();
break;
case 2:
promise._callReject();
break;
}
}
len = 0;
ticked = false;
}
function invoke(promise) {
if (ticked === false) {
setImmediate(tick);
ticked = true;
}
queue[len++] = promise;
}
module.exports = invoke;
@@ -0,0 +1,302 @@
'use strict';
const { call3, callProxyReciever } = require('./util');
const [setParallel, setParallelWithOrder, setSeries] = [
[iterateArrayParallel, iterateObjectParallel],
[iterateArrayParallel, iterateObjectParallelWithOrder],
[iterateArraySeries, iterateObjectSeries]
].map(createSet);
const arrayIteratorList = [
iterateArrayParallel,
iterateArrayWithString,
iterateArrayWithObject,
iterateArrayWithArray
];
const objectIteratorList = [
iterateObjectParallel,
iterateObjectWithString,
iterateObjectWithObject,
iterateObjectWithArray
];
const [setShorthand, setShorthandWithOrder, setPickShorthand, setOmitShorthand] = [
[arrayIteratorList, objectIteratorList],
[arrayIteratorList, [iterateObjectParallelWithOrder, ...objectIteratorList.slice(1)]],
[
[...arrayIteratorList.slice(0, 3), iteratePickWithArray],
[...objectIteratorList.slice(0, 3), iteratePickWithArray]
],
[
[...arrayIteratorList.slice(0, 3), iterateOmitWithArray],
[...objectIteratorList.slice(0, 3), iterateOmitWithArray]
]
].map(createSetShorthand);
module.exports = {
execute,
setParallel,
setParallelWithOrder,
setShorthand,
setShorthandWithOrder,
setPickShorthand,
setOmitShorthand,
setSeries,
setLimit
};
function execute(collection) {
this._callResolve = this._iterate;
this._set(collection);
this._execute();
}
function createSet([iterateArray, iterateObject]) {
return function set(collection) {
if (Array.isArray(collection)) {
this._coll = collection;
this._size = collection.length;
this._iterate = iterateArray;
} else if (collection && typeof collection === 'object') {
const keys = Object.keys(collection);
this._coll = collection;
this._size = keys.length;
this._keys = keys;
this._iterate = iterateObject;
} else {
this._size = 0;
}
this._rest = this._size;
return this;
};
}
function createSetShorthand(list) {
const [getArrayIterator, getObjectIterator] = list.map(createIteratorGetter);
return function set(collection) {
if (Array.isArray(collection)) {
this._coll = collection;
this._size = collection.length;
this._iterate = getArrayIterator(this._iterator);
} else if (collection && typeof collection === 'object') {
const keys = Object.keys(collection);
this._coll = collection;
this._size = keys.length;
this._keys = keys;
this._iterate = getObjectIterator(this._iterator);
} else {
this._size = 0;
}
this._rest = this._size;
return this;
};
}
function createIteratorGetter([
iterateParallel,
iterateWithString,
iterateWithObject,
iterateWithArray
]) {
return iterator => {
switch (typeof iterator) {
case 'function':
return iterateParallel;
case 'string':
return iterateWithString;
case 'object':
return Array.isArray(iterator) ? iterateWithArray : iterateWithObject;
}
};
}
function setLimit(collection) {
setSeries.call(this, collection);
const { _limit, _size } = this;
this._limit = _limit < _size ? _limit : _size;
this._callRest = _size - this._limit;
return this;
}
function iterateArrayParallel() {
const { _rest, _iterator, _coll } = this;
let i = -1;
while (++i < _rest && callProxyReciever(call3(_iterator, _coll[i], i, _coll), this, i)) {}
}
function iterateObjectParallel() {
const { _rest, _iterator, _coll, _keys } = this;
let i = -1;
while (++i < _rest) {
const key = _keys[i];
if (callProxyReciever(call3(_iterator, _coll[key], key, _coll), this, i) === false) {
break;
}
}
}
function iterateObjectParallelWithOrder() {
const { _rest, _iterator, _coll, _keys, _result } = this;
let i = -1;
while (++i < _rest) {
const key = _keys[i];
_result[key] = undefined;
if (callProxyReciever(call3(_iterator, _coll[key], key, _coll), this, i) === false) {
break;
}
}
}
function iterateArraySeries() {
const { _coll } = this;
const i = this._index++;
callProxyReciever(call3(this._iterator, _coll[i], i, _coll), this, i);
}
function iterateObjectSeries() {
const { _coll } = this;
const i = this._index++;
const key = this._keys[i];
callProxyReciever(call3(this._iterator, _coll[key], key, _coll), this, i);
}
function iterateArrayWithString() {
const { _iterator, _coll } = this;
let i = -1;
while (++i < this._size) {
const obj = _coll[i];
if (obj) {
this._callResolve(obj[_iterator], i);
} else {
this._callResolve(undefined, i);
}
}
}
function iterateObjectWithString() {
const { _iterator, _coll, _keys } = this;
let i = -1;
while (++i < this._size) {
const obj = _coll[_keys[i]];
if (obj) {
this._callResolve(obj[_iterator], i);
} else {
this._callResolve(undefined, i);
}
}
}
function iterateArrayWithArray() {
const { _coll } = this;
const [key, value] = this._iterator;
let i = -1;
while (++i < this._size) {
const obj = _coll[i];
if (obj) {
this._callResolve(obj[key] === value, i);
} else {
this._callResolve(undefined, i);
}
}
}
function iterateObjectWithArray() {
const { _coll, _keys } = this;
const [key, value] = this._iterator;
let i = -1;
while (++i < this._size) {
const obj = _coll[_keys[i]];
if (obj) {
this._callResolve(obj[key] === value, i);
} else {
this._callResolve(undefined, i);
}
}
}
function iterateArrayWithObject() {
const { _iterator: object, _coll } = this;
const keys = Object.keys(object);
let i = -1;
first: while (++i < this._size) {
const obj = _coll[i];
if (!obj) {
this._callResolve(undefined, i);
continue;
}
let l = keys.length;
while (l--) {
const key = keys[l];
if (obj[key] !== object[key]) {
this._callResolve(false, i);
continue first;
}
}
this._callResolve(true, i);
}
}
function iterateObjectWithObject() {
const { _iterator: object, _coll, _keys } = this;
const keys = Object.keys(object);
let i = -1;
first: while (++i < this._size) {
const obj = _coll[_keys[i]];
if (!obj) {
this._callResolve(undefined, i);
continue;
}
let l = keys.length;
while (l--) {
const key = keys[l];
if (obj[key] !== object[key]) {
this._callResolve(false, i);
continue first;
}
}
this._callResolve(true, i);
}
}
function iteratePickWithArray() {
const { _coll, _result } = this;
pick(this._iterator);
this._promise._resolve(_result);
function pick(array) {
let i = -1;
while (++i < array.length) {
const key = array[i];
if (Array.isArray(key)) {
pick(key);
continue;
}
if (_coll.hasOwnProperty(key)) {
_result[key] = _coll[key];
}
}
}
}
function iterateOmitWithArray() {
const { _coll, _result } = this;
const map = {};
createMap(this._iterator);
Object.keys(_coll).forEach(key => {
if (map.hasOwnProperty(key) === false) {
_result[key] = _coll[key];
}
});
this._promise._resolve(_result);
function createMap(array) {
let i = -1;
while (++i < array.length) {
const key = array[i];
if (Array.isArray(key)) {
createMap(key);
continue;
}
map[key] = true;
}
}
}
@@ -0,0 +1,93 @@
'use strict';
const { AigleProxy } = require('aigle-core');
const Aigle = require('../aigle');
const { map } = require('../map');
const { mapValues } = require('../mapValues');
const { INTERNAL, PENDING, apply, callProxyReciever } = require('./util');
module.exports = { createProxy };
class MixinProxy extends AigleProxy {
constructor(func, exec, args) {
super();
this._promise = new Aigle(INTERNAL);
this._func = func;
this._args = args;
this._execute = exec;
if (args[0] === PENDING) {
this._set = this._callResolve;
this._callResolve = exec;
}
}
_callResolve(value) {
this._promise._resolve(value);
}
_callReject(reason) {
this._promise._reject(reason);
}
}
function execute(value) {
const { _args } = this;
if (_args[0] === PENDING) {
_args[0] = value;
this._callResolve = this._set;
}
callProxyReciever(apply(this._func, _args), this);
return this._promise;
}
function executeWithPromisify(value) {
const { _args } = this;
if (_args[0] === PENDING) {
_args[0] = value;
this._callResolve = this._set;
} else {
value = _args[0];
}
const iterator = _args[1];
const isFunc = typeof iterator === 'function';
if (isFunc && Array.isArray(value)) {
callIterator(this, map, array => {
let index = 0;
_args[1] = () => array[index++];
callProxyReciever(apply(this._func, _args), this);
});
} else if (isFunc && value && typeof value === 'object') {
callIterator(this, mapValues, object => {
let index = 0;
const keys = Object.keys(object);
_args[1] = () => object[keys[index++]];
callProxyReciever(apply(this._func, _args), this);
});
} else {
callProxyReciever(apply(this._func, _args), this);
}
return this._promise;
}
function callIterator(proxy, func, onFulfilled) {
const [collection, iterator] = proxy._args;
const p = func(collection, (value, key) => iterator(value, key, collection));
return p._resolved === 1
? onFulfilled(p._value)
: p.then(onFulfilled, error => proxy._callReject(error));
}
/**
* @private
* @param {function} func
* @param {boolean} promisify
*/
function createProxy(func, promisify) {
const exec = promisify ? executeWithPromisify : execute;
return class extends MixinProxy {
constructor(...args) {
super(func, exec, args);
}
};
}
@@ -0,0 +1,14 @@
'use strict';
class Queue {
constructor(size = 8) {
this.array = Array(size);
this.length = 0;
}
push(task) {
this.array[this.length++] = task;
}
}
module.exports = Queue;
+442
View File
@@ -0,0 +1,442 @@
'use strict';
const { AigleCore } = require('aigle-core');
const { version: VERSION } = require('../../package.json');
const DEFAULT_LIMIT = 8;
const errorObj = { e: undefined };
const iteratorSymbol = typeof Symbol === 'function' ? Symbol.iterator : function SYMBOL() {};
const isNode =
typeof process === 'object' && Object.prototype.toString.call(process) === '[object process]';
const iterators = [
createArrayIterator,
createObjectIterator,
createSetIterator,
createMapIterator
].map(createIterator => [callProxyReciever, callProxyRecieverWithFunc].map(createIterator));
const [
[, promiseArrayIterator],
[, promiseObjectIterator],
[, promiseSetIterator],
[, promiseMapIterator]
] = iterators;
const [
[promiseArrayEach, promiseArrayEachWithFunc],
[promiseObjectEach, promiseObjectEachWithFunc],
[promiseSetEach, promiseSetEachWithFunc],
[promiseMapEach, promiseMapEachWithFunc]
] = [createArrayEach, createObjectEach, createSetEach, createMapEach].map((createEach, index) =>
iterators[index].map(createEach)
);
module.exports = {
VERSION,
DEFAULT_LIMIT,
INTERNAL,
PENDING,
UNHANDLED,
defaultIterator,
errorObj,
iteratorSymbol,
call0,
call1,
call3,
apply,
callResolve,
callReject,
callReceiver,
callThen,
callProxyReciever,
callProxyRecieverWithFunc,
promiseArrayIterator,
promiseArrayEach,
promiseArrayEachWithFunc,
promiseObjectIterator,
promiseObjectEach,
promiseObjectEachWithFunc,
promiseSetIterator,
promiseSetEach,
promiseSetEachWithFunc,
promiseMapIterator,
promiseMapEach,
promiseMapEachWithFunc,
compactArray,
concatArray,
clone,
createEmptyObject,
sortArray,
sortObject,
printWarning
};
function INTERNAL() {}
function PENDING() {}
function UNHANDLED() {}
function defaultIterator(n) {
return n;
}
function call0(handler) {
try {
return handler();
} catch (e) {
errorObj.e = e;
return errorObj;
}
}
function call1(handler, value) {
try {
return handler(value);
} catch (e) {
errorObj.e = e;
return errorObj;
}
}
function call3(handler, arg1, arg2, arg3) {
try {
return handler(arg1, arg2, arg3);
} catch (e) {
errorObj.e = e;
return errorObj;
}
}
function apply(handler, array) {
try {
switch (array.length) {
case 0:
return handler();
case 1:
return handler(array[0]);
case 2:
return handler(array[0], array[1]);
case 3:
return handler(array[0], array[1], array[2]);
default:
return handler.apply(null, array);
}
} catch (e) {
errorObj.e = e;
return errorObj;
}
}
function callResolve(receiver, onFulfilled, value) {
typeof onFulfilled === 'function'
? callReceiver(receiver, call1(onFulfilled, value))
: receiver._resolve(value);
}
function callReject(receiver, onRejected, reason) {
typeof onRejected === 'function'
? callReceiver(receiver, call1(onRejected, reason))
: receiver._reject(reason);
}
function callReceiver(receiver, promise) {
if (promise === errorObj) {
receiver._reject(errorObj.e);
return;
}
if (!promise || !promise.then) {
receiver._resolve(promise);
return;
}
if (promise instanceof AigleCore) {
switch (promise._resolved) {
case 0:
promise._addReceiver(receiver, INTERNAL);
return;
case 1:
receiver._resolve(promise._value);
return;
case 2:
promise.suppressUnhandledRejections();
receiver._reject(promise._value);
return;
}
}
callThen(promise, receiver);
}
function callThen(promise, receiver) {
promise.then(resolve, reject);
function resolve(value) {
receiver._resolve(value);
}
function reject(reason) {
receiver._reject(reason);
}
}
function callProxyThen(promise, receiver, key) {
promise.then(resolve, reject);
function resolve(value) {
receiver._callResolve(value, key);
}
function reject(reason) {
receiver._callReject(reason, key);
}
}
function callProxyReciever(promise, receiver, key) {
if (promise instanceof AigleCore) {
switch (promise._resolved) {
case 0:
promise._addReceiver(receiver, key);
return true;
case 1:
receiver._callResolve(promise._value, key);
return true;
case 2:
promise.suppressUnhandledRejections();
return receiver._callReject(promise._value, key) === true;
}
}
if (promise === errorObj) {
return receiver._callReject(errorObj.e, key) === true;
}
if (promise && promise.then) {
callProxyThen(promise, receiver, key);
} else {
receiver._callResolve(promise, key);
}
return true;
}
function callProxyRecieverWithFunc(promise, receiver, index) {
if (typeof promise === 'function') {
promise = promise();
}
return callProxyReciever(promise, receiver, index);
}
function createArrayIterator(handler) {
return (receiver, coll, index) => handler(coll[index], receiver, index);
}
function createArrayEach(iterator) {
return (receiver, times, coll) => {
let i = -1;
while (++i < times && iterator(receiver, coll, i)) {}
};
}
function createObjectIterator(handler) {
return (receiver, coll, index, result, keys) => {
const key = keys[index];
result[key] = undefined;
return handler(coll[key], receiver, key);
};
}
function createObjectEach(iterator) {
return (receiver, times, coll, result, keys) => {
let i = -1;
while (++i < times && iterator(receiver, coll, i, result, keys)) {}
};
}
function createSetIterator(handler) {
return (receiver, iter, index) => {
const item = iter.next();
return item.done === false && handler(item.value, receiver, index);
};
}
function createSetEach(iterator) {
return (receiver, times, coll) => {
const iter = coll[iteratorSymbol]();
let i = -1;
while (++i < times && iterator(receiver, iter, i)) {}
};
}
function createMapIterator(handler) {
return (receiver, iter, index, result) => {
const item = iter.next();
if (item.done) {
return false;
}
const [key, promise] = item.value;
result.set(key, undefined);
return handler(promise, receiver, key);
};
}
function createMapEach(iterator) {
return (receiver, times, coll, result) => {
const iter = coll[iteratorSymbol]();
let i = -1;
while (++i < times && iterator(receiver, iter, i, result)) {}
};
}
function compactArray(array) {
let i = -1;
const l = array.length;
const result = [];
while (++i < l) {
const value = array[i];
if (value !== INTERNAL) {
result.push(value);
}
}
return result;
}
function concatArray(array) {
let i = -1;
const l = array.length;
const result = [];
while (++i < l) {
const value = array[i];
if (Array.isArray(value)) {
result.push(...value);
} else if (value !== undefined) {
result.push(value);
}
}
return result;
}
function clone(target) {
return Array.isArray(target) ? cloneArray(target) : cloneObject(target);
}
function cloneArray(array) {
let l = array.length;
const result = Array(l);
while (l--) {
result[l] = array[l];
}
return result;
}
function cloneObject(object) {
const keys = Object.keys(object);
let l = keys.length;
const result = {};
while (l--) {
const key = keys[l];
result[key] = object[key];
}
return result;
}
function createEmptyObject(object, keys) {
let i = -1;
const l = keys.length;
const result = {};
while (++i < l) {
result[keys[i]] = undefined;
}
return result;
}
/**
* @private
* @param {Array} array
* @param {number[]} criteria
*/
function sortArray(array, criteria) {
const l = array.length;
const indices = Array(l);
for (let i = 0; i < l; i++) {
indices[i] = i;
}
quickSort(criteria, 0, l - 1, indices);
const result = Array(l);
for (let n = 0; n < l; n++) {
const i = indices[n];
result[n] = i === undefined ? array[n] : array[i];
}
return result;
}
/**
* @private
* @param {Object} object
* @param {string[]} keys
* @param {number[]} criteria
*/
function sortObject(object, keys, criteria) {
const l = keys.length;
const indices = Array(l);
for (let i = 0; i < l; i++) {
indices[i] = i;
}
quickSort(criteria, 0, l - 1, indices);
const result = Array(l);
for (let n = 0; n < l; n++) {
const i = indices[n];
result[n] = object[keys[i === undefined ? n : i]];
}
return result;
}
function partition(array, i, j, mid, indices) {
let l = i;
let r = j;
while (l <= r) {
i = l;
while (l < r && array[l] < mid) {
l++;
}
while (r >= i && array[r] >= mid) {
r--;
}
if (l > r) {
break;
}
swap(array, indices, l++, r--);
}
return l;
}
function swap(array, indices, l, r) {
const n = array[l];
array[l] = array[r];
array[r] = n;
const i = indices[l];
indices[l] = indices[r];
indices[r] = i;
}
function quickSort(array, i, j, indices) {
if (i === j) {
return;
}
let k = i;
while (++k <= j && array[i] === array[k]) {
const l = k - 1;
if (indices[l] > indices[k]) {
const i = indices[l];
indices[l] = indices[k];
indices[k] = i;
}
}
if (k > j) {
return;
}
const p = array[i] > array[k] ? i : k;
k = partition(array, i, j, array[p], indices);
quickSort(array, i, k - 1, indices);
quickSort(array, k, j, indices);
}
function printWarning(message) {
isNode
? console.warn(`\u001b[31m${message}\u001b[0m\n`)
: console.warn(`%c${message}`, 'color: red');
}