@creejs/commons-collection 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/cjs/index-dev.cjs +175 -0
- package/dist/cjs/index-dev.cjs.map +1 -0
- package/dist/cjs/index-min.cjs +2 -0
- package/dist/cjs/index-min.cjs.map +1 -0
- package/dist/esm/index-dev.js +170 -0
- package/dist/esm/index-dev.js.map +1 -0
- package/dist/esm/index-min.js +2 -0
- package/dist/esm/index-min.js.map +1 -0
- package/dist/umd/index.dev.js +181 -0
- package/dist/umd/index.dev.js.map +1 -0
- package/dist/umd/index.min.js +2 -0
- package/dist/umd/index.min.js.map +1 -0
- package/package.json +55 -0
- package/types/capped-set.d.ts +75 -0
- package/types/index.d.ts +6 -0
package/README.md
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
function c(t){return !!h(t)&&t>0}function h(t){return null!=t&&"number"==typeof t}var L={assertPositive:q};function q(t,r){if(!c(t))throw new Error(`${r?'"'+r+'" ':" "}Not Positive: ${t}`)}new TextDecoder;new TextEncoder;
|
|
6
|
+
|
|
7
|
+
// internal
|
|
8
|
+
// owned
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @typedef {{
|
|
12
|
+
* value: any,
|
|
13
|
+
* prev: Node|undefined,
|
|
14
|
+
* next: Node|undefined
|
|
15
|
+
* }} Node
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
// module vars
|
|
19
|
+
const { assertPositive } = L;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A set that has a fixed capacity and automatically removes the oldest element when the capacity is reached.
|
|
23
|
+
*
|
|
24
|
+
* @class CappedSet
|
|
25
|
+
*/
|
|
26
|
+
class CappedSet {
|
|
27
|
+
/**
|
|
28
|
+
* Creates a new CappedSet instance with a fixed capacity.
|
|
29
|
+
* @constructor
|
|
30
|
+
* @param {number} capacity - The maximum number of elements the set can hold (must be > 0)
|
|
31
|
+
* @throws {Error} If capacity is less than or equal to 0
|
|
32
|
+
*/
|
|
33
|
+
constructor (capacity) {
|
|
34
|
+
assertPositive(capacity, 'capacity');
|
|
35
|
+
this.capacity = capacity;
|
|
36
|
+
/**
|
|
37
|
+
* @type {Map<any, Node>}
|
|
38
|
+
*/
|
|
39
|
+
this._set = new Map();
|
|
40
|
+
/**
|
|
41
|
+
* @type {Node|undefined}
|
|
42
|
+
*/
|
|
43
|
+
this._head = undefined;
|
|
44
|
+
/**
|
|
45
|
+
* @type {Node|undefined}
|
|
46
|
+
*/
|
|
47
|
+
this._tail = undefined;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
get size () {
|
|
51
|
+
return this._set.size
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 获取最旧的元素
|
|
55
|
+
get oldest () {
|
|
56
|
+
return this._head?.value
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 获取最新的元素
|
|
60
|
+
get newest () {
|
|
61
|
+
return this._tail?.value
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
[Symbol.iterator] () {
|
|
65
|
+
return this._set.keys()
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Adds a value to the capped set. If the value already exists, it will be moved to the most recent position.
|
|
70
|
+
* If the set is at capacity, the oldest element will be removed before adding the new value.
|
|
71
|
+
* @param {*} value - The value to add to the set
|
|
72
|
+
*/
|
|
73
|
+
add (value) {
|
|
74
|
+
if (this._set.has(value)) {
|
|
75
|
+
const node = this._set.get(value);
|
|
76
|
+
node && this._removeNode(node);
|
|
77
|
+
} else if (this.size >= this.capacity) {
|
|
78
|
+
this._removeOldest();
|
|
79
|
+
}
|
|
80
|
+
this._addNew(value);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Checks if the value exists in the set.
|
|
85
|
+
* @param {*} value - The value to check for existence.
|
|
86
|
+
* @returns {boolean} True if the value exists, false otherwise.
|
|
87
|
+
*/
|
|
88
|
+
has (value) {
|
|
89
|
+
return this._set.has(value)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Deletes a value from the capped set.
|
|
94
|
+
* @param {*} value - The value to remove from the set.
|
|
95
|
+
* @returns {boolean} True if the value was found and removed, false otherwise.
|
|
96
|
+
*/
|
|
97
|
+
delete (value) {
|
|
98
|
+
if (this._set.has(value)) {
|
|
99
|
+
const node = this._set.get(value);
|
|
100
|
+
node && this._removeNode(node);
|
|
101
|
+
return true
|
|
102
|
+
}
|
|
103
|
+
return false
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
clear () {
|
|
107
|
+
this._set.clear();
|
|
108
|
+
this._head = undefined;
|
|
109
|
+
this._tail = undefined;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Returns an iterator of the values in the set.
|
|
114
|
+
* @returns {Iterator<any>} An iterator object that yields the values of the set.
|
|
115
|
+
*/
|
|
116
|
+
values () {
|
|
117
|
+
return this._set.keys()
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Adds a new value to the set by creating a node and appending it to the tail.
|
|
122
|
+
* Updates the linked list structure and maintains the set's size.
|
|
123
|
+
* @private
|
|
124
|
+
* @param {*} value - The value to be added to the set.
|
|
125
|
+
*/
|
|
126
|
+
_addNew (value) {
|
|
127
|
+
/**
|
|
128
|
+
* @type {Node}
|
|
129
|
+
*/
|
|
130
|
+
const node = { value, prev: this._tail, next: undefined };
|
|
131
|
+
|
|
132
|
+
if (this._tail) {
|
|
133
|
+
this._tail.next = node;
|
|
134
|
+
} else {
|
|
135
|
+
this._head = node;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
this._tail = node;
|
|
139
|
+
this._set.set(value, node);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Removes a node from the linked list and the internal Set.
|
|
144
|
+
* Updates head/tail pointers and maintains list consistency.
|
|
145
|
+
* @param {Node} node - The node to be removed
|
|
146
|
+
* @private
|
|
147
|
+
*/
|
|
148
|
+
_removeNode (node) {
|
|
149
|
+
if (node.prev) {
|
|
150
|
+
node.prev.next = node.next;
|
|
151
|
+
} else {
|
|
152
|
+
this._head = node.next;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (node.next) {
|
|
156
|
+
node.next.prev = node.prev;
|
|
157
|
+
} else {
|
|
158
|
+
this._tail = node.prev;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
this._set.delete(node.value);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
_removeOldest () {
|
|
165
|
+
if (this._head) {
|
|
166
|
+
this._removeNode(this._head);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
var index = { CappedSet };
|
|
172
|
+
|
|
173
|
+
exports.CappedSet = CappedSet;
|
|
174
|
+
exports.default = index;
|
|
175
|
+
//# sourceMappingURL=index-dev.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-dev.cjs","sources":["../../../lang/dist/esm/index-min.js","../../lib/capped-set.js","../../lib/index.js"],"sourcesContent":["var t={constructorName:r,defaults:function(t,...r){if(null==t)throw new TypeError('\"target\" must not be null or undefined');for(const n of r)if(null!=n)for(const r in n)void 0===t[r]&&(t[r]=n[r]);return t},extend:n,extends:n,equals:function(t,r){if(t===r)return!0;if(\"function\"==typeof t?.equals)return t.equals(r);if(\"function\"==typeof r?.equals)return r.equals(t);return!1},isBrowser:e,isNode:function(){return!e()}};function r(t){return t?.constructor?.name}function n(t,...r){if(null==t)throw new TypeError('\"target\" must not be null or undefined');for(const n of r)if(null!=n)for(const r in n)t[r]=n[r];return t}function e(){return\"undefined\"!=typeof window&&\"undefined\"!=typeof document}var o={isArray:i,isBoolean:s,isBuffer:function(t){return null!=t&&Buffer.isBuffer(t)},isFunction:u,isInstance:f,isIterable:function(t){return null!=t&&\"function\"==typeof t[Symbol.iterator]},isDate:function(t){return null!=t&&t instanceof Date},isError:function(t){return null!=t&&t instanceof Error},isMap:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===Map},isWeakMap:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===WeakMap},isNumber:h,isPositive:c,isNegative:y,isNotNegative:l,isNil:a,isNullOrUndefined:function(t){return null==t},isNull:p,isUndefined:g,isPlainObject:d,isObject:w,isPromise:m,isRegExp:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===RegExp},isSet:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===Set},isWeakSet:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===WeakSet},isStream:function(t){return null!=t&&\"function\"==typeof t.pipe},isString:b,isSymbol:N,isPrimitive:function(t){return null!==t&&(\"string\"==typeof t||\"number\"==typeof t||\"boolean\"==typeof t)},isInt8Array:E,isUint8Array:O,isUint8ClampedArray:$,isInt16Array:v,isUint16Array:S,isInt32Array:U,isUint32Array:x,isFloat32Array:P,isFloat64Array:j,isBigInt64Array:B,isBigUint64Array:I,isTypedArray:A,isArrayBuffer:T};function i(t){return Array.isArray(t)}function s(t){return\"boolean\"==typeof t}function u(t){return\"function\"==typeof t}function f(t){return null!=t&&\"object\"==typeof t&&!d(t)}function a(t){return null==t}function c(t){return!!h(t)&&t>0}function l(t){return!!h(t)&&t>=0}function y(t){return!!h(t)&&t<0}function p(t){return null===t}function g(t){return void 0===t}function h(t){return null!=t&&\"number\"==typeof t}function w(t){return null!=t&&\"object\"==typeof t}function d(t){return null!==t&&\"object\"==typeof t&&(t.constructor===Object||void 0===t.constructor)}function m(t){return null!=t&&\"function\"==typeof t.then}function b(t){return null!=t&&\"string\"==typeof t}function N(t){return null!=t&&\"symbol\"==typeof t}function A(t){return ArrayBuffer.isView(t)&&t.constructor!==DataView}function E(t){return t instanceof Int8Array}function O(t){return t instanceof Uint8Array}function $(t){return t instanceof Uint8ClampedArray}function v(t){return t instanceof Int16Array}function S(t){return t instanceof Uint16Array}function U(t){return t instanceof Int32Array}function x(t){return t instanceof Uint32Array}function P(t){return t instanceof Float32Array}function j(t){return t instanceof Float64Array}function B(t){return t instanceof BigInt64Array}function I(t){return t instanceof BigUint64Array}function T(t){return t instanceof ArrayBuffer}var L={assertNumber:C,assertPositive:q,assertNegative:function(t,r){if(!y(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Negative: ${t}`)},assertNotNegative:D,assertBoolean:function(t,r){if(!s(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Boolean: type=${typeof t} value=${JSON.stringify(t)}`)},assertObject:F,assertPlainObject:function(t,r){if(!d(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not PlainObject: type=${typeof t} value=${JSON.stringify(t)}`)},assertSymbol:function(t,r){if(!N(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Symbol: type=${typeof t} value=${JSON.stringify(t)}`)},assertFunction:M,assertInstance:function(t,r){if(!f(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Class Instance: type=${typeof t} value=${JSON.stringify(t)}`)},assertPromise:R,assertNil:function(t,r){if(!a(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Neither Null nor Undefined: type=${typeof t} value=${JSON.stringify(t)}`)},assertNotNil:W,assertNull:function(t,r){if(!p(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Null: type=${typeof t} value=${JSON.stringify(t)}`)},assertNotNull:function(t,r){if(p(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Should Not Null\")},assertUndefined:function(t,r){if(!g(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Undefined: type=${typeof t} value=${JSON.stringify(t)}`)},assertString:J,assertArray:k,assertStringOrSymbol:function(t,r){if(!b(t)&&!N(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not String or Symbol: type=${typeof t} value=${JSON.stringify(t)}`)},assertInt8Array:function(t,r){if(E(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Int8Array\")},assertUint8Array:function(t,r){if(O(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Uint8Array\")},assertUint8ClampedArray:function(t,r){if($(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Uint8ClampedArray\")},assertInt16Array:function(t,r){if(v(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Int16Array\")},assertUint16Array:function(t,r){if(S(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Uint16Array\")},assertInt32Array:function(t,r){if(U(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Int32Array\")},assertUint32Array:function(t,r){if(x(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Uint32Array\")},assertFloat32Array:function(t,r){if(P(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Float32Array\")},assertFloat64Array:function(t,r){if(j(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Float64Array\")},assertBigInt64Array:function(t,r){if(B(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not BigInt64Array\")},assertBigUint64Array:function(t,r){if(I(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not BigUint64Array\")},assertTypedArray:function(t,r){if(A(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not TypedArray\")},assertArrayBuffer:V};function k(t,r){if(!Array.isArray(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Array: type=${typeof t} value=${JSON.stringify(t)}`)}function J(t,r){if(!b(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not String: type=${typeof t} value=${JSON.stringify(t)}`)}function C(t,r){if(!h(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Number: type=${typeof t} value=${JSON.stringify(t)}`)}function q(t,r){if(!c(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Positive: ${t}`)}function D(t,r){if(!l(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not \"0 or Positive\": ${t}`)}function F(t,r){if(!w(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Object: type=${typeof t} value=${JSON.stringify(t)}`)}function M(t,r){if(!u(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Function: type=${typeof t} value=${JSON.stringify(t)}`)}function R(t,r){if(!m(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Promise: type=${typeof t} value=${JSON.stringify(t)}`)}function W(t,r){if(a(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Should Not Nil\")}function V(t,r){if(!T(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not ArrayBuffer\")}var H={isEmpty:z,assertNotEmpty:G,isBlank:K,assertNotBlank:function(t){if(K(t))throw new Error(`Blank String: ${t}`)},capitalize:function(t){if(J(t),0===t.length)return t;const r=t.charAt(0),n=r.toUpperCase();return r===n?t:n+t.slice(1)},decapitalize:function(t){if(J(t),0===t.length)return t;const r=t.charAt(0),n=r.toLowerCase();return r===n?t:n+t.slice(1)},splitWithFixedLength:function(t,r,n=\" \"){if(J(t),C(r),J(n),0===t.length)return[];if(r<=0)throw new Error(\"length muse >=0\");if(t.length<r)return[t.padEnd(r,n)];const e=[];for(let o=0;o<t.length;o+=r){const i=t.substring(o,o+r);e.push(i.padEnd(r,n))}return e},split:function(t,...r){J(t);if(0===t.length)return[];const n=[...r];0===r.length&&r.push(\",\");const e=Q(t,...n);if(0===e.length)return[];const o=[];let i=\"\",s=0;for(const{marker:r,index:n}of e)i=t.substring(s,n),o.push(i),s=n+r.length;return i=t.substring(s),o.push(i),o},findMarkerPositions:function(t,...r){if(J(t),0===r.length)throw new Error(\"At least one marker must be provided\");const n=[];for(const e of new Set(r)){if(z(e))continue;J(e);let r=t.indexOf(e);for(;-1!==r;)n.push({marker:e,index:r}),r=t.indexOf(e,r+e.length)}return n.sort((t,r)=>t.index-r.index),n},findMarkerPositionsRegex:Q,substringBefore:function(t,r){if(J(t),J(r),0===t.length||0===r.length)return;const n=t.indexOf(r);if(-1===n)return;return t.substring(0,n)},substringBeforeLast:function(t,r){if(J(t),J(r),0===t.length||0===r.length)return;const n=t.lastIndexOf(r);if(-1===n)return;return t.substring(0,n)},substringAfter:function(t,r){if(J(t),J(r),0===t.length||0===r.length)return;const n=t.indexOf(r);if(-1===n)return;return t.substring(n+r.length)},substringAfterLast:function(t,r){if(J(t),J(r),0===t.length||0===r.length)return;const n=t.lastIndexOf(r);if(-1===n)return;return t.substring(n+r.length)},substringBetween:function(t,r,n){G(t),G(r),G(n);const e=t.indexOf(r);if(-1===e)return;const o=t.indexOf(n,e+r.length);if(-1===o)return;return t.substring(e+r.length,o)},substringBetweenGreedy:function(t,r,n){G(t),G(r),G(n);const e=t.indexOf(r);if(-1===e)return;const o=t.lastIndexOf(n);if(-1===o||o<=e)return;return t.substring(e+r.length,o)},substringsBetween:function(t,r,n){G(t),G(r),G(n);const e=[];let o=0;for(;;){const i=t.indexOf(r,o);if(-1===i)break;const s=t.indexOf(n,i+r.length);if(-1===s)break;e.push(t.substring(i+r.length,s)),o=s+n.length}return e}};function z(t){return null==t||(J(t),0===t.length)}function G(t){if(z(t))throw new Error(`Empty String: ${t}`)}function K(t){return null==t||(J(t),0===t.trim().length)}function Q(t,...r){if(J(t),0===r.length)throw new Error(\"At least one marker must be provided\");const n=[...new Set(r.filter(t=>null!=t))].map(t=>(J(t),t.replace(/[.*+?^${}()|[\\]\\\\]/g,\"\\\\$&\"))),e=new RegExp(n.map(t=>`(${t})`).join(\"|\"),\"g\"),o=[];let i=null;for(;null!==(i=e.exec(t));){for(let t=1;t<i.length;t++)if(i[t]){o.push({marker:r[t-1],index:i.index});break}0===i[0].length&&e.lastIndex++}return o}var X={quiet:function(t,r){M(t);try{const n=t();return m(n)?n.catch(t=>{r&&r.isErrorEnabled()&&r.error(\"quiet() with async error:\",t)}):n}catch(t){r&&r.isErrorEnabled()&&r.error(\"quiet() with sync error:\",t)}},quietKeepError:function(t,r){M(t),k(r);try{const n=t();return m(n)?n.catch(t=>r.push(t)):n}catch(t){r.push(t)}}},Y={defer:Z,delay:function(t,r){h(t)?(r=t,t=Promise.resolve()):null==t&&null==r&&(r=1,t=Promise.resolve());null!=t&&R(t),C(r=r??1e3);const n=Z(),e=Date.now();return t.then((...t)=>{const o=Date.now()-e;o<r?setTimeout(()=>n.resolve(...t),r-o):n.resolve(...t)}).catch(t=>{const o=Date.now()-e;o<r?setTimeout(()=>n.reject(t),r-o):n.reject(t)}),n.promise},timeout:function(t,r,n){R(t),C(r=r??1);const e=Z(r,n),o=Date.now();return t.then((...t)=>{Date.now()-o<=r?e.resolve(...t):e.reject(new Error(n??`Promise Timeout: ${r}ms`))}).catch(t=>{!e.resolved&&!e.rejected&&e.reject(t)}),e.promise},allSettled:_,returnValuePromised:tt,series:async function(t){k(t);const r=[];for(const n of t)M(n),r.push(await n());return r},seriesAllSettled:async function(t){k(t);const r=[];for(const n of t){M(n);try{r.push({ok:!0,result:await n()})}catch(t){r.push({ok:!1,result:t})}}return r},parallel:async function(t,r=5){if(k(t),C(r),r<=0)throw new Error(`Invalid maxParallel: ${r}, should > 0`);t.forEach(t=>M(t));const n=[];if(t.length<=r){const r=await Promise.all(t.map(t=>tt(t)));return n.push(...r),n}const e=[];for(const o of t)if(M(o),e.push(o),e.length>=r){const t=await Promise.all(e.map(t=>tt(t)));n.push(...t),e.length=0}if(e.length>0&&e.length<r){const t=await Promise.all(e.map(t=>tt(t)));n.push(...t)}return n},parallelAllSettled:async function(t,r=5){if(k(t),C(r),r<=0)throw new Error(`Invalid maxParallel: ${r}, should > 0`);t.forEach(t=>M(t));const n=[];if(t.length<=r){const r=await _(t.map(t=>tt(t)));return n.push(...r),n}const e=[];for(const o of t)if(M(o),e.push(o),e.length>=r){const t=await _(e.map(t=>tt(t)));n.push(...t),e.length=0}if(e.length>0&&e.length<r){const t=await _(e.map(t=>tt(t)));n.push(...t)}return n}};function Z(t=-1,r){C(t);const n={};let e;return t>=0&&(n.timerHandler=e=setTimeout(()=>{clearTimeout(e),n.timerCleared=!0,n.reject(new Error(r??`Promise Timeout: ${t}ms`))},t)),n.promise=new Promise((t,r)=>{n.resolve=r=>{null!=e&&(clearTimeout(e),n.timerCleared=!0),n.resolved=!0,t(r)},n.reject=t=>{null!=e&&(clearTimeout(e),n.timerCleared=!0),n.rejected=!0,r(t)}}),n.promise.cancel=()=>{null!=e&&(clearTimeout(e),n.timerCleared=!0),n.rejected=!0,n.canceled=n.promise.canceled=!0,n.reject(new Error(\"Cancelled\"))},n}async function _(t){k(t);const r=await Promise.allSettled(t),n=[];for(const t of r)\"fulfilled\"===t.status&&n.push({ok:!0,result:t.value}),\"rejected\"===t.status&&n.push({ok:!1,result:t.reason});return n}function tt(t){try{const r=t();return m(r)?r:Promise.resolve(r)}catch(t){return Promise.reject(t)}}const{isPlainObject:rt}=o;var nt={proxy:et,newProxyInstance:function(t,r,n,e=!0){const o=et(t,n,e);return Reflect.construct(o,r??[])}};function et(t,r,n=!0){if(\"function\"!=typeof t)throw new TypeError(`Not Class: type=${typeof t}, value=${JSON.stringify(t)}`);if(null!=r){if(!rt(r))throw new TypeError(`Not PropertyHandler: type=${typeof r}, value=${JSON.stringify(r)}`);const{get:t,set:n}=r;if(null!=t&&\"function\"!=typeof t)throw new TypeError(`Not PropertyHandler.get: type=${typeof t}, value=${JSON.stringify(t)}`);if(null!=n&&\"function\"!=typeof n)throw new TypeError(`Not PropertyHandler.set: type=${typeof n}, value=${JSON.stringify(n)}`)}const e={construct(t,e,o){const i=Reflect.construct(t,e);return new Proxy(n?Object.preventExtensions(i):i,r??{})}};return new Proxy(t,e)}var ot={proxy:function(t,r,n=!0){if(a(t)||!w(t)||i(t))throw new TypeError(`Not Object: type=${typeof t}, value=${JSON.stringify(t)}`);return new Proxy(n?Object.preventExtensions(t):t,r??{})}};function it(t){F(t,\"obj\");const r=new Set;let n=t;for(;n&&n!==Object.prototype;){const e=Object.getOwnPropertyNames(n);for(const n of e)\"constructor\"!==n&&\"function\"==typeof t[n]&&r.add(n);n=Object.getPrototypeOf(n)}return[...new Set(r)]}var st={getMethodsOfClass:function(t){M(t,\"cls\");const r=new Set;let n=t.prototype;for(;n&&n!==Object.prototype;){const t=Object.getOwnPropertyNames(n);for(const e of t)\"constructor\"!==e&&\"function\"==typeof n[e]&&r.add(e);n=Object.getPrototypeOf(n)}return[...new Set(r)]},getStaticMethodsOfClass:function(t){M(t,\"cls\");const r=new Set;let n=t;for(;n&&n!==Object.getPrototypeOf(Object);){const t=Object.getOwnPropertyNames(n);for(const e of t)\"function\"==typeof n[e]&&r.add(e);n=Object.getPrototypeOf(n)}return[...r]},getMethods:it,getMethodsOfObject:it},ut={startsWith:function(t,r){W(t,\"src\"),W(r,\"searching\");return at(t.subarray(0,r.length),r)},isSameType:ft,equals:at};function ft(t,n){return W(t,\"src\"),W(n,\"target\"),r(t)===r(n)}function at(t,r){if(W(t,\"src\"),W(r,\"target\"),!ft(t,r))return!1;if(t.byteLength!==r.byteLength)return!1;const n=new DataView(t.buffer,t.byteOffset,t.byteLength),e=new DataView(r.buffer,r.byteOffset,r.byteLength);for(let r=0;r<t.byteLength;r++)if(n.getUint8(r)!==e.getUint8(r))return!1;return!0}var ct={readString:function(t,r=0,n){if(V(t),D(r),r>=t.byteLength)return;let e=null;null!=n?(q(n),e=r+n>=t.byteLength?new Uint8Array(t,r):new Uint8Array(t,r,n)):e=new Uint8Array(t,r);return lt.decode(e)},writeString:function(t,r,n=0){V(t,\"buffer\"),J(r,\"str\"),D(n,\"offset\");const e=yt.encode(r),o=e.byteLength;if(n+o>t.byteLength)throw new Error(`offset + str.byteLength > buffer.byteLength:${n+o} > ${t.byteLength}`);new Uint8Array(t,n,e.byteLength).set(e)},writeArrayBuffer:function(t,r,n=0,e=0,o){V(t),V(r),C(n),C(e);const i=t.byteLength;if(n<-1*i)n=0;else if(n<0)n+=i;else if(n>=i)throw new Error(`Out of target Bounds: targetOffset(${n}) >= targetLength(${i})`);const s=r.byteLength;if(e<-1*s)e=0;else if(e<0)e+=s;else if(e>=s)throw new Error(`Out of data Bounds: dataOffset(${e}) >= dataArrayBufferLength(${s})`);null!=o&&(q(o,\"dataLength\"),e+o>s&&(o=void 0));const u=new Uint8Array(r,e,o);if(u.byteLength>i-n)throw new Error(`Out of target Bounds: from targetOffset(${n}), No Space to store dataArrayBuffer(${e}, ${o??\"NoLimit\"})`);new Uint8Array(t).set(u,n)}};const lt=new TextDecoder,yt=new TextEncoder;const pt=1e6;var gt={s2ns:1e9,ms2ns:pt,timestamp64:ht,lapseNano:wt,lapseMillis:dt,timeoutNano:function(t,r){return wt(t)>r},timeoutMillis:function(t,r){return dt(t)>r}};function ht(){if(\"undefined\"!=typeof performance&&\"number\"==typeof performance.timeOrigin){const t=performance.timeOrigin,r=performance.now();return BigInt((t+r)*pt)}return BigInt(Date.now()*pt)}function wt(t,r){return(r??ht())-t}function dt(t,r){r=r??ht();return BigInt(r-t)/BigInt(pt)}var mt={first:function(t,r){return k(t,\"arr\"),t[0]??r},last:function(t,r){return k(t,\"arr\"),t[t.length-1]??r},equals:function(t,r,n){if(!Array.isArray(t)||!Array.isArray(r))return!1;if(t.length!==r.length)return!1;for(let e=0;e<t.length;e++)if(n){if(0!==n(t[e],r[e]))return!1}else if(t[e]!==r[e])return!1;return!0},equalsIgnoreOrder:function(t,r,n){if(!Array.isArray(t)||!Array.isArray(r))return!1;if(t.length!==r.length)return!1;t.sort(n),r.sort(n);for(let e=0;e<t.length;e++)if(n){if(0!==n(t[e],r[e]))return!1}else if(t[e]!==r[e])return!1;return!0}};var bt={LangUtils:t,StringUtils:H,TypeUtils:o,TypeAssert:L,ExecUtils:X,PromiseUtils:Y,Lang:t,Type:o,Exec:X,ClassProxyUtils:nt,InstanceProxyUtils:ot,ReflectUtils:st,TypedArrayUtils:ut,ArrayBufferUtils:ct,TimeUtils:gt,ArrayUtils:mt};export{ct as ArrayBufferUtils,mt as ArrayUtils,nt as ClassProxyUtils,X as Exec,X as ExecUtils,ot as InstanceProxyUtils,t as Lang,t as LangUtils,Y as PromiseUtils,st as ReflectUtils,H as StringUtils,gt as TimeUtils,o as Type,L as TypeAssert,o as TypeUtils,ut as TypedArrayUtils,bt as default};\n//# sourceMappingURL=index-min.js.map\n","// internal\n// owned\nimport { TypeAssert } from '@creejs/commons-lang'\n\n/**\n * @typedef {{\n * value: any,\n * prev: Node|undefined,\n * next: Node|undefined\n * }} Node\n */\n\n// module vars\nconst { assertPositive } = TypeAssert\n\n/**\n * A set that has a fixed capacity and automatically removes the oldest element when the capacity is reached.\n *\n * @class CappedSet\n */\nexport default class CappedSet {\n /**\n * Creates a new CappedSet instance with a fixed capacity.\n * @constructor\n * @param {number} capacity - The maximum number of elements the set can hold (must be > 0)\n * @throws {Error} If capacity is less than or equal to 0\n */\n constructor (capacity) {\n assertPositive(capacity, 'capacity')\n this.capacity = capacity\n /**\n * @type {Map<any, Node>}\n */\n this._set = new Map()\n /**\n * @type {Node|undefined}\n */\n this._head = undefined\n /**\n * @type {Node|undefined}\n */\n this._tail = undefined\n }\n\n get size () {\n return this._set.size\n }\n\n // 获取最旧的元素\n get oldest () {\n return this._head?.value\n }\n\n // 获取最新的元素\n get newest () {\n return this._tail?.value\n }\n\n [Symbol.iterator] () {\n return this._set.keys()\n }\n\n /**\n * Adds a value to the capped set. If the value already exists, it will be moved to the most recent position.\n * If the set is at capacity, the oldest element will be removed before adding the new value.\n * @param {*} value - The value to add to the set\n */\n add (value) {\n if (this._set.has(value)) {\n const node = this._set.get(value)\n node && this._removeNode(node)\n } else if (this.size >= this.capacity) {\n this._removeOldest()\n }\n this._addNew(value)\n }\n\n /**\n * Checks if the value exists in the set.\n * @param {*} value - The value to check for existence.\n * @returns {boolean} True if the value exists, false otherwise.\n */\n has (value) {\n return this._set.has(value)\n }\n\n /**\n * Deletes a value from the capped set.\n * @param {*} value - The value to remove from the set.\n * @returns {boolean} True if the value was found and removed, false otherwise.\n */\n delete (value) {\n if (this._set.has(value)) {\n const node = this._set.get(value)\n node && this._removeNode(node)\n return true\n }\n return false\n }\n\n clear () {\n this._set.clear()\n this._head = undefined\n this._tail = undefined\n }\n\n /**\n * Returns an iterator of the values in the set.\n * @returns {Iterator<any>} An iterator object that yields the values of the set.\n */\n values () {\n return this._set.keys()\n }\n\n /**\n * Adds a new value to the set by creating a node and appending it to the tail.\n * Updates the linked list structure and maintains the set's size.\n * @private\n * @param {*} value - The value to be added to the set.\n */\n _addNew (value) {\n /**\n * @type {Node}\n */\n const node = { value, prev: this._tail, next: undefined }\n\n if (this._tail) {\n this._tail.next = node\n } else {\n this._head = node\n }\n\n this._tail = node\n this._set.set(value, node)\n }\n\n /**\n * Removes a node from the linked list and the internal Set.\n * Updates head/tail pointers and maintains list consistency.\n * @param {Node} node - The node to be removed\n * @private\n */\n _removeNode (node) {\n if (node.prev) {\n node.prev.next = node.next\n } else {\n this._head = node.next\n }\n\n if (node.next) {\n node.next.prev = node.prev\n } else {\n this._tail = node.prev\n }\n\n this._set.delete(node.value)\n }\n\n _removeOldest () {\n if (this._head) {\n this._removeNode(this._head)\n }\n }\n}\n\nexport { CappedSet }\n","import CappedSet from './capped-set.js'\n\nexport default { CappedSet }\nexport { CappedSet }\n"],"names":["TypeAssert"],"mappings":"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"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e={assertPositive:function(e,t){if(!function(e){return!!function(e){return null!=e&&"number"==typeof e}(e)&&e>0}(e))throw new Error(`${t?'"'+t+'" ':" "}Not Positive: ${e}`)}};new TextDecoder,new TextEncoder;const{assertPositive:t}=e;class s{constructor(e){t(e,"capacity"),this.capacity=e,this._set=new Map,this._head=void 0,this._tail=void 0}get size(){return this._set.size}get oldest(){return this._head?.value}get newest(){return this._tail?.value}[Symbol.iterator](){return this._set.keys()}add(e){if(this._set.has(e)){const t=this._set.get(e);t&&this._removeNode(t)}else this.size>=this.capacity&&this._removeOldest();this._addNew(e)}has(e){return this._set.has(e)}delete(e){if(this._set.has(e)){const t=this._set.get(e);return t&&this._removeNode(t),!0}return!1}clear(){this._set.clear(),this._head=void 0,this._tail=void 0}values(){return this._set.keys()}_addNew(e){const t={value:e,prev:this._tail,next:void 0};this._tail?this._tail.next=t:this._head=t,this._tail=t,this._set.set(e,t)}_removeNode(e){e.prev?e.prev.next=e.next:this._head=e.next,e.next?e.next.prev=e.prev:this._tail=e.prev,this._set.delete(e.value)}_removeOldest(){this._head&&this._removeNode(this._head)}}var i={CappedSet:s};exports.CappedSet=s,exports.default=i;
|
|
2
|
+
//# sourceMappingURL=index-min.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-min.cjs","sources":["../../../lang/dist/esm/index-min.js","../../lib/capped-set.js","../../lib/index.js"],"sourcesContent":["var t={constructorName:r,defaults:function(t,...r){if(null==t)throw new TypeError('\"target\" must not be null or undefined');for(const n of r)if(null!=n)for(const r in n)void 0===t[r]&&(t[r]=n[r]);return t},extend:n,extends:n,equals:function(t,r){if(t===r)return!0;if(\"function\"==typeof t?.equals)return t.equals(r);if(\"function\"==typeof r?.equals)return r.equals(t);return!1},isBrowser:e,isNode:function(){return!e()}};function r(t){return t?.constructor?.name}function n(t,...r){if(null==t)throw new TypeError('\"target\" must not be null or undefined');for(const n of r)if(null!=n)for(const r in n)t[r]=n[r];return t}function e(){return\"undefined\"!=typeof window&&\"undefined\"!=typeof document}var o={isArray:i,isBoolean:s,isBuffer:function(t){return null!=t&&Buffer.isBuffer(t)},isFunction:u,isInstance:f,isIterable:function(t){return null!=t&&\"function\"==typeof t[Symbol.iterator]},isDate:function(t){return null!=t&&t instanceof Date},isError:function(t){return null!=t&&t instanceof Error},isMap:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===Map},isWeakMap:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===WeakMap},isNumber:h,isPositive:c,isNegative:y,isNotNegative:l,isNil:a,isNullOrUndefined:function(t){return null==t},isNull:p,isUndefined:g,isPlainObject:d,isObject:w,isPromise:m,isRegExp:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===RegExp},isSet:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===Set},isWeakSet:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===WeakSet},isStream:function(t){return null!=t&&\"function\"==typeof t.pipe},isString:b,isSymbol:N,isPrimitive:function(t){return null!==t&&(\"string\"==typeof t||\"number\"==typeof t||\"boolean\"==typeof t)},isInt8Array:E,isUint8Array:O,isUint8ClampedArray:$,isInt16Array:v,isUint16Array:S,isInt32Array:U,isUint32Array:x,isFloat32Array:P,isFloat64Array:j,isBigInt64Array:B,isBigUint64Array:I,isTypedArray:A,isArrayBuffer:T};function i(t){return Array.isArray(t)}function s(t){return\"boolean\"==typeof t}function u(t){return\"function\"==typeof t}function f(t){return null!=t&&\"object\"==typeof t&&!d(t)}function a(t){return null==t}function c(t){return!!h(t)&&t>0}function l(t){return!!h(t)&&t>=0}function y(t){return!!h(t)&&t<0}function p(t){return null===t}function g(t){return void 0===t}function h(t){return null!=t&&\"number\"==typeof t}function w(t){return null!=t&&\"object\"==typeof t}function d(t){return null!==t&&\"object\"==typeof t&&(t.constructor===Object||void 0===t.constructor)}function m(t){return null!=t&&\"function\"==typeof t.then}function b(t){return null!=t&&\"string\"==typeof t}function N(t){return null!=t&&\"symbol\"==typeof t}function A(t){return ArrayBuffer.isView(t)&&t.constructor!==DataView}function E(t){return t instanceof Int8Array}function O(t){return t instanceof Uint8Array}function $(t){return t instanceof Uint8ClampedArray}function v(t){return t instanceof Int16Array}function S(t){return t instanceof Uint16Array}function U(t){return t instanceof Int32Array}function x(t){return t instanceof Uint32Array}function P(t){return t instanceof Float32Array}function j(t){return t instanceof Float64Array}function B(t){return t instanceof BigInt64Array}function I(t){return t instanceof BigUint64Array}function T(t){return t instanceof ArrayBuffer}var L={assertNumber:C,assertPositive:q,assertNegative:function(t,r){if(!y(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Negative: ${t}`)},assertNotNegative:D,assertBoolean:function(t,r){if(!s(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Boolean: type=${typeof t} value=${JSON.stringify(t)}`)},assertObject:F,assertPlainObject:function(t,r){if(!d(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not PlainObject: type=${typeof t} value=${JSON.stringify(t)}`)},assertSymbol:function(t,r){if(!N(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Symbol: type=${typeof t} value=${JSON.stringify(t)}`)},assertFunction:M,assertInstance:function(t,r){if(!f(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Class Instance: type=${typeof t} value=${JSON.stringify(t)}`)},assertPromise:R,assertNil:function(t,r){if(!a(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Neither Null nor Undefined: type=${typeof t} value=${JSON.stringify(t)}`)},assertNotNil:W,assertNull:function(t,r){if(!p(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Null: type=${typeof t} value=${JSON.stringify(t)}`)},assertNotNull:function(t,r){if(p(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Should Not Null\")},assertUndefined:function(t,r){if(!g(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Undefined: type=${typeof t} value=${JSON.stringify(t)}`)},assertString:J,assertArray:k,assertStringOrSymbol:function(t,r){if(!b(t)&&!N(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not String or Symbol: type=${typeof t} value=${JSON.stringify(t)}`)},assertInt8Array:function(t,r){if(E(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Int8Array\")},assertUint8Array:function(t,r){if(O(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Uint8Array\")},assertUint8ClampedArray:function(t,r){if($(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Uint8ClampedArray\")},assertInt16Array:function(t,r){if(v(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Int16Array\")},assertUint16Array:function(t,r){if(S(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Uint16Array\")},assertInt32Array:function(t,r){if(U(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Int32Array\")},assertUint32Array:function(t,r){if(x(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Uint32Array\")},assertFloat32Array:function(t,r){if(P(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Float32Array\")},assertFloat64Array:function(t,r){if(j(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Float64Array\")},assertBigInt64Array:function(t,r){if(B(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not BigInt64Array\")},assertBigUint64Array:function(t,r){if(I(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not BigUint64Array\")},assertTypedArray:function(t,r){if(A(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not TypedArray\")},assertArrayBuffer:V};function k(t,r){if(!Array.isArray(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Array: type=${typeof t} value=${JSON.stringify(t)}`)}function J(t,r){if(!b(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not String: type=${typeof t} value=${JSON.stringify(t)}`)}function C(t,r){if(!h(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Number: type=${typeof t} value=${JSON.stringify(t)}`)}function q(t,r){if(!c(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Positive: ${t}`)}function D(t,r){if(!l(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not \"0 or Positive\": ${t}`)}function F(t,r){if(!w(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Object: type=${typeof t} value=${JSON.stringify(t)}`)}function M(t,r){if(!u(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Function: type=${typeof t} value=${JSON.stringify(t)}`)}function R(t,r){if(!m(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Promise: type=${typeof t} value=${JSON.stringify(t)}`)}function W(t,r){if(a(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Should Not Nil\")}function V(t,r){if(!T(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not ArrayBuffer\")}var H={isEmpty:z,assertNotEmpty:G,isBlank:K,assertNotBlank:function(t){if(K(t))throw new Error(`Blank String: ${t}`)},capitalize:function(t){if(J(t),0===t.length)return t;const r=t.charAt(0),n=r.toUpperCase();return r===n?t:n+t.slice(1)},decapitalize:function(t){if(J(t),0===t.length)return t;const r=t.charAt(0),n=r.toLowerCase();return r===n?t:n+t.slice(1)},splitWithFixedLength:function(t,r,n=\" \"){if(J(t),C(r),J(n),0===t.length)return[];if(r<=0)throw new Error(\"length muse >=0\");if(t.length<r)return[t.padEnd(r,n)];const e=[];for(let o=0;o<t.length;o+=r){const i=t.substring(o,o+r);e.push(i.padEnd(r,n))}return e},split:function(t,...r){J(t);if(0===t.length)return[];const n=[...r];0===r.length&&r.push(\",\");const e=Q(t,...n);if(0===e.length)return[];const o=[];let i=\"\",s=0;for(const{marker:r,index:n}of e)i=t.substring(s,n),o.push(i),s=n+r.length;return i=t.substring(s),o.push(i),o},findMarkerPositions:function(t,...r){if(J(t),0===r.length)throw new Error(\"At least one marker must be provided\");const n=[];for(const e of new Set(r)){if(z(e))continue;J(e);let r=t.indexOf(e);for(;-1!==r;)n.push({marker:e,index:r}),r=t.indexOf(e,r+e.length)}return n.sort((t,r)=>t.index-r.index),n},findMarkerPositionsRegex:Q,substringBefore:function(t,r){if(J(t),J(r),0===t.length||0===r.length)return;const n=t.indexOf(r);if(-1===n)return;return t.substring(0,n)},substringBeforeLast:function(t,r){if(J(t),J(r),0===t.length||0===r.length)return;const n=t.lastIndexOf(r);if(-1===n)return;return t.substring(0,n)},substringAfter:function(t,r){if(J(t),J(r),0===t.length||0===r.length)return;const n=t.indexOf(r);if(-1===n)return;return t.substring(n+r.length)},substringAfterLast:function(t,r){if(J(t),J(r),0===t.length||0===r.length)return;const n=t.lastIndexOf(r);if(-1===n)return;return t.substring(n+r.length)},substringBetween:function(t,r,n){G(t),G(r),G(n);const e=t.indexOf(r);if(-1===e)return;const o=t.indexOf(n,e+r.length);if(-1===o)return;return t.substring(e+r.length,o)},substringBetweenGreedy:function(t,r,n){G(t),G(r),G(n);const e=t.indexOf(r);if(-1===e)return;const o=t.lastIndexOf(n);if(-1===o||o<=e)return;return t.substring(e+r.length,o)},substringsBetween:function(t,r,n){G(t),G(r),G(n);const e=[];let o=0;for(;;){const i=t.indexOf(r,o);if(-1===i)break;const s=t.indexOf(n,i+r.length);if(-1===s)break;e.push(t.substring(i+r.length,s)),o=s+n.length}return e}};function z(t){return null==t||(J(t),0===t.length)}function G(t){if(z(t))throw new Error(`Empty String: ${t}`)}function K(t){return null==t||(J(t),0===t.trim().length)}function Q(t,...r){if(J(t),0===r.length)throw new Error(\"At least one marker must be provided\");const n=[...new Set(r.filter(t=>null!=t))].map(t=>(J(t),t.replace(/[.*+?^${}()|[\\]\\\\]/g,\"\\\\$&\"))),e=new RegExp(n.map(t=>`(${t})`).join(\"|\"),\"g\"),o=[];let i=null;for(;null!==(i=e.exec(t));){for(let t=1;t<i.length;t++)if(i[t]){o.push({marker:r[t-1],index:i.index});break}0===i[0].length&&e.lastIndex++}return o}var X={quiet:function(t,r){M(t);try{const n=t();return m(n)?n.catch(t=>{r&&r.isErrorEnabled()&&r.error(\"quiet() with async error:\",t)}):n}catch(t){r&&r.isErrorEnabled()&&r.error(\"quiet() with sync error:\",t)}},quietKeepError:function(t,r){M(t),k(r);try{const n=t();return m(n)?n.catch(t=>r.push(t)):n}catch(t){r.push(t)}}},Y={defer:Z,delay:function(t,r){h(t)?(r=t,t=Promise.resolve()):null==t&&null==r&&(r=1,t=Promise.resolve());null!=t&&R(t),C(r=r??1e3);const n=Z(),e=Date.now();return t.then((...t)=>{const o=Date.now()-e;o<r?setTimeout(()=>n.resolve(...t),r-o):n.resolve(...t)}).catch(t=>{const o=Date.now()-e;o<r?setTimeout(()=>n.reject(t),r-o):n.reject(t)}),n.promise},timeout:function(t,r,n){R(t),C(r=r??1);const e=Z(r,n),o=Date.now();return t.then((...t)=>{Date.now()-o<=r?e.resolve(...t):e.reject(new Error(n??`Promise Timeout: ${r}ms`))}).catch(t=>{!e.resolved&&!e.rejected&&e.reject(t)}),e.promise},allSettled:_,returnValuePromised:tt,series:async function(t){k(t);const r=[];for(const n of t)M(n),r.push(await n());return r},seriesAllSettled:async function(t){k(t);const r=[];for(const n of t){M(n);try{r.push({ok:!0,result:await n()})}catch(t){r.push({ok:!1,result:t})}}return r},parallel:async function(t,r=5){if(k(t),C(r),r<=0)throw new Error(`Invalid maxParallel: ${r}, should > 0`);t.forEach(t=>M(t));const n=[];if(t.length<=r){const r=await Promise.all(t.map(t=>tt(t)));return n.push(...r),n}const e=[];for(const o of t)if(M(o),e.push(o),e.length>=r){const t=await Promise.all(e.map(t=>tt(t)));n.push(...t),e.length=0}if(e.length>0&&e.length<r){const t=await Promise.all(e.map(t=>tt(t)));n.push(...t)}return n},parallelAllSettled:async function(t,r=5){if(k(t),C(r),r<=0)throw new Error(`Invalid maxParallel: ${r}, should > 0`);t.forEach(t=>M(t));const n=[];if(t.length<=r){const r=await _(t.map(t=>tt(t)));return n.push(...r),n}const e=[];for(const o of t)if(M(o),e.push(o),e.length>=r){const t=await _(e.map(t=>tt(t)));n.push(...t),e.length=0}if(e.length>0&&e.length<r){const t=await _(e.map(t=>tt(t)));n.push(...t)}return n}};function Z(t=-1,r){C(t);const n={};let e;return t>=0&&(n.timerHandler=e=setTimeout(()=>{clearTimeout(e),n.timerCleared=!0,n.reject(new Error(r??`Promise Timeout: ${t}ms`))},t)),n.promise=new Promise((t,r)=>{n.resolve=r=>{null!=e&&(clearTimeout(e),n.timerCleared=!0),n.resolved=!0,t(r)},n.reject=t=>{null!=e&&(clearTimeout(e),n.timerCleared=!0),n.rejected=!0,r(t)}}),n.promise.cancel=()=>{null!=e&&(clearTimeout(e),n.timerCleared=!0),n.rejected=!0,n.canceled=n.promise.canceled=!0,n.reject(new Error(\"Cancelled\"))},n}async function _(t){k(t);const r=await Promise.allSettled(t),n=[];for(const t of r)\"fulfilled\"===t.status&&n.push({ok:!0,result:t.value}),\"rejected\"===t.status&&n.push({ok:!1,result:t.reason});return n}function tt(t){try{const r=t();return m(r)?r:Promise.resolve(r)}catch(t){return Promise.reject(t)}}const{isPlainObject:rt}=o;var nt={proxy:et,newProxyInstance:function(t,r,n,e=!0){const o=et(t,n,e);return Reflect.construct(o,r??[])}};function et(t,r,n=!0){if(\"function\"!=typeof t)throw new TypeError(`Not Class: type=${typeof t}, value=${JSON.stringify(t)}`);if(null!=r){if(!rt(r))throw new TypeError(`Not PropertyHandler: type=${typeof r}, value=${JSON.stringify(r)}`);const{get:t,set:n}=r;if(null!=t&&\"function\"!=typeof t)throw new TypeError(`Not PropertyHandler.get: type=${typeof t}, value=${JSON.stringify(t)}`);if(null!=n&&\"function\"!=typeof n)throw new TypeError(`Not PropertyHandler.set: type=${typeof n}, value=${JSON.stringify(n)}`)}const e={construct(t,e,o){const i=Reflect.construct(t,e);return new Proxy(n?Object.preventExtensions(i):i,r??{})}};return new Proxy(t,e)}var ot={proxy:function(t,r,n=!0){if(a(t)||!w(t)||i(t))throw new TypeError(`Not Object: type=${typeof t}, value=${JSON.stringify(t)}`);return new Proxy(n?Object.preventExtensions(t):t,r??{})}};function it(t){F(t,\"obj\");const r=new Set;let n=t;for(;n&&n!==Object.prototype;){const e=Object.getOwnPropertyNames(n);for(const n of e)\"constructor\"!==n&&\"function\"==typeof t[n]&&r.add(n);n=Object.getPrototypeOf(n)}return[...new Set(r)]}var st={getMethodsOfClass:function(t){M(t,\"cls\");const r=new Set;let n=t.prototype;for(;n&&n!==Object.prototype;){const t=Object.getOwnPropertyNames(n);for(const e of t)\"constructor\"!==e&&\"function\"==typeof n[e]&&r.add(e);n=Object.getPrototypeOf(n)}return[...new Set(r)]},getStaticMethodsOfClass:function(t){M(t,\"cls\");const r=new Set;let n=t;for(;n&&n!==Object.getPrototypeOf(Object);){const t=Object.getOwnPropertyNames(n);for(const e of t)\"function\"==typeof n[e]&&r.add(e);n=Object.getPrototypeOf(n)}return[...r]},getMethods:it,getMethodsOfObject:it},ut={startsWith:function(t,r){W(t,\"src\"),W(r,\"searching\");return at(t.subarray(0,r.length),r)},isSameType:ft,equals:at};function ft(t,n){return W(t,\"src\"),W(n,\"target\"),r(t)===r(n)}function at(t,r){if(W(t,\"src\"),W(r,\"target\"),!ft(t,r))return!1;if(t.byteLength!==r.byteLength)return!1;const n=new DataView(t.buffer,t.byteOffset,t.byteLength),e=new DataView(r.buffer,r.byteOffset,r.byteLength);for(let r=0;r<t.byteLength;r++)if(n.getUint8(r)!==e.getUint8(r))return!1;return!0}var ct={readString:function(t,r=0,n){if(V(t),D(r),r>=t.byteLength)return;let e=null;null!=n?(q(n),e=r+n>=t.byteLength?new Uint8Array(t,r):new Uint8Array(t,r,n)):e=new Uint8Array(t,r);return lt.decode(e)},writeString:function(t,r,n=0){V(t,\"buffer\"),J(r,\"str\"),D(n,\"offset\");const e=yt.encode(r),o=e.byteLength;if(n+o>t.byteLength)throw new Error(`offset + str.byteLength > buffer.byteLength:${n+o} > ${t.byteLength}`);new Uint8Array(t,n,e.byteLength).set(e)},writeArrayBuffer:function(t,r,n=0,e=0,o){V(t),V(r),C(n),C(e);const i=t.byteLength;if(n<-1*i)n=0;else if(n<0)n+=i;else if(n>=i)throw new Error(`Out of target Bounds: targetOffset(${n}) >= targetLength(${i})`);const s=r.byteLength;if(e<-1*s)e=0;else if(e<0)e+=s;else if(e>=s)throw new Error(`Out of data Bounds: dataOffset(${e}) >= dataArrayBufferLength(${s})`);null!=o&&(q(o,\"dataLength\"),e+o>s&&(o=void 0));const u=new Uint8Array(r,e,o);if(u.byteLength>i-n)throw new Error(`Out of target Bounds: from targetOffset(${n}), No Space to store dataArrayBuffer(${e}, ${o??\"NoLimit\"})`);new Uint8Array(t).set(u,n)}};const lt=new TextDecoder,yt=new TextEncoder;const pt=1e6;var gt={s2ns:1e9,ms2ns:pt,timestamp64:ht,lapseNano:wt,lapseMillis:dt,timeoutNano:function(t,r){return wt(t)>r},timeoutMillis:function(t,r){return dt(t)>r}};function ht(){if(\"undefined\"!=typeof performance&&\"number\"==typeof performance.timeOrigin){const t=performance.timeOrigin,r=performance.now();return BigInt((t+r)*pt)}return BigInt(Date.now()*pt)}function wt(t,r){return(r??ht())-t}function dt(t,r){r=r??ht();return BigInt(r-t)/BigInt(pt)}var mt={first:function(t,r){return k(t,\"arr\"),t[0]??r},last:function(t,r){return k(t,\"arr\"),t[t.length-1]??r},equals:function(t,r,n){if(!Array.isArray(t)||!Array.isArray(r))return!1;if(t.length!==r.length)return!1;for(let e=0;e<t.length;e++)if(n){if(0!==n(t[e],r[e]))return!1}else if(t[e]!==r[e])return!1;return!0},equalsIgnoreOrder:function(t,r,n){if(!Array.isArray(t)||!Array.isArray(r))return!1;if(t.length!==r.length)return!1;t.sort(n),r.sort(n);for(let e=0;e<t.length;e++)if(n){if(0!==n(t[e],r[e]))return!1}else if(t[e]!==r[e])return!1;return!0}};var bt={LangUtils:t,StringUtils:H,TypeUtils:o,TypeAssert:L,ExecUtils:X,PromiseUtils:Y,Lang:t,Type:o,Exec:X,ClassProxyUtils:nt,InstanceProxyUtils:ot,ReflectUtils:st,TypedArrayUtils:ut,ArrayBufferUtils:ct,TimeUtils:gt,ArrayUtils:mt};export{ct as ArrayBufferUtils,mt as ArrayUtils,nt as ClassProxyUtils,X as Exec,X as ExecUtils,ot as InstanceProxyUtils,t as Lang,t as LangUtils,Y as PromiseUtils,st as ReflectUtils,H as StringUtils,gt as TimeUtils,o as Type,L as TypeAssert,o as TypeUtils,ut as TypedArrayUtils,bt as default};\n//# sourceMappingURL=index-min.js.map\n","// internal\n// owned\nimport { TypeAssert } from '@creejs/commons-lang'\n\n/**\n * @typedef {{\n * value: any,\n * prev: Node|undefined,\n * next: Node|undefined\n * }} Node\n */\n\n// module vars\nconst { assertPositive } = TypeAssert\n\n/**\n * A set that has a fixed capacity and automatically removes the oldest element when the capacity is reached.\n *\n * @class CappedSet\n */\nexport default class CappedSet {\n /**\n * Creates a new CappedSet instance with a fixed capacity.\n * @constructor\n * @param {number} capacity - The maximum number of elements the set can hold (must be > 0)\n * @throws {Error} If capacity is less than or equal to 0\n */\n constructor (capacity) {\n assertPositive(capacity, 'capacity')\n this.capacity = capacity\n /**\n * @type {Map<any, Node>}\n */\n this._set = new Map()\n /**\n * @type {Node|undefined}\n */\n this._head = undefined\n /**\n * @type {Node|undefined}\n */\n this._tail = undefined\n }\n\n get size () {\n return this._set.size\n }\n\n // 获取最旧的元素\n get oldest () {\n return this._head?.value\n }\n\n // 获取最新的元素\n get newest () {\n return this._tail?.value\n }\n\n [Symbol.iterator] () {\n return this._set.keys()\n }\n\n /**\n * Adds a value to the capped set. If the value already exists, it will be moved to the most recent position.\n * If the set is at capacity, the oldest element will be removed before adding the new value.\n * @param {*} value - The value to add to the set\n */\n add (value) {\n if (this._set.has(value)) {\n const node = this._set.get(value)\n node && this._removeNode(node)\n } else if (this.size >= this.capacity) {\n this._removeOldest()\n }\n this._addNew(value)\n }\n\n /**\n * Checks if the value exists in the set.\n * @param {*} value - The value to check for existence.\n * @returns {boolean} True if the value exists, false otherwise.\n */\n has (value) {\n return this._set.has(value)\n }\n\n /**\n * Deletes a value from the capped set.\n * @param {*} value - The value to remove from the set.\n * @returns {boolean} True if the value was found and removed, false otherwise.\n */\n delete (value) {\n if (this._set.has(value)) {\n const node = this._set.get(value)\n node && this._removeNode(node)\n return true\n }\n return false\n }\n\n clear () {\n this._set.clear()\n this._head = undefined\n this._tail = undefined\n }\n\n /**\n * Returns an iterator of the values in the set.\n * @returns {Iterator<any>} An iterator object that yields the values of the set.\n */\n values () {\n return this._set.keys()\n }\n\n /**\n * Adds a new value to the set by creating a node and appending it to the tail.\n * Updates the linked list structure and maintains the set's size.\n * @private\n * @param {*} value - The value to be added to the set.\n */\n _addNew (value) {\n /**\n * @type {Node}\n */\n const node = { value, prev: this._tail, next: undefined }\n\n if (this._tail) {\n this._tail.next = node\n } else {\n this._head = node\n }\n\n this._tail = node\n this._set.set(value, node)\n }\n\n /**\n * Removes a node from the linked list and the internal Set.\n * Updates head/tail pointers and maintains list consistency.\n * @param {Node} node - The node to be removed\n * @private\n */\n _removeNode (node) {\n if (node.prev) {\n node.prev.next = node.next\n } else {\n this._head = node.next\n }\n\n if (node.next) {\n node.next.prev = node.prev\n } else {\n this._tail = node.prev\n }\n\n this._set.delete(node.value)\n }\n\n _removeOldest () {\n if (this._head) {\n this._removeNode(this._head)\n }\n }\n}\n\nexport { CappedSet }\n","import CappedSet from './capped-set.js'\n\nexport default { CappedSet }\nexport { CappedSet }\n"],"names":["L","assertPositive","t","r","h","c","Error","TextDecoder","TextEncoder","TypeAssert","CappedSet","constructor","capacity","this","_set","Map","_head","undefined","_tail","size","oldest","value","newest","Symbol","iterator","keys","add","has","node","get","_removeNode","_removeOldest","_addNew","clear","values","prev","next","set","delete","index"],"mappings":"oEAA6uG,IAAIA,EAAE,CAAgBC,eAAy5F,SAAWC,EAAEC,GAAG,IAAnjI,SAAWD,GAAG,QAAiJ,SAAWA,GAAG,OAAO,MAAMA,GAAG,iBAAiBA,CAAC,CAAzLE,CAAEF,IAAIA,EAAE,CAAC,CAAwhIG,CAAEH,GAAG,MAAM,IAAII,MAAM,GAAGH,EAAE,IAAIA,EAAE,KAAK,oBAAoBD,IAAI,GAA4/S,IAAIK,YAAe,IAAIC,YCahwf,MAAMP,eAAEA,GAAmBQ,EAOZ,MAAMC,EAOnB,WAAAC,CAAaC,GACXX,EAAeW,EAAU,YACzBC,KAAKD,SAAWA,EAIhBC,KAAKC,KAAO,IAAIC,IAIhBF,KAAKG,WAAQC,EAIbJ,KAAKK,WAAQD,CACf,CAEA,QAAIE,GACF,OAAON,KAAKC,KAAKK,IACnB,CAGA,UAAIC,GACF,OAAOP,KAAKG,OAAOK,KACrB,CAGA,UAAIC,GACF,OAAOT,KAAKK,OAAOG,KACrB,CAEA,CAACE,OAAOC,YACN,OAAOX,KAAKC,KAAKW,MACnB,CAOA,GAAAC,CAAKL,GACH,GAAIR,KAAKC,KAAKa,IAAIN,GAAQ,CACxB,MAAMO,EAAOf,KAAKC,KAAKe,IAAIR,GAC3BO,GAAQf,KAAKiB,YAAYF,EAC3B,MAAWf,KAAKM,MAAQN,KAAKD,UAC3BC,KAAKkB,gBAEPlB,KAAKmB,QAAQX,EACf,CAOA,GAAAM,CAAKN,GACH,OAAOR,KAAKC,KAAKa,IAAIN,EACvB,CAOA,OAAQA,GACN,GAAIR,KAAKC,KAAKa,IAAIN,GAAQ,CACxB,MAAMO,EAAOf,KAAKC,KAAKe,IAAIR,GAE3B,OADAO,GAAQf,KAAKiB,YAAYF,IAClB,CACT,CACA,OAAO,CACT,CAEA,KAAAK,GACEpB,KAAKC,KAAKmB,QACVpB,KAAKG,WAAQC,EACbJ,KAAKK,WAAQD,CACf,CAMA,MAAAiB,GACE,OAAOrB,KAAKC,KAAKW,MACnB,CAQA,OAAAO,CAASX,GAIP,MAAMO,EAAO,CAAEP,QAAOc,KAAMtB,KAAKK,MAAOkB,UAAMnB,GAE1CJ,KAAKK,MACPL,KAAKK,MAAMkB,KAAOR,EAElBf,KAAKG,MAAQY,EAGff,KAAKK,MAAQU,EACbf,KAAKC,KAAKuB,IAAIhB,EAAOO,EACvB,CAQA,WAAAE,CAAaF,GACPA,EAAKO,KACPP,EAAKO,KAAKC,KAAOR,EAAKQ,KAEtBvB,KAAKG,MAAQY,EAAKQ,KAGhBR,EAAKQ,KACPR,EAAKQ,KAAKD,KAAOP,EAAKO,KAEtBtB,KAAKK,MAAQU,EAAKO,KAGpBtB,KAAKC,KAAKwB,OAAOV,EAAKP,MACxB,CAEA,aAAAU,GACMlB,KAAKG,OACPH,KAAKiB,YAAYjB,KAAKG,MAE1B,EChKF,IAAAuB,EAAe,CAAE7B"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
function c(t){return !!h(t)&&t>0}function h(t){return null!=t&&"number"==typeof t}var L={assertPositive:q};function q(t,r){if(!c(t))throw new Error(`${r?'"'+r+'" ':" "}Not Positive: ${t}`)}new TextDecoder;new TextEncoder;
|
|
2
|
+
|
|
3
|
+
// internal
|
|
4
|
+
// owned
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @typedef {{
|
|
8
|
+
* value: any,
|
|
9
|
+
* prev: Node|undefined,
|
|
10
|
+
* next: Node|undefined
|
|
11
|
+
* }} Node
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
// module vars
|
|
15
|
+
const { assertPositive } = L;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A set that has a fixed capacity and automatically removes the oldest element when the capacity is reached.
|
|
19
|
+
*
|
|
20
|
+
* @class CappedSet
|
|
21
|
+
*/
|
|
22
|
+
class CappedSet {
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new CappedSet instance with a fixed capacity.
|
|
25
|
+
* @constructor
|
|
26
|
+
* @param {number} capacity - The maximum number of elements the set can hold (must be > 0)
|
|
27
|
+
* @throws {Error} If capacity is less than or equal to 0
|
|
28
|
+
*/
|
|
29
|
+
constructor (capacity) {
|
|
30
|
+
assertPositive(capacity, 'capacity');
|
|
31
|
+
this.capacity = capacity;
|
|
32
|
+
/**
|
|
33
|
+
* @type {Map<any, Node>}
|
|
34
|
+
*/
|
|
35
|
+
this._set = new Map();
|
|
36
|
+
/**
|
|
37
|
+
* @type {Node|undefined}
|
|
38
|
+
*/
|
|
39
|
+
this._head = undefined;
|
|
40
|
+
/**
|
|
41
|
+
* @type {Node|undefined}
|
|
42
|
+
*/
|
|
43
|
+
this._tail = undefined;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
get size () {
|
|
47
|
+
return this._set.size
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// 获取最旧的元素
|
|
51
|
+
get oldest () {
|
|
52
|
+
return this._head?.value
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// 获取最新的元素
|
|
56
|
+
get newest () {
|
|
57
|
+
return this._tail?.value
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
[Symbol.iterator] () {
|
|
61
|
+
return this._set.keys()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Adds a value to the capped set. If the value already exists, it will be moved to the most recent position.
|
|
66
|
+
* If the set is at capacity, the oldest element will be removed before adding the new value.
|
|
67
|
+
* @param {*} value - The value to add to the set
|
|
68
|
+
*/
|
|
69
|
+
add (value) {
|
|
70
|
+
if (this._set.has(value)) {
|
|
71
|
+
const node = this._set.get(value);
|
|
72
|
+
node && this._removeNode(node);
|
|
73
|
+
} else if (this.size >= this.capacity) {
|
|
74
|
+
this._removeOldest();
|
|
75
|
+
}
|
|
76
|
+
this._addNew(value);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Checks if the value exists in the set.
|
|
81
|
+
* @param {*} value - The value to check for existence.
|
|
82
|
+
* @returns {boolean} True if the value exists, false otherwise.
|
|
83
|
+
*/
|
|
84
|
+
has (value) {
|
|
85
|
+
return this._set.has(value)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Deletes a value from the capped set.
|
|
90
|
+
* @param {*} value - The value to remove from the set.
|
|
91
|
+
* @returns {boolean} True if the value was found and removed, false otherwise.
|
|
92
|
+
*/
|
|
93
|
+
delete (value) {
|
|
94
|
+
if (this._set.has(value)) {
|
|
95
|
+
const node = this._set.get(value);
|
|
96
|
+
node && this._removeNode(node);
|
|
97
|
+
return true
|
|
98
|
+
}
|
|
99
|
+
return false
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
clear () {
|
|
103
|
+
this._set.clear();
|
|
104
|
+
this._head = undefined;
|
|
105
|
+
this._tail = undefined;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Returns an iterator of the values in the set.
|
|
110
|
+
* @returns {Iterator<any>} An iterator object that yields the values of the set.
|
|
111
|
+
*/
|
|
112
|
+
values () {
|
|
113
|
+
return this._set.keys()
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Adds a new value to the set by creating a node and appending it to the tail.
|
|
118
|
+
* Updates the linked list structure and maintains the set's size.
|
|
119
|
+
* @private
|
|
120
|
+
* @param {*} value - The value to be added to the set.
|
|
121
|
+
*/
|
|
122
|
+
_addNew (value) {
|
|
123
|
+
/**
|
|
124
|
+
* @type {Node}
|
|
125
|
+
*/
|
|
126
|
+
const node = { value, prev: this._tail, next: undefined };
|
|
127
|
+
|
|
128
|
+
if (this._tail) {
|
|
129
|
+
this._tail.next = node;
|
|
130
|
+
} else {
|
|
131
|
+
this._head = node;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
this._tail = node;
|
|
135
|
+
this._set.set(value, node);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Removes a node from the linked list and the internal Set.
|
|
140
|
+
* Updates head/tail pointers and maintains list consistency.
|
|
141
|
+
* @param {Node} node - The node to be removed
|
|
142
|
+
* @private
|
|
143
|
+
*/
|
|
144
|
+
_removeNode (node) {
|
|
145
|
+
if (node.prev) {
|
|
146
|
+
node.prev.next = node.next;
|
|
147
|
+
} else {
|
|
148
|
+
this._head = node.next;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (node.next) {
|
|
152
|
+
node.next.prev = node.prev;
|
|
153
|
+
} else {
|
|
154
|
+
this._tail = node.prev;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
this._set.delete(node.value);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
_removeOldest () {
|
|
161
|
+
if (this._head) {
|
|
162
|
+
this._removeNode(this._head);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
var index = { CappedSet };
|
|
168
|
+
|
|
169
|
+
export { CappedSet, index as default };
|
|
170
|
+
//# sourceMappingURL=index-dev.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-dev.js","sources":["../../../lang/dist/esm/index-min.js","../../lib/capped-set.js","../../lib/index.js"],"sourcesContent":["var t={constructorName:r,defaults:function(t,...r){if(null==t)throw new TypeError('\"target\" must not be null or undefined');for(const n of r)if(null!=n)for(const r in n)void 0===t[r]&&(t[r]=n[r]);return t},extend:n,extends:n,equals:function(t,r){if(t===r)return!0;if(\"function\"==typeof t?.equals)return t.equals(r);if(\"function\"==typeof r?.equals)return r.equals(t);return!1},isBrowser:e,isNode:function(){return!e()}};function r(t){return t?.constructor?.name}function n(t,...r){if(null==t)throw new TypeError('\"target\" must not be null or undefined');for(const n of r)if(null!=n)for(const r in n)t[r]=n[r];return t}function e(){return\"undefined\"!=typeof window&&\"undefined\"!=typeof document}var o={isArray:i,isBoolean:s,isBuffer:function(t){return null!=t&&Buffer.isBuffer(t)},isFunction:u,isInstance:f,isIterable:function(t){return null!=t&&\"function\"==typeof t[Symbol.iterator]},isDate:function(t){return null!=t&&t instanceof Date},isError:function(t){return null!=t&&t instanceof Error},isMap:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===Map},isWeakMap:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===WeakMap},isNumber:h,isPositive:c,isNegative:y,isNotNegative:l,isNil:a,isNullOrUndefined:function(t){return null==t},isNull:p,isUndefined:g,isPlainObject:d,isObject:w,isPromise:m,isRegExp:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===RegExp},isSet:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===Set},isWeakSet:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===WeakSet},isStream:function(t){return null!=t&&\"function\"==typeof t.pipe},isString:b,isSymbol:N,isPrimitive:function(t){return null!==t&&(\"string\"==typeof t||\"number\"==typeof t||\"boolean\"==typeof t)},isInt8Array:E,isUint8Array:O,isUint8ClampedArray:$,isInt16Array:v,isUint16Array:S,isInt32Array:U,isUint32Array:x,isFloat32Array:P,isFloat64Array:j,isBigInt64Array:B,isBigUint64Array:I,isTypedArray:A,isArrayBuffer:T};function i(t){return Array.isArray(t)}function s(t){return\"boolean\"==typeof t}function u(t){return\"function\"==typeof t}function f(t){return null!=t&&\"object\"==typeof t&&!d(t)}function a(t){return null==t}function c(t){return!!h(t)&&t>0}function l(t){return!!h(t)&&t>=0}function y(t){return!!h(t)&&t<0}function p(t){return null===t}function g(t){return void 0===t}function h(t){return null!=t&&\"number\"==typeof t}function w(t){return null!=t&&\"object\"==typeof t}function d(t){return null!==t&&\"object\"==typeof t&&(t.constructor===Object||void 0===t.constructor)}function m(t){return null!=t&&\"function\"==typeof t.then}function b(t){return null!=t&&\"string\"==typeof t}function N(t){return null!=t&&\"symbol\"==typeof t}function A(t){return ArrayBuffer.isView(t)&&t.constructor!==DataView}function E(t){return t instanceof Int8Array}function O(t){return t instanceof Uint8Array}function $(t){return t instanceof Uint8ClampedArray}function v(t){return t instanceof Int16Array}function S(t){return t instanceof Uint16Array}function U(t){return t instanceof Int32Array}function x(t){return t instanceof Uint32Array}function P(t){return t instanceof Float32Array}function j(t){return t instanceof Float64Array}function B(t){return t instanceof BigInt64Array}function I(t){return t instanceof BigUint64Array}function T(t){return t instanceof ArrayBuffer}var L={assertNumber:C,assertPositive:q,assertNegative:function(t,r){if(!y(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Negative: ${t}`)},assertNotNegative:D,assertBoolean:function(t,r){if(!s(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Boolean: type=${typeof t} value=${JSON.stringify(t)}`)},assertObject:F,assertPlainObject:function(t,r){if(!d(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not PlainObject: type=${typeof t} value=${JSON.stringify(t)}`)},assertSymbol:function(t,r){if(!N(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Symbol: type=${typeof t} value=${JSON.stringify(t)}`)},assertFunction:M,assertInstance:function(t,r){if(!f(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Class Instance: type=${typeof t} value=${JSON.stringify(t)}`)},assertPromise:R,assertNil:function(t,r){if(!a(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Neither Null nor Undefined: type=${typeof t} value=${JSON.stringify(t)}`)},assertNotNil:W,assertNull:function(t,r){if(!p(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Null: type=${typeof t} value=${JSON.stringify(t)}`)},assertNotNull:function(t,r){if(p(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Should Not Null\")},assertUndefined:function(t,r){if(!g(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Undefined: type=${typeof t} value=${JSON.stringify(t)}`)},assertString:J,assertArray:k,assertStringOrSymbol:function(t,r){if(!b(t)&&!N(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not String or Symbol: type=${typeof t} value=${JSON.stringify(t)}`)},assertInt8Array:function(t,r){if(E(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Int8Array\")},assertUint8Array:function(t,r){if(O(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Uint8Array\")},assertUint8ClampedArray:function(t,r){if($(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Uint8ClampedArray\")},assertInt16Array:function(t,r){if(v(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Int16Array\")},assertUint16Array:function(t,r){if(S(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Uint16Array\")},assertInt32Array:function(t,r){if(U(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Int32Array\")},assertUint32Array:function(t,r){if(x(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Uint32Array\")},assertFloat32Array:function(t,r){if(P(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Float32Array\")},assertFloat64Array:function(t,r){if(j(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Float64Array\")},assertBigInt64Array:function(t,r){if(B(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not BigInt64Array\")},assertBigUint64Array:function(t,r){if(I(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not BigUint64Array\")},assertTypedArray:function(t,r){if(A(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not TypedArray\")},assertArrayBuffer:V};function k(t,r){if(!Array.isArray(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Array: type=${typeof t} value=${JSON.stringify(t)}`)}function J(t,r){if(!b(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not String: type=${typeof t} value=${JSON.stringify(t)}`)}function C(t,r){if(!h(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Number: type=${typeof t} value=${JSON.stringify(t)}`)}function q(t,r){if(!c(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Positive: ${t}`)}function D(t,r){if(!l(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not \"0 or Positive\": ${t}`)}function F(t,r){if(!w(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Object: type=${typeof t} value=${JSON.stringify(t)}`)}function M(t,r){if(!u(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Function: type=${typeof t} value=${JSON.stringify(t)}`)}function R(t,r){if(!m(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Promise: type=${typeof t} value=${JSON.stringify(t)}`)}function W(t,r){if(a(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Should Not Nil\")}function V(t,r){if(!T(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not ArrayBuffer\")}var H={isEmpty:z,assertNotEmpty:G,isBlank:K,assertNotBlank:function(t){if(K(t))throw new Error(`Blank String: ${t}`)},capitalize:function(t){if(J(t),0===t.length)return t;const r=t.charAt(0),n=r.toUpperCase();return r===n?t:n+t.slice(1)},decapitalize:function(t){if(J(t),0===t.length)return t;const r=t.charAt(0),n=r.toLowerCase();return r===n?t:n+t.slice(1)},splitWithFixedLength:function(t,r,n=\" \"){if(J(t),C(r),J(n),0===t.length)return[];if(r<=0)throw new Error(\"length muse >=0\");if(t.length<r)return[t.padEnd(r,n)];const e=[];for(let o=0;o<t.length;o+=r){const i=t.substring(o,o+r);e.push(i.padEnd(r,n))}return e},split:function(t,...r){J(t);if(0===t.length)return[];const n=[...r];0===r.length&&r.push(\",\");const e=Q(t,...n);if(0===e.length)return[];const o=[];let i=\"\",s=0;for(const{marker:r,index:n}of e)i=t.substring(s,n),o.push(i),s=n+r.length;return i=t.substring(s),o.push(i),o},findMarkerPositions:function(t,...r){if(J(t),0===r.length)throw new Error(\"At least one marker must be provided\");const n=[];for(const e of new Set(r)){if(z(e))continue;J(e);let r=t.indexOf(e);for(;-1!==r;)n.push({marker:e,index:r}),r=t.indexOf(e,r+e.length)}return n.sort((t,r)=>t.index-r.index),n},findMarkerPositionsRegex:Q,substringBefore:function(t,r){if(J(t),J(r),0===t.length||0===r.length)return;const n=t.indexOf(r);if(-1===n)return;return t.substring(0,n)},substringBeforeLast:function(t,r){if(J(t),J(r),0===t.length||0===r.length)return;const n=t.lastIndexOf(r);if(-1===n)return;return t.substring(0,n)},substringAfter:function(t,r){if(J(t),J(r),0===t.length||0===r.length)return;const n=t.indexOf(r);if(-1===n)return;return t.substring(n+r.length)},substringAfterLast:function(t,r){if(J(t),J(r),0===t.length||0===r.length)return;const n=t.lastIndexOf(r);if(-1===n)return;return t.substring(n+r.length)},substringBetween:function(t,r,n){G(t),G(r),G(n);const e=t.indexOf(r);if(-1===e)return;const o=t.indexOf(n,e+r.length);if(-1===o)return;return t.substring(e+r.length,o)},substringBetweenGreedy:function(t,r,n){G(t),G(r),G(n);const e=t.indexOf(r);if(-1===e)return;const o=t.lastIndexOf(n);if(-1===o||o<=e)return;return t.substring(e+r.length,o)},substringsBetween:function(t,r,n){G(t),G(r),G(n);const e=[];let o=0;for(;;){const i=t.indexOf(r,o);if(-1===i)break;const s=t.indexOf(n,i+r.length);if(-1===s)break;e.push(t.substring(i+r.length,s)),o=s+n.length}return e}};function z(t){return null==t||(J(t),0===t.length)}function G(t){if(z(t))throw new Error(`Empty String: ${t}`)}function K(t){return null==t||(J(t),0===t.trim().length)}function Q(t,...r){if(J(t),0===r.length)throw new Error(\"At least one marker must be provided\");const n=[...new Set(r.filter(t=>null!=t))].map(t=>(J(t),t.replace(/[.*+?^${}()|[\\]\\\\]/g,\"\\\\$&\"))),e=new RegExp(n.map(t=>`(${t})`).join(\"|\"),\"g\"),o=[];let i=null;for(;null!==(i=e.exec(t));){for(let t=1;t<i.length;t++)if(i[t]){o.push({marker:r[t-1],index:i.index});break}0===i[0].length&&e.lastIndex++}return o}var X={quiet:function(t,r){M(t);try{const n=t();return m(n)?n.catch(t=>{r&&r.isErrorEnabled()&&r.error(\"quiet() with async error:\",t)}):n}catch(t){r&&r.isErrorEnabled()&&r.error(\"quiet() with sync error:\",t)}},quietKeepError:function(t,r){M(t),k(r);try{const n=t();return m(n)?n.catch(t=>r.push(t)):n}catch(t){r.push(t)}}},Y={defer:Z,delay:function(t,r){h(t)?(r=t,t=Promise.resolve()):null==t&&null==r&&(r=1,t=Promise.resolve());null!=t&&R(t),C(r=r??1e3);const n=Z(),e=Date.now();return t.then((...t)=>{const o=Date.now()-e;o<r?setTimeout(()=>n.resolve(...t),r-o):n.resolve(...t)}).catch(t=>{const o=Date.now()-e;o<r?setTimeout(()=>n.reject(t),r-o):n.reject(t)}),n.promise},timeout:function(t,r,n){R(t),C(r=r??1);const e=Z(r,n),o=Date.now();return t.then((...t)=>{Date.now()-o<=r?e.resolve(...t):e.reject(new Error(n??`Promise Timeout: ${r}ms`))}).catch(t=>{!e.resolved&&!e.rejected&&e.reject(t)}),e.promise},allSettled:_,returnValuePromised:tt,series:async function(t){k(t);const r=[];for(const n of t)M(n),r.push(await n());return r},seriesAllSettled:async function(t){k(t);const r=[];for(const n of t){M(n);try{r.push({ok:!0,result:await n()})}catch(t){r.push({ok:!1,result:t})}}return r},parallel:async function(t,r=5){if(k(t),C(r),r<=0)throw new Error(`Invalid maxParallel: ${r}, should > 0`);t.forEach(t=>M(t));const n=[];if(t.length<=r){const r=await Promise.all(t.map(t=>tt(t)));return n.push(...r),n}const e=[];for(const o of t)if(M(o),e.push(o),e.length>=r){const t=await Promise.all(e.map(t=>tt(t)));n.push(...t),e.length=0}if(e.length>0&&e.length<r){const t=await Promise.all(e.map(t=>tt(t)));n.push(...t)}return n},parallelAllSettled:async function(t,r=5){if(k(t),C(r),r<=0)throw new Error(`Invalid maxParallel: ${r}, should > 0`);t.forEach(t=>M(t));const n=[];if(t.length<=r){const r=await _(t.map(t=>tt(t)));return n.push(...r),n}const e=[];for(const o of t)if(M(o),e.push(o),e.length>=r){const t=await _(e.map(t=>tt(t)));n.push(...t),e.length=0}if(e.length>0&&e.length<r){const t=await _(e.map(t=>tt(t)));n.push(...t)}return n}};function Z(t=-1,r){C(t);const n={};let e;return t>=0&&(n.timerHandler=e=setTimeout(()=>{clearTimeout(e),n.timerCleared=!0,n.reject(new Error(r??`Promise Timeout: ${t}ms`))},t)),n.promise=new Promise((t,r)=>{n.resolve=r=>{null!=e&&(clearTimeout(e),n.timerCleared=!0),n.resolved=!0,t(r)},n.reject=t=>{null!=e&&(clearTimeout(e),n.timerCleared=!0),n.rejected=!0,r(t)}}),n.promise.cancel=()=>{null!=e&&(clearTimeout(e),n.timerCleared=!0),n.rejected=!0,n.canceled=n.promise.canceled=!0,n.reject(new Error(\"Cancelled\"))},n}async function _(t){k(t);const r=await Promise.allSettled(t),n=[];for(const t of r)\"fulfilled\"===t.status&&n.push({ok:!0,result:t.value}),\"rejected\"===t.status&&n.push({ok:!1,result:t.reason});return n}function tt(t){try{const r=t();return m(r)?r:Promise.resolve(r)}catch(t){return Promise.reject(t)}}const{isPlainObject:rt}=o;var nt={proxy:et,newProxyInstance:function(t,r,n,e=!0){const o=et(t,n,e);return Reflect.construct(o,r??[])}};function et(t,r,n=!0){if(\"function\"!=typeof t)throw new TypeError(`Not Class: type=${typeof t}, value=${JSON.stringify(t)}`);if(null!=r){if(!rt(r))throw new TypeError(`Not PropertyHandler: type=${typeof r}, value=${JSON.stringify(r)}`);const{get:t,set:n}=r;if(null!=t&&\"function\"!=typeof t)throw new TypeError(`Not PropertyHandler.get: type=${typeof t}, value=${JSON.stringify(t)}`);if(null!=n&&\"function\"!=typeof n)throw new TypeError(`Not PropertyHandler.set: type=${typeof n}, value=${JSON.stringify(n)}`)}const e={construct(t,e,o){const i=Reflect.construct(t,e);return new Proxy(n?Object.preventExtensions(i):i,r??{})}};return new Proxy(t,e)}var ot={proxy:function(t,r,n=!0){if(a(t)||!w(t)||i(t))throw new TypeError(`Not Object: type=${typeof t}, value=${JSON.stringify(t)}`);return new Proxy(n?Object.preventExtensions(t):t,r??{})}};function it(t){F(t,\"obj\");const r=new Set;let n=t;for(;n&&n!==Object.prototype;){const e=Object.getOwnPropertyNames(n);for(const n of e)\"constructor\"!==n&&\"function\"==typeof t[n]&&r.add(n);n=Object.getPrototypeOf(n)}return[...new Set(r)]}var st={getMethodsOfClass:function(t){M(t,\"cls\");const r=new Set;let n=t.prototype;for(;n&&n!==Object.prototype;){const t=Object.getOwnPropertyNames(n);for(const e of t)\"constructor\"!==e&&\"function\"==typeof n[e]&&r.add(e);n=Object.getPrototypeOf(n)}return[...new Set(r)]},getStaticMethodsOfClass:function(t){M(t,\"cls\");const r=new Set;let n=t;for(;n&&n!==Object.getPrototypeOf(Object);){const t=Object.getOwnPropertyNames(n);for(const e of t)\"function\"==typeof n[e]&&r.add(e);n=Object.getPrototypeOf(n)}return[...r]},getMethods:it,getMethodsOfObject:it},ut={startsWith:function(t,r){W(t,\"src\"),W(r,\"searching\");return at(t.subarray(0,r.length),r)},isSameType:ft,equals:at};function ft(t,n){return W(t,\"src\"),W(n,\"target\"),r(t)===r(n)}function at(t,r){if(W(t,\"src\"),W(r,\"target\"),!ft(t,r))return!1;if(t.byteLength!==r.byteLength)return!1;const n=new DataView(t.buffer,t.byteOffset,t.byteLength),e=new DataView(r.buffer,r.byteOffset,r.byteLength);for(let r=0;r<t.byteLength;r++)if(n.getUint8(r)!==e.getUint8(r))return!1;return!0}var ct={readString:function(t,r=0,n){if(V(t),D(r),r>=t.byteLength)return;let e=null;null!=n?(q(n),e=r+n>=t.byteLength?new Uint8Array(t,r):new Uint8Array(t,r,n)):e=new Uint8Array(t,r);return lt.decode(e)},writeString:function(t,r,n=0){V(t,\"buffer\"),J(r,\"str\"),D(n,\"offset\");const e=yt.encode(r),o=e.byteLength;if(n+o>t.byteLength)throw new Error(`offset + str.byteLength > buffer.byteLength:${n+o} > ${t.byteLength}`);new Uint8Array(t,n,e.byteLength).set(e)},writeArrayBuffer:function(t,r,n=0,e=0,o){V(t),V(r),C(n),C(e);const i=t.byteLength;if(n<-1*i)n=0;else if(n<0)n+=i;else if(n>=i)throw new Error(`Out of target Bounds: targetOffset(${n}) >= targetLength(${i})`);const s=r.byteLength;if(e<-1*s)e=0;else if(e<0)e+=s;else if(e>=s)throw new Error(`Out of data Bounds: dataOffset(${e}) >= dataArrayBufferLength(${s})`);null!=o&&(q(o,\"dataLength\"),e+o>s&&(o=void 0));const u=new Uint8Array(r,e,o);if(u.byteLength>i-n)throw new Error(`Out of target Bounds: from targetOffset(${n}), No Space to store dataArrayBuffer(${e}, ${o??\"NoLimit\"})`);new Uint8Array(t).set(u,n)}};const lt=new TextDecoder,yt=new TextEncoder;const pt=1e6;var gt={s2ns:1e9,ms2ns:pt,timestamp64:ht,lapseNano:wt,lapseMillis:dt,timeoutNano:function(t,r){return wt(t)>r},timeoutMillis:function(t,r){return dt(t)>r}};function ht(){if(\"undefined\"!=typeof performance&&\"number\"==typeof performance.timeOrigin){const t=performance.timeOrigin,r=performance.now();return BigInt((t+r)*pt)}return BigInt(Date.now()*pt)}function wt(t,r){return(r??ht())-t}function dt(t,r){r=r??ht();return BigInt(r-t)/BigInt(pt)}var mt={first:function(t,r){return k(t,\"arr\"),t[0]??r},last:function(t,r){return k(t,\"arr\"),t[t.length-1]??r},equals:function(t,r,n){if(!Array.isArray(t)||!Array.isArray(r))return!1;if(t.length!==r.length)return!1;for(let e=0;e<t.length;e++)if(n){if(0!==n(t[e],r[e]))return!1}else if(t[e]!==r[e])return!1;return!0},equalsIgnoreOrder:function(t,r,n){if(!Array.isArray(t)||!Array.isArray(r))return!1;if(t.length!==r.length)return!1;t.sort(n),r.sort(n);for(let e=0;e<t.length;e++)if(n){if(0!==n(t[e],r[e]))return!1}else if(t[e]!==r[e])return!1;return!0}};var bt={LangUtils:t,StringUtils:H,TypeUtils:o,TypeAssert:L,ExecUtils:X,PromiseUtils:Y,Lang:t,Type:o,Exec:X,ClassProxyUtils:nt,InstanceProxyUtils:ot,ReflectUtils:st,TypedArrayUtils:ut,ArrayBufferUtils:ct,TimeUtils:gt,ArrayUtils:mt};export{ct as ArrayBufferUtils,mt as ArrayUtils,nt as ClassProxyUtils,X as Exec,X as ExecUtils,ot as InstanceProxyUtils,t as Lang,t as LangUtils,Y as PromiseUtils,st as ReflectUtils,H as StringUtils,gt as TimeUtils,o as Type,L as TypeAssert,o as TypeUtils,ut as TypedArrayUtils,bt as default};\n//# sourceMappingURL=index-min.js.map\n","// internal\n// owned\nimport { TypeAssert } from '@creejs/commons-lang'\n\n/**\n * @typedef {{\n * value: any,\n * prev: Node|undefined,\n * next: Node|undefined\n * }} Node\n */\n\n// module vars\nconst { assertPositive } = TypeAssert\n\n/**\n * A set that has a fixed capacity and automatically removes the oldest element when the capacity is reached.\n *\n * @class CappedSet\n */\nexport default class CappedSet {\n /**\n * Creates a new CappedSet instance with a fixed capacity.\n * @constructor\n * @param {number} capacity - The maximum number of elements the set can hold (must be > 0)\n * @throws {Error} If capacity is less than or equal to 0\n */\n constructor (capacity) {\n assertPositive(capacity, 'capacity')\n this.capacity = capacity\n /**\n * @type {Map<any, Node>}\n */\n this._set = new Map()\n /**\n * @type {Node|undefined}\n */\n this._head = undefined\n /**\n * @type {Node|undefined}\n */\n this._tail = undefined\n }\n\n get size () {\n return this._set.size\n }\n\n // 获取最旧的元素\n get oldest () {\n return this._head?.value\n }\n\n // 获取最新的元素\n get newest () {\n return this._tail?.value\n }\n\n [Symbol.iterator] () {\n return this._set.keys()\n }\n\n /**\n * Adds a value to the capped set. If the value already exists, it will be moved to the most recent position.\n * If the set is at capacity, the oldest element will be removed before adding the new value.\n * @param {*} value - The value to add to the set\n */\n add (value) {\n if (this._set.has(value)) {\n const node = this._set.get(value)\n node && this._removeNode(node)\n } else if (this.size >= this.capacity) {\n this._removeOldest()\n }\n this._addNew(value)\n }\n\n /**\n * Checks if the value exists in the set.\n * @param {*} value - The value to check for existence.\n * @returns {boolean} True if the value exists, false otherwise.\n */\n has (value) {\n return this._set.has(value)\n }\n\n /**\n * Deletes a value from the capped set.\n * @param {*} value - The value to remove from the set.\n * @returns {boolean} True if the value was found and removed, false otherwise.\n */\n delete (value) {\n if (this._set.has(value)) {\n const node = this._set.get(value)\n node && this._removeNode(node)\n return true\n }\n return false\n }\n\n clear () {\n this._set.clear()\n this._head = undefined\n this._tail = undefined\n }\n\n /**\n * Returns an iterator of the values in the set.\n * @returns {Iterator<any>} An iterator object that yields the values of the set.\n */\n values () {\n return this._set.keys()\n }\n\n /**\n * Adds a new value to the set by creating a node and appending it to the tail.\n * Updates the linked list structure and maintains the set's size.\n * @private\n * @param {*} value - The value to be added to the set.\n */\n _addNew (value) {\n /**\n * @type {Node}\n */\n const node = { value, prev: this._tail, next: undefined }\n\n if (this._tail) {\n this._tail.next = node\n } else {\n this._head = node\n }\n\n this._tail = node\n this._set.set(value, node)\n }\n\n /**\n * Removes a node from the linked list and the internal Set.\n * Updates head/tail pointers and maintains list consistency.\n * @param {Node} node - The node to be removed\n * @private\n */\n _removeNode (node) {\n if (node.prev) {\n node.prev.next = node.next\n } else {\n this._head = node.next\n }\n\n if (node.next) {\n node.next.prev = node.prev\n } else {\n this._tail = node.prev\n }\n\n this._set.delete(node.value)\n }\n\n _removeOldest () {\n if (this._head) {\n this._removeNode(this._head)\n }\n }\n}\n\nexport { CappedSet }\n","import CappedSet from './capped-set.js'\n\nexport default { CappedSet }\nexport { CappedSet }\n"],"names":["TypeAssert"],"mappings":"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"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e={assertPositive:function(e,t){if(!function(e){return!!function(e){return null!=e&&"number"==typeof e}(e)&&e>0}(e))throw new Error(`${t?'"'+t+'" ':" "}Not Positive: ${e}`)}};new TextDecoder,new TextEncoder;const{assertPositive:t}=e;class s{constructor(e){t(e,"capacity"),this.capacity=e,this._set=new Map,this._head=void 0,this._tail=void 0}get size(){return this._set.size}get oldest(){return this._head?.value}get newest(){return this._tail?.value}[Symbol.iterator](){return this._set.keys()}add(e){if(this._set.has(e)){const t=this._set.get(e);t&&this._removeNode(t)}else this.size>=this.capacity&&this._removeOldest();this._addNew(e)}has(e){return this._set.has(e)}delete(e){if(this._set.has(e)){const t=this._set.get(e);return t&&this._removeNode(t),!0}return!1}clear(){this._set.clear(),this._head=void 0,this._tail=void 0}values(){return this._set.keys()}_addNew(e){const t={value:e,prev:this._tail,next:void 0};this._tail?this._tail.next=t:this._head=t,this._tail=t,this._set.set(e,t)}_removeNode(e){e.prev?e.prev.next=e.next:this._head=e.next,e.next?e.next.prev=e.prev:this._tail=e.prev,this._set.delete(e.value)}_removeOldest(){this._head&&this._removeNode(this._head)}}var i={CappedSet:s};export{s as CappedSet,i as default};
|
|
2
|
+
//# sourceMappingURL=index-min.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-min.js","sources":["../../../lang/dist/esm/index-min.js","../../lib/capped-set.js","../../lib/index.js"],"sourcesContent":["var t={constructorName:r,defaults:function(t,...r){if(null==t)throw new TypeError('\"target\" must not be null or undefined');for(const n of r)if(null!=n)for(const r in n)void 0===t[r]&&(t[r]=n[r]);return t},extend:n,extends:n,equals:function(t,r){if(t===r)return!0;if(\"function\"==typeof t?.equals)return t.equals(r);if(\"function\"==typeof r?.equals)return r.equals(t);return!1},isBrowser:e,isNode:function(){return!e()}};function r(t){return t?.constructor?.name}function n(t,...r){if(null==t)throw new TypeError('\"target\" must not be null or undefined');for(const n of r)if(null!=n)for(const r in n)t[r]=n[r];return t}function e(){return\"undefined\"!=typeof window&&\"undefined\"!=typeof document}var o={isArray:i,isBoolean:s,isBuffer:function(t){return null!=t&&Buffer.isBuffer(t)},isFunction:u,isInstance:f,isIterable:function(t){return null!=t&&\"function\"==typeof t[Symbol.iterator]},isDate:function(t){return null!=t&&t instanceof Date},isError:function(t){return null!=t&&t instanceof Error},isMap:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===Map},isWeakMap:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===WeakMap},isNumber:h,isPositive:c,isNegative:y,isNotNegative:l,isNil:a,isNullOrUndefined:function(t){return null==t},isNull:p,isUndefined:g,isPlainObject:d,isObject:w,isPromise:m,isRegExp:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===RegExp},isSet:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===Set},isWeakSet:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===WeakSet},isStream:function(t){return null!=t&&\"function\"==typeof t.pipe},isString:b,isSymbol:N,isPrimitive:function(t){return null!==t&&(\"string\"==typeof t||\"number\"==typeof t||\"boolean\"==typeof t)},isInt8Array:E,isUint8Array:O,isUint8ClampedArray:$,isInt16Array:v,isUint16Array:S,isInt32Array:U,isUint32Array:x,isFloat32Array:P,isFloat64Array:j,isBigInt64Array:B,isBigUint64Array:I,isTypedArray:A,isArrayBuffer:T};function i(t){return Array.isArray(t)}function s(t){return\"boolean\"==typeof t}function u(t){return\"function\"==typeof t}function f(t){return null!=t&&\"object\"==typeof t&&!d(t)}function a(t){return null==t}function c(t){return!!h(t)&&t>0}function l(t){return!!h(t)&&t>=0}function y(t){return!!h(t)&&t<0}function p(t){return null===t}function g(t){return void 0===t}function h(t){return null!=t&&\"number\"==typeof t}function w(t){return null!=t&&\"object\"==typeof t}function d(t){return null!==t&&\"object\"==typeof t&&(t.constructor===Object||void 0===t.constructor)}function m(t){return null!=t&&\"function\"==typeof t.then}function b(t){return null!=t&&\"string\"==typeof t}function N(t){return null!=t&&\"symbol\"==typeof t}function A(t){return ArrayBuffer.isView(t)&&t.constructor!==DataView}function E(t){return t instanceof Int8Array}function O(t){return t instanceof Uint8Array}function $(t){return t instanceof Uint8ClampedArray}function v(t){return t instanceof Int16Array}function S(t){return t instanceof Uint16Array}function U(t){return t instanceof Int32Array}function x(t){return t instanceof Uint32Array}function P(t){return t instanceof Float32Array}function j(t){return t instanceof Float64Array}function B(t){return t instanceof BigInt64Array}function I(t){return t instanceof BigUint64Array}function T(t){return t instanceof ArrayBuffer}var L={assertNumber:C,assertPositive:q,assertNegative:function(t,r){if(!y(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Negative: ${t}`)},assertNotNegative:D,assertBoolean:function(t,r){if(!s(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Boolean: type=${typeof t} value=${JSON.stringify(t)}`)},assertObject:F,assertPlainObject:function(t,r){if(!d(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not PlainObject: type=${typeof t} value=${JSON.stringify(t)}`)},assertSymbol:function(t,r){if(!N(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Symbol: type=${typeof t} value=${JSON.stringify(t)}`)},assertFunction:M,assertInstance:function(t,r){if(!f(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Class Instance: type=${typeof t} value=${JSON.stringify(t)}`)},assertPromise:R,assertNil:function(t,r){if(!a(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Neither Null nor Undefined: type=${typeof t} value=${JSON.stringify(t)}`)},assertNotNil:W,assertNull:function(t,r){if(!p(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Null: type=${typeof t} value=${JSON.stringify(t)}`)},assertNotNull:function(t,r){if(p(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Should Not Null\")},assertUndefined:function(t,r){if(!g(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Undefined: type=${typeof t} value=${JSON.stringify(t)}`)},assertString:J,assertArray:k,assertStringOrSymbol:function(t,r){if(!b(t)&&!N(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not String or Symbol: type=${typeof t} value=${JSON.stringify(t)}`)},assertInt8Array:function(t,r){if(E(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Int8Array\")},assertUint8Array:function(t,r){if(O(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Uint8Array\")},assertUint8ClampedArray:function(t,r){if($(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Uint8ClampedArray\")},assertInt16Array:function(t,r){if(v(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Int16Array\")},assertUint16Array:function(t,r){if(S(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Uint16Array\")},assertInt32Array:function(t,r){if(U(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Int32Array\")},assertUint32Array:function(t,r){if(x(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Uint32Array\")},assertFloat32Array:function(t,r){if(P(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Float32Array\")},assertFloat64Array:function(t,r){if(j(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Float64Array\")},assertBigInt64Array:function(t,r){if(B(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not BigInt64Array\")},assertBigUint64Array:function(t,r){if(I(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not BigUint64Array\")},assertTypedArray:function(t,r){if(A(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not TypedArray\")},assertArrayBuffer:V};function k(t,r){if(!Array.isArray(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Array: type=${typeof t} value=${JSON.stringify(t)}`)}function J(t,r){if(!b(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not String: type=${typeof t} value=${JSON.stringify(t)}`)}function C(t,r){if(!h(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Number: type=${typeof t} value=${JSON.stringify(t)}`)}function q(t,r){if(!c(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Positive: ${t}`)}function D(t,r){if(!l(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not \"0 or Positive\": ${t}`)}function F(t,r){if(!w(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Object: type=${typeof t} value=${JSON.stringify(t)}`)}function M(t,r){if(!u(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Function: type=${typeof t} value=${JSON.stringify(t)}`)}function R(t,r){if(!m(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Promise: type=${typeof t} value=${JSON.stringify(t)}`)}function W(t,r){if(a(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Should Not Nil\")}function V(t,r){if(!T(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not ArrayBuffer\")}var H={isEmpty:z,assertNotEmpty:G,isBlank:K,assertNotBlank:function(t){if(K(t))throw new Error(`Blank String: ${t}`)},capitalize:function(t){if(J(t),0===t.length)return t;const r=t.charAt(0),n=r.toUpperCase();return r===n?t:n+t.slice(1)},decapitalize:function(t){if(J(t),0===t.length)return t;const r=t.charAt(0),n=r.toLowerCase();return r===n?t:n+t.slice(1)},splitWithFixedLength:function(t,r,n=\" \"){if(J(t),C(r),J(n),0===t.length)return[];if(r<=0)throw new Error(\"length muse >=0\");if(t.length<r)return[t.padEnd(r,n)];const e=[];for(let o=0;o<t.length;o+=r){const i=t.substring(o,o+r);e.push(i.padEnd(r,n))}return e},split:function(t,...r){J(t);if(0===t.length)return[];const n=[...r];0===r.length&&r.push(\",\");const e=Q(t,...n);if(0===e.length)return[];const o=[];let i=\"\",s=0;for(const{marker:r,index:n}of e)i=t.substring(s,n),o.push(i),s=n+r.length;return i=t.substring(s),o.push(i),o},findMarkerPositions:function(t,...r){if(J(t),0===r.length)throw new Error(\"At least one marker must be provided\");const n=[];for(const e of new Set(r)){if(z(e))continue;J(e);let r=t.indexOf(e);for(;-1!==r;)n.push({marker:e,index:r}),r=t.indexOf(e,r+e.length)}return n.sort((t,r)=>t.index-r.index),n},findMarkerPositionsRegex:Q,substringBefore:function(t,r){if(J(t),J(r),0===t.length||0===r.length)return;const n=t.indexOf(r);if(-1===n)return;return t.substring(0,n)},substringBeforeLast:function(t,r){if(J(t),J(r),0===t.length||0===r.length)return;const n=t.lastIndexOf(r);if(-1===n)return;return t.substring(0,n)},substringAfter:function(t,r){if(J(t),J(r),0===t.length||0===r.length)return;const n=t.indexOf(r);if(-1===n)return;return t.substring(n+r.length)},substringAfterLast:function(t,r){if(J(t),J(r),0===t.length||0===r.length)return;const n=t.lastIndexOf(r);if(-1===n)return;return t.substring(n+r.length)},substringBetween:function(t,r,n){G(t),G(r),G(n);const e=t.indexOf(r);if(-1===e)return;const o=t.indexOf(n,e+r.length);if(-1===o)return;return t.substring(e+r.length,o)},substringBetweenGreedy:function(t,r,n){G(t),G(r),G(n);const e=t.indexOf(r);if(-1===e)return;const o=t.lastIndexOf(n);if(-1===o||o<=e)return;return t.substring(e+r.length,o)},substringsBetween:function(t,r,n){G(t),G(r),G(n);const e=[];let o=0;for(;;){const i=t.indexOf(r,o);if(-1===i)break;const s=t.indexOf(n,i+r.length);if(-1===s)break;e.push(t.substring(i+r.length,s)),o=s+n.length}return e}};function z(t){return null==t||(J(t),0===t.length)}function G(t){if(z(t))throw new Error(`Empty String: ${t}`)}function K(t){return null==t||(J(t),0===t.trim().length)}function Q(t,...r){if(J(t),0===r.length)throw new Error(\"At least one marker must be provided\");const n=[...new Set(r.filter(t=>null!=t))].map(t=>(J(t),t.replace(/[.*+?^${}()|[\\]\\\\]/g,\"\\\\$&\"))),e=new RegExp(n.map(t=>`(${t})`).join(\"|\"),\"g\"),o=[];let i=null;for(;null!==(i=e.exec(t));){for(let t=1;t<i.length;t++)if(i[t]){o.push({marker:r[t-1],index:i.index});break}0===i[0].length&&e.lastIndex++}return o}var X={quiet:function(t,r){M(t);try{const n=t();return m(n)?n.catch(t=>{r&&r.isErrorEnabled()&&r.error(\"quiet() with async error:\",t)}):n}catch(t){r&&r.isErrorEnabled()&&r.error(\"quiet() with sync error:\",t)}},quietKeepError:function(t,r){M(t),k(r);try{const n=t();return m(n)?n.catch(t=>r.push(t)):n}catch(t){r.push(t)}}},Y={defer:Z,delay:function(t,r){h(t)?(r=t,t=Promise.resolve()):null==t&&null==r&&(r=1,t=Promise.resolve());null!=t&&R(t),C(r=r??1e3);const n=Z(),e=Date.now();return t.then((...t)=>{const o=Date.now()-e;o<r?setTimeout(()=>n.resolve(...t),r-o):n.resolve(...t)}).catch(t=>{const o=Date.now()-e;o<r?setTimeout(()=>n.reject(t),r-o):n.reject(t)}),n.promise},timeout:function(t,r,n){R(t),C(r=r??1);const e=Z(r,n),o=Date.now();return t.then((...t)=>{Date.now()-o<=r?e.resolve(...t):e.reject(new Error(n??`Promise Timeout: ${r}ms`))}).catch(t=>{!e.resolved&&!e.rejected&&e.reject(t)}),e.promise},allSettled:_,returnValuePromised:tt,series:async function(t){k(t);const r=[];for(const n of t)M(n),r.push(await n());return r},seriesAllSettled:async function(t){k(t);const r=[];for(const n of t){M(n);try{r.push({ok:!0,result:await n()})}catch(t){r.push({ok:!1,result:t})}}return r},parallel:async function(t,r=5){if(k(t),C(r),r<=0)throw new Error(`Invalid maxParallel: ${r}, should > 0`);t.forEach(t=>M(t));const n=[];if(t.length<=r){const r=await Promise.all(t.map(t=>tt(t)));return n.push(...r),n}const e=[];for(const o of t)if(M(o),e.push(o),e.length>=r){const t=await Promise.all(e.map(t=>tt(t)));n.push(...t),e.length=0}if(e.length>0&&e.length<r){const t=await Promise.all(e.map(t=>tt(t)));n.push(...t)}return n},parallelAllSettled:async function(t,r=5){if(k(t),C(r),r<=0)throw new Error(`Invalid maxParallel: ${r}, should > 0`);t.forEach(t=>M(t));const n=[];if(t.length<=r){const r=await _(t.map(t=>tt(t)));return n.push(...r),n}const e=[];for(const o of t)if(M(o),e.push(o),e.length>=r){const t=await _(e.map(t=>tt(t)));n.push(...t),e.length=0}if(e.length>0&&e.length<r){const t=await _(e.map(t=>tt(t)));n.push(...t)}return n}};function Z(t=-1,r){C(t);const n={};let e;return t>=0&&(n.timerHandler=e=setTimeout(()=>{clearTimeout(e),n.timerCleared=!0,n.reject(new Error(r??`Promise Timeout: ${t}ms`))},t)),n.promise=new Promise((t,r)=>{n.resolve=r=>{null!=e&&(clearTimeout(e),n.timerCleared=!0),n.resolved=!0,t(r)},n.reject=t=>{null!=e&&(clearTimeout(e),n.timerCleared=!0),n.rejected=!0,r(t)}}),n.promise.cancel=()=>{null!=e&&(clearTimeout(e),n.timerCleared=!0),n.rejected=!0,n.canceled=n.promise.canceled=!0,n.reject(new Error(\"Cancelled\"))},n}async function _(t){k(t);const r=await Promise.allSettled(t),n=[];for(const t of r)\"fulfilled\"===t.status&&n.push({ok:!0,result:t.value}),\"rejected\"===t.status&&n.push({ok:!1,result:t.reason});return n}function tt(t){try{const r=t();return m(r)?r:Promise.resolve(r)}catch(t){return Promise.reject(t)}}const{isPlainObject:rt}=o;var nt={proxy:et,newProxyInstance:function(t,r,n,e=!0){const o=et(t,n,e);return Reflect.construct(o,r??[])}};function et(t,r,n=!0){if(\"function\"!=typeof t)throw new TypeError(`Not Class: type=${typeof t}, value=${JSON.stringify(t)}`);if(null!=r){if(!rt(r))throw new TypeError(`Not PropertyHandler: type=${typeof r}, value=${JSON.stringify(r)}`);const{get:t,set:n}=r;if(null!=t&&\"function\"!=typeof t)throw new TypeError(`Not PropertyHandler.get: type=${typeof t}, value=${JSON.stringify(t)}`);if(null!=n&&\"function\"!=typeof n)throw new TypeError(`Not PropertyHandler.set: type=${typeof n}, value=${JSON.stringify(n)}`)}const e={construct(t,e,o){const i=Reflect.construct(t,e);return new Proxy(n?Object.preventExtensions(i):i,r??{})}};return new Proxy(t,e)}var ot={proxy:function(t,r,n=!0){if(a(t)||!w(t)||i(t))throw new TypeError(`Not Object: type=${typeof t}, value=${JSON.stringify(t)}`);return new Proxy(n?Object.preventExtensions(t):t,r??{})}};function it(t){F(t,\"obj\");const r=new Set;let n=t;for(;n&&n!==Object.prototype;){const e=Object.getOwnPropertyNames(n);for(const n of e)\"constructor\"!==n&&\"function\"==typeof t[n]&&r.add(n);n=Object.getPrototypeOf(n)}return[...new Set(r)]}var st={getMethodsOfClass:function(t){M(t,\"cls\");const r=new Set;let n=t.prototype;for(;n&&n!==Object.prototype;){const t=Object.getOwnPropertyNames(n);for(const e of t)\"constructor\"!==e&&\"function\"==typeof n[e]&&r.add(e);n=Object.getPrototypeOf(n)}return[...new Set(r)]},getStaticMethodsOfClass:function(t){M(t,\"cls\");const r=new Set;let n=t;for(;n&&n!==Object.getPrototypeOf(Object);){const t=Object.getOwnPropertyNames(n);for(const e of t)\"function\"==typeof n[e]&&r.add(e);n=Object.getPrototypeOf(n)}return[...r]},getMethods:it,getMethodsOfObject:it},ut={startsWith:function(t,r){W(t,\"src\"),W(r,\"searching\");return at(t.subarray(0,r.length),r)},isSameType:ft,equals:at};function ft(t,n){return W(t,\"src\"),W(n,\"target\"),r(t)===r(n)}function at(t,r){if(W(t,\"src\"),W(r,\"target\"),!ft(t,r))return!1;if(t.byteLength!==r.byteLength)return!1;const n=new DataView(t.buffer,t.byteOffset,t.byteLength),e=new DataView(r.buffer,r.byteOffset,r.byteLength);for(let r=0;r<t.byteLength;r++)if(n.getUint8(r)!==e.getUint8(r))return!1;return!0}var ct={readString:function(t,r=0,n){if(V(t),D(r),r>=t.byteLength)return;let e=null;null!=n?(q(n),e=r+n>=t.byteLength?new Uint8Array(t,r):new Uint8Array(t,r,n)):e=new Uint8Array(t,r);return lt.decode(e)},writeString:function(t,r,n=0){V(t,\"buffer\"),J(r,\"str\"),D(n,\"offset\");const e=yt.encode(r),o=e.byteLength;if(n+o>t.byteLength)throw new Error(`offset + str.byteLength > buffer.byteLength:${n+o} > ${t.byteLength}`);new Uint8Array(t,n,e.byteLength).set(e)},writeArrayBuffer:function(t,r,n=0,e=0,o){V(t),V(r),C(n),C(e);const i=t.byteLength;if(n<-1*i)n=0;else if(n<0)n+=i;else if(n>=i)throw new Error(`Out of target Bounds: targetOffset(${n}) >= targetLength(${i})`);const s=r.byteLength;if(e<-1*s)e=0;else if(e<0)e+=s;else if(e>=s)throw new Error(`Out of data Bounds: dataOffset(${e}) >= dataArrayBufferLength(${s})`);null!=o&&(q(o,\"dataLength\"),e+o>s&&(o=void 0));const u=new Uint8Array(r,e,o);if(u.byteLength>i-n)throw new Error(`Out of target Bounds: from targetOffset(${n}), No Space to store dataArrayBuffer(${e}, ${o??\"NoLimit\"})`);new Uint8Array(t).set(u,n)}};const lt=new TextDecoder,yt=new TextEncoder;const pt=1e6;var gt={s2ns:1e9,ms2ns:pt,timestamp64:ht,lapseNano:wt,lapseMillis:dt,timeoutNano:function(t,r){return wt(t)>r},timeoutMillis:function(t,r){return dt(t)>r}};function ht(){if(\"undefined\"!=typeof performance&&\"number\"==typeof performance.timeOrigin){const t=performance.timeOrigin,r=performance.now();return BigInt((t+r)*pt)}return BigInt(Date.now()*pt)}function wt(t,r){return(r??ht())-t}function dt(t,r){r=r??ht();return BigInt(r-t)/BigInt(pt)}var mt={first:function(t,r){return k(t,\"arr\"),t[0]??r},last:function(t,r){return k(t,\"arr\"),t[t.length-1]??r},equals:function(t,r,n){if(!Array.isArray(t)||!Array.isArray(r))return!1;if(t.length!==r.length)return!1;for(let e=0;e<t.length;e++)if(n){if(0!==n(t[e],r[e]))return!1}else if(t[e]!==r[e])return!1;return!0},equalsIgnoreOrder:function(t,r,n){if(!Array.isArray(t)||!Array.isArray(r))return!1;if(t.length!==r.length)return!1;t.sort(n),r.sort(n);for(let e=0;e<t.length;e++)if(n){if(0!==n(t[e],r[e]))return!1}else if(t[e]!==r[e])return!1;return!0}};var bt={LangUtils:t,StringUtils:H,TypeUtils:o,TypeAssert:L,ExecUtils:X,PromiseUtils:Y,Lang:t,Type:o,Exec:X,ClassProxyUtils:nt,InstanceProxyUtils:ot,ReflectUtils:st,TypedArrayUtils:ut,ArrayBufferUtils:ct,TimeUtils:gt,ArrayUtils:mt};export{ct as ArrayBufferUtils,mt as ArrayUtils,nt as ClassProxyUtils,X as Exec,X as ExecUtils,ot as InstanceProxyUtils,t as Lang,t as LangUtils,Y as PromiseUtils,st as ReflectUtils,H as StringUtils,gt as TimeUtils,o as Type,L as TypeAssert,o as TypeUtils,ut as TypedArrayUtils,bt as default};\n//# sourceMappingURL=index-min.js.map\n","// internal\n// owned\nimport { TypeAssert } from '@creejs/commons-lang'\n\n/**\n * @typedef {{\n * value: any,\n * prev: Node|undefined,\n * next: Node|undefined\n * }} Node\n */\n\n// module vars\nconst { assertPositive } = TypeAssert\n\n/**\n * A set that has a fixed capacity and automatically removes the oldest element when the capacity is reached.\n *\n * @class CappedSet\n */\nexport default class CappedSet {\n /**\n * Creates a new CappedSet instance with a fixed capacity.\n * @constructor\n * @param {number} capacity - The maximum number of elements the set can hold (must be > 0)\n * @throws {Error} If capacity is less than or equal to 0\n */\n constructor (capacity) {\n assertPositive(capacity, 'capacity')\n this.capacity = capacity\n /**\n * @type {Map<any, Node>}\n */\n this._set = new Map()\n /**\n * @type {Node|undefined}\n */\n this._head = undefined\n /**\n * @type {Node|undefined}\n */\n this._tail = undefined\n }\n\n get size () {\n return this._set.size\n }\n\n // 获取最旧的元素\n get oldest () {\n return this._head?.value\n }\n\n // 获取最新的元素\n get newest () {\n return this._tail?.value\n }\n\n [Symbol.iterator] () {\n return this._set.keys()\n }\n\n /**\n * Adds a value to the capped set. If the value already exists, it will be moved to the most recent position.\n * If the set is at capacity, the oldest element will be removed before adding the new value.\n * @param {*} value - The value to add to the set\n */\n add (value) {\n if (this._set.has(value)) {\n const node = this._set.get(value)\n node && this._removeNode(node)\n } else if (this.size >= this.capacity) {\n this._removeOldest()\n }\n this._addNew(value)\n }\n\n /**\n * Checks if the value exists in the set.\n * @param {*} value - The value to check for existence.\n * @returns {boolean} True if the value exists, false otherwise.\n */\n has (value) {\n return this._set.has(value)\n }\n\n /**\n * Deletes a value from the capped set.\n * @param {*} value - The value to remove from the set.\n * @returns {boolean} True if the value was found and removed, false otherwise.\n */\n delete (value) {\n if (this._set.has(value)) {\n const node = this._set.get(value)\n node && this._removeNode(node)\n return true\n }\n return false\n }\n\n clear () {\n this._set.clear()\n this._head = undefined\n this._tail = undefined\n }\n\n /**\n * Returns an iterator of the values in the set.\n * @returns {Iterator<any>} An iterator object that yields the values of the set.\n */\n values () {\n return this._set.keys()\n }\n\n /**\n * Adds a new value to the set by creating a node and appending it to the tail.\n * Updates the linked list structure and maintains the set's size.\n * @private\n * @param {*} value - The value to be added to the set.\n */\n _addNew (value) {\n /**\n * @type {Node}\n */\n const node = { value, prev: this._tail, next: undefined }\n\n if (this._tail) {\n this._tail.next = node\n } else {\n this._head = node\n }\n\n this._tail = node\n this._set.set(value, node)\n }\n\n /**\n * Removes a node from the linked list and the internal Set.\n * Updates head/tail pointers and maintains list consistency.\n * @param {Node} node - The node to be removed\n * @private\n */\n _removeNode (node) {\n if (node.prev) {\n node.prev.next = node.next\n } else {\n this._head = node.next\n }\n\n if (node.next) {\n node.next.prev = node.prev\n } else {\n this._tail = node.prev\n }\n\n this._set.delete(node.value)\n }\n\n _removeOldest () {\n if (this._head) {\n this._removeNode(this._head)\n }\n }\n}\n\nexport { CappedSet }\n","import CappedSet from './capped-set.js'\n\nexport default { CappedSet }\nexport { CappedSet }\n"],"names":["L","assertPositive","t","r","h","c","Error","TextDecoder","TextEncoder","TypeAssert","CappedSet","constructor","capacity","this","_set","Map","_head","undefined","_tail","size","oldest","value","newest","Symbol","iterator","keys","add","has","node","get","_removeNode","_removeOldest","_addNew","clear","values","prev","next","set","delete","index"],"mappings":"AAA6uG,IAAIA,EAAE,CAAgBC,eAAy5F,SAAWC,EAAEC,GAAG,IAAnjI,SAAWD,GAAG,QAAiJ,SAAWA,GAAG,OAAO,MAAMA,GAAG,iBAAiBA,CAAC,CAAzLE,CAAEF,IAAIA,EAAE,CAAC,CAAwhIG,CAAEH,GAAG,MAAM,IAAII,MAAM,GAAGH,EAAE,IAAIA,EAAE,KAAK,oBAAoBD,IAAI,GAA4/S,IAAIK,YAAe,IAAIC,YCahwf,MAAMP,eAAEA,GAAmBQ,EAOZ,MAAMC,EAOnB,WAAAC,CAAaC,GACXX,EAAeW,EAAU,YACzBC,KAAKD,SAAWA,EAIhBC,KAAKC,KAAO,IAAIC,IAIhBF,KAAKG,WAAQC,EAIbJ,KAAKK,WAAQD,CACf,CAEA,QAAIE,GACF,OAAON,KAAKC,KAAKK,IACnB,CAGA,UAAIC,GACF,OAAOP,KAAKG,OAAOK,KACrB,CAGA,UAAIC,GACF,OAAOT,KAAKK,OAAOG,KACrB,CAEA,CAACE,OAAOC,YACN,OAAOX,KAAKC,KAAKW,MACnB,CAOA,GAAAC,CAAKL,GACH,GAAIR,KAAKC,KAAKa,IAAIN,GAAQ,CACxB,MAAMO,EAAOf,KAAKC,KAAKe,IAAIR,GAC3BO,GAAQf,KAAKiB,YAAYF,EAC3B,MAAWf,KAAKM,MAAQN,KAAKD,UAC3BC,KAAKkB,gBAEPlB,KAAKmB,QAAQX,EACf,CAOA,GAAAM,CAAKN,GACH,OAAOR,KAAKC,KAAKa,IAAIN,EACvB,CAOA,OAAQA,GACN,GAAIR,KAAKC,KAAKa,IAAIN,GAAQ,CACxB,MAAMO,EAAOf,KAAKC,KAAKe,IAAIR,GAE3B,OADAO,GAAQf,KAAKiB,YAAYF,IAClB,CACT,CACA,OAAO,CACT,CAEA,KAAAK,GACEpB,KAAKC,KAAKmB,QACVpB,KAAKG,WAAQC,EACbJ,KAAKK,WAAQD,CACf,CAMA,MAAAiB,GACE,OAAOrB,KAAKC,KAAKW,MACnB,CAQA,OAAAO,CAASX,GAIP,MAAMO,EAAO,CAAEP,QAAOc,KAAMtB,KAAKK,MAAOkB,UAAMnB,GAE1CJ,KAAKK,MACPL,KAAKK,MAAMkB,KAAOR,EAElBf,KAAKG,MAAQY,EAGff,KAAKK,MAAQU,EACbf,KAAKC,KAAKuB,IAAIhB,EAAOO,EACvB,CAQA,WAAAE,CAAaF,GACPA,EAAKO,KACPP,EAAKO,KAAKC,KAAOR,EAAKQ,KAEtBvB,KAAKG,MAAQY,EAAKQ,KAGhBR,EAAKQ,KACPR,EAAKQ,KAAKD,KAAOP,EAAKO,KAEtBtB,KAAKK,MAAQU,EAAKO,KAGpBtB,KAAKC,KAAKwB,OAAOV,EAAKP,MACxB,CAEA,aAAAU,GACMlB,KAAKG,OACPH,KAAKiB,YAAYjB,KAAKG,MAE1B,EChKF,IAAAuB,EAAe,CAAE7B"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CommonsLang = {}));
|
|
5
|
+
})(this, (function (exports) { 'use strict';
|
|
6
|
+
|
|
7
|
+
function c(t){return !!h(t)&&t>0}function h(t){return null!=t&&"number"==typeof t}var L={assertPositive:q};function q(t,r){if(!c(t))throw new Error(`${r?'"'+r+'" ':" "}Not Positive: ${t}`)}new TextDecoder;new TextEncoder;
|
|
8
|
+
|
|
9
|
+
// internal
|
|
10
|
+
// owned
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @typedef {{
|
|
14
|
+
* value: any,
|
|
15
|
+
* prev: Node|undefined,
|
|
16
|
+
* next: Node|undefined
|
|
17
|
+
* }} Node
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
// module vars
|
|
21
|
+
const { assertPositive } = L;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A set that has a fixed capacity and automatically removes the oldest element when the capacity is reached.
|
|
25
|
+
*
|
|
26
|
+
* @class CappedSet
|
|
27
|
+
*/
|
|
28
|
+
class CappedSet {
|
|
29
|
+
/**
|
|
30
|
+
* Creates a new CappedSet instance with a fixed capacity.
|
|
31
|
+
* @constructor
|
|
32
|
+
* @param {number} capacity - The maximum number of elements the set can hold (must be > 0)
|
|
33
|
+
* @throws {Error} If capacity is less than or equal to 0
|
|
34
|
+
*/
|
|
35
|
+
constructor (capacity) {
|
|
36
|
+
assertPositive(capacity, 'capacity');
|
|
37
|
+
this.capacity = capacity;
|
|
38
|
+
/**
|
|
39
|
+
* @type {Map<any, Node>}
|
|
40
|
+
*/
|
|
41
|
+
this._set = new Map();
|
|
42
|
+
/**
|
|
43
|
+
* @type {Node|undefined}
|
|
44
|
+
*/
|
|
45
|
+
this._head = undefined;
|
|
46
|
+
/**
|
|
47
|
+
* @type {Node|undefined}
|
|
48
|
+
*/
|
|
49
|
+
this._tail = undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
get size () {
|
|
53
|
+
return this._set.size
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// 获取最旧的元素
|
|
57
|
+
get oldest () {
|
|
58
|
+
return this._head?.value
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// 获取最新的元素
|
|
62
|
+
get newest () {
|
|
63
|
+
return this._tail?.value
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
[Symbol.iterator] () {
|
|
67
|
+
return this._set.keys()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Adds a value to the capped set. If the value already exists, it will be moved to the most recent position.
|
|
72
|
+
* If the set is at capacity, the oldest element will be removed before adding the new value.
|
|
73
|
+
* @param {*} value - The value to add to the set
|
|
74
|
+
*/
|
|
75
|
+
add (value) {
|
|
76
|
+
if (this._set.has(value)) {
|
|
77
|
+
const node = this._set.get(value);
|
|
78
|
+
node && this._removeNode(node);
|
|
79
|
+
} else if (this.size >= this.capacity) {
|
|
80
|
+
this._removeOldest();
|
|
81
|
+
}
|
|
82
|
+
this._addNew(value);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Checks if the value exists in the set.
|
|
87
|
+
* @param {*} value - The value to check for existence.
|
|
88
|
+
* @returns {boolean} True if the value exists, false otherwise.
|
|
89
|
+
*/
|
|
90
|
+
has (value) {
|
|
91
|
+
return this._set.has(value)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Deletes a value from the capped set.
|
|
96
|
+
* @param {*} value - The value to remove from the set.
|
|
97
|
+
* @returns {boolean} True if the value was found and removed, false otherwise.
|
|
98
|
+
*/
|
|
99
|
+
delete (value) {
|
|
100
|
+
if (this._set.has(value)) {
|
|
101
|
+
const node = this._set.get(value);
|
|
102
|
+
node && this._removeNode(node);
|
|
103
|
+
return true
|
|
104
|
+
}
|
|
105
|
+
return false
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
clear () {
|
|
109
|
+
this._set.clear();
|
|
110
|
+
this._head = undefined;
|
|
111
|
+
this._tail = undefined;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Returns an iterator of the values in the set.
|
|
116
|
+
* @returns {Iterator<any>} An iterator object that yields the values of the set.
|
|
117
|
+
*/
|
|
118
|
+
values () {
|
|
119
|
+
return this._set.keys()
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Adds a new value to the set by creating a node and appending it to the tail.
|
|
124
|
+
* Updates the linked list structure and maintains the set's size.
|
|
125
|
+
* @private
|
|
126
|
+
* @param {*} value - The value to be added to the set.
|
|
127
|
+
*/
|
|
128
|
+
_addNew (value) {
|
|
129
|
+
/**
|
|
130
|
+
* @type {Node}
|
|
131
|
+
*/
|
|
132
|
+
const node = { value, prev: this._tail, next: undefined };
|
|
133
|
+
|
|
134
|
+
if (this._tail) {
|
|
135
|
+
this._tail.next = node;
|
|
136
|
+
} else {
|
|
137
|
+
this._head = node;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
this._tail = node;
|
|
141
|
+
this._set.set(value, node);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Removes a node from the linked list and the internal Set.
|
|
146
|
+
* Updates head/tail pointers and maintains list consistency.
|
|
147
|
+
* @param {Node} node - The node to be removed
|
|
148
|
+
* @private
|
|
149
|
+
*/
|
|
150
|
+
_removeNode (node) {
|
|
151
|
+
if (node.prev) {
|
|
152
|
+
node.prev.next = node.next;
|
|
153
|
+
} else {
|
|
154
|
+
this._head = node.next;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (node.next) {
|
|
158
|
+
node.next.prev = node.prev;
|
|
159
|
+
} else {
|
|
160
|
+
this._tail = node.prev;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
this._set.delete(node.value);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
_removeOldest () {
|
|
167
|
+
if (this._head) {
|
|
168
|
+
this._removeNode(this._head);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
var index = { CappedSet };
|
|
174
|
+
|
|
175
|
+
exports.CappedSet = CappedSet;
|
|
176
|
+
exports.default = index;
|
|
177
|
+
|
|
178
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
179
|
+
|
|
180
|
+
}));
|
|
181
|
+
//# sourceMappingURL=index.dev.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.dev.js","sources":["../../../lang/dist/esm/index-min.js","../../lib/capped-set.js","../../lib/index.js"],"sourcesContent":["var t={constructorName:r,defaults:function(t,...r){if(null==t)throw new TypeError('\"target\" must not be null or undefined');for(const n of r)if(null!=n)for(const r in n)void 0===t[r]&&(t[r]=n[r]);return t},extend:n,extends:n,equals:function(t,r){if(t===r)return!0;if(\"function\"==typeof t?.equals)return t.equals(r);if(\"function\"==typeof r?.equals)return r.equals(t);return!1},isBrowser:e,isNode:function(){return!e()}};function r(t){return t?.constructor?.name}function n(t,...r){if(null==t)throw new TypeError('\"target\" must not be null or undefined');for(const n of r)if(null!=n)for(const r in n)t[r]=n[r];return t}function e(){return\"undefined\"!=typeof window&&\"undefined\"!=typeof document}var o={isArray:i,isBoolean:s,isBuffer:function(t){return null!=t&&Buffer.isBuffer(t)},isFunction:u,isInstance:f,isIterable:function(t){return null!=t&&\"function\"==typeof t[Symbol.iterator]},isDate:function(t){return null!=t&&t instanceof Date},isError:function(t){return null!=t&&t instanceof Error},isMap:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===Map},isWeakMap:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===WeakMap},isNumber:h,isPositive:c,isNegative:y,isNotNegative:l,isNil:a,isNullOrUndefined:function(t){return null==t},isNull:p,isUndefined:g,isPlainObject:d,isObject:w,isPromise:m,isRegExp:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===RegExp},isSet:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===Set},isWeakSet:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===WeakSet},isStream:function(t){return null!=t&&\"function\"==typeof t.pipe},isString:b,isSymbol:N,isPrimitive:function(t){return null!==t&&(\"string\"==typeof t||\"number\"==typeof t||\"boolean\"==typeof t)},isInt8Array:E,isUint8Array:O,isUint8ClampedArray:$,isInt16Array:v,isUint16Array:S,isInt32Array:U,isUint32Array:x,isFloat32Array:P,isFloat64Array:j,isBigInt64Array:B,isBigUint64Array:I,isTypedArray:A,isArrayBuffer:T};function i(t){return Array.isArray(t)}function s(t){return\"boolean\"==typeof t}function u(t){return\"function\"==typeof t}function f(t){return null!=t&&\"object\"==typeof t&&!d(t)}function a(t){return null==t}function c(t){return!!h(t)&&t>0}function l(t){return!!h(t)&&t>=0}function y(t){return!!h(t)&&t<0}function p(t){return null===t}function g(t){return void 0===t}function h(t){return null!=t&&\"number\"==typeof t}function w(t){return null!=t&&\"object\"==typeof t}function d(t){return null!==t&&\"object\"==typeof t&&(t.constructor===Object||void 0===t.constructor)}function m(t){return null!=t&&\"function\"==typeof t.then}function b(t){return null!=t&&\"string\"==typeof t}function N(t){return null!=t&&\"symbol\"==typeof t}function A(t){return ArrayBuffer.isView(t)&&t.constructor!==DataView}function E(t){return t instanceof Int8Array}function O(t){return t instanceof Uint8Array}function $(t){return t instanceof Uint8ClampedArray}function v(t){return t instanceof Int16Array}function S(t){return t instanceof Uint16Array}function U(t){return t instanceof Int32Array}function x(t){return t instanceof Uint32Array}function P(t){return t instanceof Float32Array}function j(t){return t instanceof Float64Array}function B(t){return t instanceof BigInt64Array}function I(t){return t instanceof BigUint64Array}function T(t){return t instanceof ArrayBuffer}var L={assertNumber:C,assertPositive:q,assertNegative:function(t,r){if(!y(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Negative: ${t}`)},assertNotNegative:D,assertBoolean:function(t,r){if(!s(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Boolean: type=${typeof t} value=${JSON.stringify(t)}`)},assertObject:F,assertPlainObject:function(t,r){if(!d(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not PlainObject: type=${typeof t} value=${JSON.stringify(t)}`)},assertSymbol:function(t,r){if(!N(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Symbol: type=${typeof t} value=${JSON.stringify(t)}`)},assertFunction:M,assertInstance:function(t,r){if(!f(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Class Instance: type=${typeof t} value=${JSON.stringify(t)}`)},assertPromise:R,assertNil:function(t,r){if(!a(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Neither Null nor Undefined: type=${typeof t} value=${JSON.stringify(t)}`)},assertNotNil:W,assertNull:function(t,r){if(!p(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Null: type=${typeof t} value=${JSON.stringify(t)}`)},assertNotNull:function(t,r){if(p(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Should Not Null\")},assertUndefined:function(t,r){if(!g(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Undefined: type=${typeof t} value=${JSON.stringify(t)}`)},assertString:J,assertArray:k,assertStringOrSymbol:function(t,r){if(!b(t)&&!N(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not String or Symbol: type=${typeof t} value=${JSON.stringify(t)}`)},assertInt8Array:function(t,r){if(E(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Int8Array\")},assertUint8Array:function(t,r){if(O(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Uint8Array\")},assertUint8ClampedArray:function(t,r){if($(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Uint8ClampedArray\")},assertInt16Array:function(t,r){if(v(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Int16Array\")},assertUint16Array:function(t,r){if(S(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Uint16Array\")},assertInt32Array:function(t,r){if(U(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Int32Array\")},assertUint32Array:function(t,r){if(x(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Uint32Array\")},assertFloat32Array:function(t,r){if(P(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Float32Array\")},assertFloat64Array:function(t,r){if(j(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Float64Array\")},assertBigInt64Array:function(t,r){if(B(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not BigInt64Array\")},assertBigUint64Array:function(t,r){if(I(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not BigUint64Array\")},assertTypedArray:function(t,r){if(A(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not TypedArray\")},assertArrayBuffer:V};function k(t,r){if(!Array.isArray(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Array: type=${typeof t} value=${JSON.stringify(t)}`)}function J(t,r){if(!b(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not String: type=${typeof t} value=${JSON.stringify(t)}`)}function C(t,r){if(!h(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Number: type=${typeof t} value=${JSON.stringify(t)}`)}function q(t,r){if(!c(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Positive: ${t}`)}function D(t,r){if(!l(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not \"0 or Positive\": ${t}`)}function F(t,r){if(!w(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Object: type=${typeof t} value=${JSON.stringify(t)}`)}function M(t,r){if(!u(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Function: type=${typeof t} value=${JSON.stringify(t)}`)}function R(t,r){if(!m(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Promise: type=${typeof t} value=${JSON.stringify(t)}`)}function W(t,r){if(a(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Should Not Nil\")}function V(t,r){if(!T(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not ArrayBuffer\")}var H={isEmpty:z,assertNotEmpty:G,isBlank:K,assertNotBlank:function(t){if(K(t))throw new Error(`Blank String: ${t}`)},capitalize:function(t){if(J(t),0===t.length)return t;const r=t.charAt(0),n=r.toUpperCase();return r===n?t:n+t.slice(1)},decapitalize:function(t){if(J(t),0===t.length)return t;const r=t.charAt(0),n=r.toLowerCase();return r===n?t:n+t.slice(1)},splitWithFixedLength:function(t,r,n=\" \"){if(J(t),C(r),J(n),0===t.length)return[];if(r<=0)throw new Error(\"length muse >=0\");if(t.length<r)return[t.padEnd(r,n)];const e=[];for(let o=0;o<t.length;o+=r){const i=t.substring(o,o+r);e.push(i.padEnd(r,n))}return e},split:function(t,...r){J(t);if(0===t.length)return[];const n=[...r];0===r.length&&r.push(\",\");const e=Q(t,...n);if(0===e.length)return[];const o=[];let i=\"\",s=0;for(const{marker:r,index:n}of e)i=t.substring(s,n),o.push(i),s=n+r.length;return i=t.substring(s),o.push(i),o},findMarkerPositions:function(t,...r){if(J(t),0===r.length)throw new Error(\"At least one marker must be provided\");const n=[];for(const e of new Set(r)){if(z(e))continue;J(e);let r=t.indexOf(e);for(;-1!==r;)n.push({marker:e,index:r}),r=t.indexOf(e,r+e.length)}return n.sort((t,r)=>t.index-r.index),n},findMarkerPositionsRegex:Q,substringBefore:function(t,r){if(J(t),J(r),0===t.length||0===r.length)return;const n=t.indexOf(r);if(-1===n)return;return t.substring(0,n)},substringBeforeLast:function(t,r){if(J(t),J(r),0===t.length||0===r.length)return;const n=t.lastIndexOf(r);if(-1===n)return;return t.substring(0,n)},substringAfter:function(t,r){if(J(t),J(r),0===t.length||0===r.length)return;const n=t.indexOf(r);if(-1===n)return;return t.substring(n+r.length)},substringAfterLast:function(t,r){if(J(t),J(r),0===t.length||0===r.length)return;const n=t.lastIndexOf(r);if(-1===n)return;return t.substring(n+r.length)},substringBetween:function(t,r,n){G(t),G(r),G(n);const e=t.indexOf(r);if(-1===e)return;const o=t.indexOf(n,e+r.length);if(-1===o)return;return t.substring(e+r.length,o)},substringBetweenGreedy:function(t,r,n){G(t),G(r),G(n);const e=t.indexOf(r);if(-1===e)return;const o=t.lastIndexOf(n);if(-1===o||o<=e)return;return t.substring(e+r.length,o)},substringsBetween:function(t,r,n){G(t),G(r),G(n);const e=[];let o=0;for(;;){const i=t.indexOf(r,o);if(-1===i)break;const s=t.indexOf(n,i+r.length);if(-1===s)break;e.push(t.substring(i+r.length,s)),o=s+n.length}return e}};function z(t){return null==t||(J(t),0===t.length)}function G(t){if(z(t))throw new Error(`Empty String: ${t}`)}function K(t){return null==t||(J(t),0===t.trim().length)}function Q(t,...r){if(J(t),0===r.length)throw new Error(\"At least one marker must be provided\");const n=[...new Set(r.filter(t=>null!=t))].map(t=>(J(t),t.replace(/[.*+?^${}()|[\\]\\\\]/g,\"\\\\$&\"))),e=new RegExp(n.map(t=>`(${t})`).join(\"|\"),\"g\"),o=[];let i=null;for(;null!==(i=e.exec(t));){for(let t=1;t<i.length;t++)if(i[t]){o.push({marker:r[t-1],index:i.index});break}0===i[0].length&&e.lastIndex++}return o}var X={quiet:function(t,r){M(t);try{const n=t();return m(n)?n.catch(t=>{r&&r.isErrorEnabled()&&r.error(\"quiet() with async error:\",t)}):n}catch(t){r&&r.isErrorEnabled()&&r.error(\"quiet() with sync error:\",t)}},quietKeepError:function(t,r){M(t),k(r);try{const n=t();return m(n)?n.catch(t=>r.push(t)):n}catch(t){r.push(t)}}},Y={defer:Z,delay:function(t,r){h(t)?(r=t,t=Promise.resolve()):null==t&&null==r&&(r=1,t=Promise.resolve());null!=t&&R(t),C(r=r??1e3);const n=Z(),e=Date.now();return t.then((...t)=>{const o=Date.now()-e;o<r?setTimeout(()=>n.resolve(...t),r-o):n.resolve(...t)}).catch(t=>{const o=Date.now()-e;o<r?setTimeout(()=>n.reject(t),r-o):n.reject(t)}),n.promise},timeout:function(t,r,n){R(t),C(r=r??1);const e=Z(r,n),o=Date.now();return t.then((...t)=>{Date.now()-o<=r?e.resolve(...t):e.reject(new Error(n??`Promise Timeout: ${r}ms`))}).catch(t=>{!e.resolved&&!e.rejected&&e.reject(t)}),e.promise},allSettled:_,returnValuePromised:tt,series:async function(t){k(t);const r=[];for(const n of t)M(n),r.push(await n());return r},seriesAllSettled:async function(t){k(t);const r=[];for(const n of t){M(n);try{r.push({ok:!0,result:await n()})}catch(t){r.push({ok:!1,result:t})}}return r},parallel:async function(t,r=5){if(k(t),C(r),r<=0)throw new Error(`Invalid maxParallel: ${r}, should > 0`);t.forEach(t=>M(t));const n=[];if(t.length<=r){const r=await Promise.all(t.map(t=>tt(t)));return n.push(...r),n}const e=[];for(const o of t)if(M(o),e.push(o),e.length>=r){const t=await Promise.all(e.map(t=>tt(t)));n.push(...t),e.length=0}if(e.length>0&&e.length<r){const t=await Promise.all(e.map(t=>tt(t)));n.push(...t)}return n},parallelAllSettled:async function(t,r=5){if(k(t),C(r),r<=0)throw new Error(`Invalid maxParallel: ${r}, should > 0`);t.forEach(t=>M(t));const n=[];if(t.length<=r){const r=await _(t.map(t=>tt(t)));return n.push(...r),n}const e=[];for(const o of t)if(M(o),e.push(o),e.length>=r){const t=await _(e.map(t=>tt(t)));n.push(...t),e.length=0}if(e.length>0&&e.length<r){const t=await _(e.map(t=>tt(t)));n.push(...t)}return n}};function Z(t=-1,r){C(t);const n={};let e;return t>=0&&(n.timerHandler=e=setTimeout(()=>{clearTimeout(e),n.timerCleared=!0,n.reject(new Error(r??`Promise Timeout: ${t}ms`))},t)),n.promise=new Promise((t,r)=>{n.resolve=r=>{null!=e&&(clearTimeout(e),n.timerCleared=!0),n.resolved=!0,t(r)},n.reject=t=>{null!=e&&(clearTimeout(e),n.timerCleared=!0),n.rejected=!0,r(t)}}),n.promise.cancel=()=>{null!=e&&(clearTimeout(e),n.timerCleared=!0),n.rejected=!0,n.canceled=n.promise.canceled=!0,n.reject(new Error(\"Cancelled\"))},n}async function _(t){k(t);const r=await Promise.allSettled(t),n=[];for(const t of r)\"fulfilled\"===t.status&&n.push({ok:!0,result:t.value}),\"rejected\"===t.status&&n.push({ok:!1,result:t.reason});return n}function tt(t){try{const r=t();return m(r)?r:Promise.resolve(r)}catch(t){return Promise.reject(t)}}const{isPlainObject:rt}=o;var nt={proxy:et,newProxyInstance:function(t,r,n,e=!0){const o=et(t,n,e);return Reflect.construct(o,r??[])}};function et(t,r,n=!0){if(\"function\"!=typeof t)throw new TypeError(`Not Class: type=${typeof t}, value=${JSON.stringify(t)}`);if(null!=r){if(!rt(r))throw new TypeError(`Not PropertyHandler: type=${typeof r}, value=${JSON.stringify(r)}`);const{get:t,set:n}=r;if(null!=t&&\"function\"!=typeof t)throw new TypeError(`Not PropertyHandler.get: type=${typeof t}, value=${JSON.stringify(t)}`);if(null!=n&&\"function\"!=typeof n)throw new TypeError(`Not PropertyHandler.set: type=${typeof n}, value=${JSON.stringify(n)}`)}const e={construct(t,e,o){const i=Reflect.construct(t,e);return new Proxy(n?Object.preventExtensions(i):i,r??{})}};return new Proxy(t,e)}var ot={proxy:function(t,r,n=!0){if(a(t)||!w(t)||i(t))throw new TypeError(`Not Object: type=${typeof t}, value=${JSON.stringify(t)}`);return new Proxy(n?Object.preventExtensions(t):t,r??{})}};function it(t){F(t,\"obj\");const r=new Set;let n=t;for(;n&&n!==Object.prototype;){const e=Object.getOwnPropertyNames(n);for(const n of e)\"constructor\"!==n&&\"function\"==typeof t[n]&&r.add(n);n=Object.getPrototypeOf(n)}return[...new Set(r)]}var st={getMethodsOfClass:function(t){M(t,\"cls\");const r=new Set;let n=t.prototype;for(;n&&n!==Object.prototype;){const t=Object.getOwnPropertyNames(n);for(const e of t)\"constructor\"!==e&&\"function\"==typeof n[e]&&r.add(e);n=Object.getPrototypeOf(n)}return[...new Set(r)]},getStaticMethodsOfClass:function(t){M(t,\"cls\");const r=new Set;let n=t;for(;n&&n!==Object.getPrototypeOf(Object);){const t=Object.getOwnPropertyNames(n);for(const e of t)\"function\"==typeof n[e]&&r.add(e);n=Object.getPrototypeOf(n)}return[...r]},getMethods:it,getMethodsOfObject:it},ut={startsWith:function(t,r){W(t,\"src\"),W(r,\"searching\");return at(t.subarray(0,r.length),r)},isSameType:ft,equals:at};function ft(t,n){return W(t,\"src\"),W(n,\"target\"),r(t)===r(n)}function at(t,r){if(W(t,\"src\"),W(r,\"target\"),!ft(t,r))return!1;if(t.byteLength!==r.byteLength)return!1;const n=new DataView(t.buffer,t.byteOffset,t.byteLength),e=new DataView(r.buffer,r.byteOffset,r.byteLength);for(let r=0;r<t.byteLength;r++)if(n.getUint8(r)!==e.getUint8(r))return!1;return!0}var ct={readString:function(t,r=0,n){if(V(t),D(r),r>=t.byteLength)return;let e=null;null!=n?(q(n),e=r+n>=t.byteLength?new Uint8Array(t,r):new Uint8Array(t,r,n)):e=new Uint8Array(t,r);return lt.decode(e)},writeString:function(t,r,n=0){V(t,\"buffer\"),J(r,\"str\"),D(n,\"offset\");const e=yt.encode(r),o=e.byteLength;if(n+o>t.byteLength)throw new Error(`offset + str.byteLength > buffer.byteLength:${n+o} > ${t.byteLength}`);new Uint8Array(t,n,e.byteLength).set(e)},writeArrayBuffer:function(t,r,n=0,e=0,o){V(t),V(r),C(n),C(e);const i=t.byteLength;if(n<-1*i)n=0;else if(n<0)n+=i;else if(n>=i)throw new Error(`Out of target Bounds: targetOffset(${n}) >= targetLength(${i})`);const s=r.byteLength;if(e<-1*s)e=0;else if(e<0)e+=s;else if(e>=s)throw new Error(`Out of data Bounds: dataOffset(${e}) >= dataArrayBufferLength(${s})`);null!=o&&(q(o,\"dataLength\"),e+o>s&&(o=void 0));const u=new Uint8Array(r,e,o);if(u.byteLength>i-n)throw new Error(`Out of target Bounds: from targetOffset(${n}), No Space to store dataArrayBuffer(${e}, ${o??\"NoLimit\"})`);new Uint8Array(t).set(u,n)}};const lt=new TextDecoder,yt=new TextEncoder;const pt=1e6;var gt={s2ns:1e9,ms2ns:pt,timestamp64:ht,lapseNano:wt,lapseMillis:dt,timeoutNano:function(t,r){return wt(t)>r},timeoutMillis:function(t,r){return dt(t)>r}};function ht(){if(\"undefined\"!=typeof performance&&\"number\"==typeof performance.timeOrigin){const t=performance.timeOrigin,r=performance.now();return BigInt((t+r)*pt)}return BigInt(Date.now()*pt)}function wt(t,r){return(r??ht())-t}function dt(t,r){r=r??ht();return BigInt(r-t)/BigInt(pt)}var mt={first:function(t,r){return k(t,\"arr\"),t[0]??r},last:function(t,r){return k(t,\"arr\"),t[t.length-1]??r},equals:function(t,r,n){if(!Array.isArray(t)||!Array.isArray(r))return!1;if(t.length!==r.length)return!1;for(let e=0;e<t.length;e++)if(n){if(0!==n(t[e],r[e]))return!1}else if(t[e]!==r[e])return!1;return!0},equalsIgnoreOrder:function(t,r,n){if(!Array.isArray(t)||!Array.isArray(r))return!1;if(t.length!==r.length)return!1;t.sort(n),r.sort(n);for(let e=0;e<t.length;e++)if(n){if(0!==n(t[e],r[e]))return!1}else if(t[e]!==r[e])return!1;return!0}};var bt={LangUtils:t,StringUtils:H,TypeUtils:o,TypeAssert:L,ExecUtils:X,PromiseUtils:Y,Lang:t,Type:o,Exec:X,ClassProxyUtils:nt,InstanceProxyUtils:ot,ReflectUtils:st,TypedArrayUtils:ut,ArrayBufferUtils:ct,TimeUtils:gt,ArrayUtils:mt};export{ct as ArrayBufferUtils,mt as ArrayUtils,nt as ClassProxyUtils,X as Exec,X as ExecUtils,ot as InstanceProxyUtils,t as Lang,t as LangUtils,Y as PromiseUtils,st as ReflectUtils,H as StringUtils,gt as TimeUtils,o as Type,L as TypeAssert,o as TypeUtils,ut as TypedArrayUtils,bt as default};\n//# sourceMappingURL=index-min.js.map\n","// internal\n// owned\nimport { TypeAssert } from '@creejs/commons-lang'\n\n/**\n * @typedef {{\n * value: any,\n * prev: Node|undefined,\n * next: Node|undefined\n * }} Node\n */\n\n// module vars\nconst { assertPositive } = TypeAssert\n\n/**\n * A set that has a fixed capacity and automatically removes the oldest element when the capacity is reached.\n *\n * @class CappedSet\n */\nexport default class CappedSet {\n /**\n * Creates a new CappedSet instance with a fixed capacity.\n * @constructor\n * @param {number} capacity - The maximum number of elements the set can hold (must be > 0)\n * @throws {Error} If capacity is less than or equal to 0\n */\n constructor (capacity) {\n assertPositive(capacity, 'capacity')\n this.capacity = capacity\n /**\n * @type {Map<any, Node>}\n */\n this._set = new Map()\n /**\n * @type {Node|undefined}\n */\n this._head = undefined\n /**\n * @type {Node|undefined}\n */\n this._tail = undefined\n }\n\n get size () {\n return this._set.size\n }\n\n // 获取最旧的元素\n get oldest () {\n return this._head?.value\n }\n\n // 获取最新的元素\n get newest () {\n return this._tail?.value\n }\n\n [Symbol.iterator] () {\n return this._set.keys()\n }\n\n /**\n * Adds a value to the capped set. If the value already exists, it will be moved to the most recent position.\n * If the set is at capacity, the oldest element will be removed before adding the new value.\n * @param {*} value - The value to add to the set\n */\n add (value) {\n if (this._set.has(value)) {\n const node = this._set.get(value)\n node && this._removeNode(node)\n } else if (this.size >= this.capacity) {\n this._removeOldest()\n }\n this._addNew(value)\n }\n\n /**\n * Checks if the value exists in the set.\n * @param {*} value - The value to check for existence.\n * @returns {boolean} True if the value exists, false otherwise.\n */\n has (value) {\n return this._set.has(value)\n }\n\n /**\n * Deletes a value from the capped set.\n * @param {*} value - The value to remove from the set.\n * @returns {boolean} True if the value was found and removed, false otherwise.\n */\n delete (value) {\n if (this._set.has(value)) {\n const node = this._set.get(value)\n node && this._removeNode(node)\n return true\n }\n return false\n }\n\n clear () {\n this._set.clear()\n this._head = undefined\n this._tail = undefined\n }\n\n /**\n * Returns an iterator of the values in the set.\n * @returns {Iterator<any>} An iterator object that yields the values of the set.\n */\n values () {\n return this._set.keys()\n }\n\n /**\n * Adds a new value to the set by creating a node and appending it to the tail.\n * Updates the linked list structure and maintains the set's size.\n * @private\n * @param {*} value - The value to be added to the set.\n */\n _addNew (value) {\n /**\n * @type {Node}\n */\n const node = { value, prev: this._tail, next: undefined }\n\n if (this._tail) {\n this._tail.next = node\n } else {\n this._head = node\n }\n\n this._tail = node\n this._set.set(value, node)\n }\n\n /**\n * Removes a node from the linked list and the internal Set.\n * Updates head/tail pointers and maintains list consistency.\n * @param {Node} node - The node to be removed\n * @private\n */\n _removeNode (node) {\n if (node.prev) {\n node.prev.next = node.next\n } else {\n this._head = node.next\n }\n\n if (node.next) {\n node.next.prev = node.prev\n } else {\n this._tail = node.prev\n }\n\n this._set.delete(node.value)\n }\n\n _removeOldest () {\n if (this._head) {\n this._removeNode(this._head)\n }\n }\n}\n\nexport { CappedSet }\n","import CappedSet from './capped-set.js'\n\nexport default { CappedSet }\nexport { CappedSet }\n"],"names":["TypeAssert"],"mappings":"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"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).CommonsLang={})}(this,function(e){"use strict";var t={assertPositive:function(e,t){if(!function(e){return!!function(e){return null!=e&&"number"==typeof e}(e)&&e>0}(e))throw new Error(`${t?'"'+t+'" ':" "}Not Positive: ${e}`)}};new TextDecoder,new TextEncoder;const{assertPositive:s}=t;class i{constructor(e){s(e,"capacity"),this.capacity=e,this._set=new Map,this._head=void 0,this._tail=void 0}get size(){return this._set.size}get oldest(){return this._head?.value}get newest(){return this._tail?.value}[Symbol.iterator](){return this._set.keys()}add(e){if(this._set.has(e)){const t=this._set.get(e);t&&this._removeNode(t)}else this.size>=this.capacity&&this._removeOldest();this._addNew(e)}has(e){return this._set.has(e)}delete(e){if(this._set.has(e)){const t=this._set.get(e);return t&&this._removeNode(t),!0}return!1}clear(){this._set.clear(),this._head=void 0,this._tail=void 0}values(){return this._set.keys()}_addNew(e){const t={value:e,prev:this._tail,next:void 0};this._tail?this._tail.next=t:this._head=t,this._tail=t,this._set.set(e,t)}_removeNode(e){e.prev?e.prev.next=e.next:this._head=e.next,e.next?e.next.prev=e.prev:this._tail=e.prev,this._set.delete(e.value)}_removeOldest(){this._head&&this._removeNode(this._head)}}var r={CappedSet:i};e.CappedSet=i,e.default=r,Object.defineProperty(e,"__esModule",{value:!0})});
|
|
2
|
+
//# sourceMappingURL=index.min.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.min.js","sources":["../../../lang/dist/esm/index-min.js","../../lib/capped-set.js","../../lib/index.js"],"sourcesContent":["var t={constructorName:r,defaults:function(t,...r){if(null==t)throw new TypeError('\"target\" must not be null or undefined');for(const n of r)if(null!=n)for(const r in n)void 0===t[r]&&(t[r]=n[r]);return t},extend:n,extends:n,equals:function(t,r){if(t===r)return!0;if(\"function\"==typeof t?.equals)return t.equals(r);if(\"function\"==typeof r?.equals)return r.equals(t);return!1},isBrowser:e,isNode:function(){return!e()}};function r(t){return t?.constructor?.name}function n(t,...r){if(null==t)throw new TypeError('\"target\" must not be null or undefined');for(const n of r)if(null!=n)for(const r in n)t[r]=n[r];return t}function e(){return\"undefined\"!=typeof window&&\"undefined\"!=typeof document}var o={isArray:i,isBoolean:s,isBuffer:function(t){return null!=t&&Buffer.isBuffer(t)},isFunction:u,isInstance:f,isIterable:function(t){return null!=t&&\"function\"==typeof t[Symbol.iterator]},isDate:function(t){return null!=t&&t instanceof Date},isError:function(t){return null!=t&&t instanceof Error},isMap:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===Map},isWeakMap:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===WeakMap},isNumber:h,isPositive:c,isNegative:y,isNotNegative:l,isNil:a,isNullOrUndefined:function(t){return null==t},isNull:p,isUndefined:g,isPlainObject:d,isObject:w,isPromise:m,isRegExp:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===RegExp},isSet:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===Set},isWeakSet:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===WeakSet},isStream:function(t){return null!=t&&\"function\"==typeof t.pipe},isString:b,isSymbol:N,isPrimitive:function(t){return null!==t&&(\"string\"==typeof t||\"number\"==typeof t||\"boolean\"==typeof t)},isInt8Array:E,isUint8Array:O,isUint8ClampedArray:$,isInt16Array:v,isUint16Array:S,isInt32Array:U,isUint32Array:x,isFloat32Array:P,isFloat64Array:j,isBigInt64Array:B,isBigUint64Array:I,isTypedArray:A,isArrayBuffer:T};function i(t){return Array.isArray(t)}function s(t){return\"boolean\"==typeof t}function u(t){return\"function\"==typeof t}function f(t){return null!=t&&\"object\"==typeof t&&!d(t)}function a(t){return null==t}function c(t){return!!h(t)&&t>0}function l(t){return!!h(t)&&t>=0}function y(t){return!!h(t)&&t<0}function p(t){return null===t}function g(t){return void 0===t}function h(t){return null!=t&&\"number\"==typeof t}function w(t){return null!=t&&\"object\"==typeof t}function d(t){return null!==t&&\"object\"==typeof t&&(t.constructor===Object||void 0===t.constructor)}function m(t){return null!=t&&\"function\"==typeof t.then}function b(t){return null!=t&&\"string\"==typeof t}function N(t){return null!=t&&\"symbol\"==typeof t}function A(t){return ArrayBuffer.isView(t)&&t.constructor!==DataView}function E(t){return t instanceof Int8Array}function O(t){return t instanceof Uint8Array}function $(t){return t instanceof Uint8ClampedArray}function v(t){return t instanceof Int16Array}function S(t){return t instanceof Uint16Array}function U(t){return t instanceof Int32Array}function x(t){return t instanceof Uint32Array}function P(t){return t instanceof Float32Array}function j(t){return t instanceof Float64Array}function B(t){return t instanceof BigInt64Array}function I(t){return t instanceof BigUint64Array}function T(t){return t instanceof ArrayBuffer}var L={assertNumber:C,assertPositive:q,assertNegative:function(t,r){if(!y(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Negative: ${t}`)},assertNotNegative:D,assertBoolean:function(t,r){if(!s(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Boolean: type=${typeof t} value=${JSON.stringify(t)}`)},assertObject:F,assertPlainObject:function(t,r){if(!d(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not PlainObject: type=${typeof t} value=${JSON.stringify(t)}`)},assertSymbol:function(t,r){if(!N(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Symbol: type=${typeof t} value=${JSON.stringify(t)}`)},assertFunction:M,assertInstance:function(t,r){if(!f(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Class Instance: type=${typeof t} value=${JSON.stringify(t)}`)},assertPromise:R,assertNil:function(t,r){if(!a(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Neither Null nor Undefined: type=${typeof t} value=${JSON.stringify(t)}`)},assertNotNil:W,assertNull:function(t,r){if(!p(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Null: type=${typeof t} value=${JSON.stringify(t)}`)},assertNotNull:function(t,r){if(p(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Should Not Null\")},assertUndefined:function(t,r){if(!g(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Undefined: type=${typeof t} value=${JSON.stringify(t)}`)},assertString:J,assertArray:k,assertStringOrSymbol:function(t,r){if(!b(t)&&!N(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not String or Symbol: type=${typeof t} value=${JSON.stringify(t)}`)},assertInt8Array:function(t,r){if(E(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Int8Array\")},assertUint8Array:function(t,r){if(O(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Uint8Array\")},assertUint8ClampedArray:function(t,r){if($(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Uint8ClampedArray\")},assertInt16Array:function(t,r){if(v(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Int16Array\")},assertUint16Array:function(t,r){if(S(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Uint16Array\")},assertInt32Array:function(t,r){if(U(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Int32Array\")},assertUint32Array:function(t,r){if(x(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Uint32Array\")},assertFloat32Array:function(t,r){if(P(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Float32Array\")},assertFloat64Array:function(t,r){if(j(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not Float64Array\")},assertBigInt64Array:function(t,r){if(B(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not BigInt64Array\")},assertBigUint64Array:function(t,r){if(I(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not BigUint64Array\")},assertTypedArray:function(t,r){if(A(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not TypedArray\")},assertArrayBuffer:V};function k(t,r){if(!Array.isArray(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Array: type=${typeof t} value=${JSON.stringify(t)}`)}function J(t,r){if(!b(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not String: type=${typeof t} value=${JSON.stringify(t)}`)}function C(t,r){if(!h(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Number: type=${typeof t} value=${JSON.stringify(t)}`)}function q(t,r){if(!c(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Positive: ${t}`)}function D(t,r){if(!l(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not \"0 or Positive\": ${t}`)}function F(t,r){if(!w(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Object: type=${typeof t} value=${JSON.stringify(t)}`)}function M(t,r){if(!u(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Function: type=${typeof t} value=${JSON.stringify(t)}`)}function R(t,r){if(!m(t))throw new Error(`${r?'\"'+r+'\" ':\" \"}Not Promise: type=${typeof t} value=${JSON.stringify(t)}`)}function W(t,r){if(a(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Should Not Nil\")}function V(t,r){if(!T(t))throw new Error((r?'\"'+r+'\" ':\" \")+\"Not ArrayBuffer\")}var H={isEmpty:z,assertNotEmpty:G,isBlank:K,assertNotBlank:function(t){if(K(t))throw new Error(`Blank String: ${t}`)},capitalize:function(t){if(J(t),0===t.length)return t;const r=t.charAt(0),n=r.toUpperCase();return r===n?t:n+t.slice(1)},decapitalize:function(t){if(J(t),0===t.length)return t;const r=t.charAt(0),n=r.toLowerCase();return r===n?t:n+t.slice(1)},splitWithFixedLength:function(t,r,n=\" \"){if(J(t),C(r),J(n),0===t.length)return[];if(r<=0)throw new Error(\"length muse >=0\");if(t.length<r)return[t.padEnd(r,n)];const e=[];for(let o=0;o<t.length;o+=r){const i=t.substring(o,o+r);e.push(i.padEnd(r,n))}return e},split:function(t,...r){J(t);if(0===t.length)return[];const n=[...r];0===r.length&&r.push(\",\");const e=Q(t,...n);if(0===e.length)return[];const o=[];let i=\"\",s=0;for(const{marker:r,index:n}of e)i=t.substring(s,n),o.push(i),s=n+r.length;return i=t.substring(s),o.push(i),o},findMarkerPositions:function(t,...r){if(J(t),0===r.length)throw new Error(\"At least one marker must be provided\");const n=[];for(const e of new Set(r)){if(z(e))continue;J(e);let r=t.indexOf(e);for(;-1!==r;)n.push({marker:e,index:r}),r=t.indexOf(e,r+e.length)}return n.sort((t,r)=>t.index-r.index),n},findMarkerPositionsRegex:Q,substringBefore:function(t,r){if(J(t),J(r),0===t.length||0===r.length)return;const n=t.indexOf(r);if(-1===n)return;return t.substring(0,n)},substringBeforeLast:function(t,r){if(J(t),J(r),0===t.length||0===r.length)return;const n=t.lastIndexOf(r);if(-1===n)return;return t.substring(0,n)},substringAfter:function(t,r){if(J(t),J(r),0===t.length||0===r.length)return;const n=t.indexOf(r);if(-1===n)return;return t.substring(n+r.length)},substringAfterLast:function(t,r){if(J(t),J(r),0===t.length||0===r.length)return;const n=t.lastIndexOf(r);if(-1===n)return;return t.substring(n+r.length)},substringBetween:function(t,r,n){G(t),G(r),G(n);const e=t.indexOf(r);if(-1===e)return;const o=t.indexOf(n,e+r.length);if(-1===o)return;return t.substring(e+r.length,o)},substringBetweenGreedy:function(t,r,n){G(t),G(r),G(n);const e=t.indexOf(r);if(-1===e)return;const o=t.lastIndexOf(n);if(-1===o||o<=e)return;return t.substring(e+r.length,o)},substringsBetween:function(t,r,n){G(t),G(r),G(n);const e=[];let o=0;for(;;){const i=t.indexOf(r,o);if(-1===i)break;const s=t.indexOf(n,i+r.length);if(-1===s)break;e.push(t.substring(i+r.length,s)),o=s+n.length}return e}};function z(t){return null==t||(J(t),0===t.length)}function G(t){if(z(t))throw new Error(`Empty String: ${t}`)}function K(t){return null==t||(J(t),0===t.trim().length)}function Q(t,...r){if(J(t),0===r.length)throw new Error(\"At least one marker must be provided\");const n=[...new Set(r.filter(t=>null!=t))].map(t=>(J(t),t.replace(/[.*+?^${}()|[\\]\\\\]/g,\"\\\\$&\"))),e=new RegExp(n.map(t=>`(${t})`).join(\"|\"),\"g\"),o=[];let i=null;for(;null!==(i=e.exec(t));){for(let t=1;t<i.length;t++)if(i[t]){o.push({marker:r[t-1],index:i.index});break}0===i[0].length&&e.lastIndex++}return o}var X={quiet:function(t,r){M(t);try{const n=t();return m(n)?n.catch(t=>{r&&r.isErrorEnabled()&&r.error(\"quiet() with async error:\",t)}):n}catch(t){r&&r.isErrorEnabled()&&r.error(\"quiet() with sync error:\",t)}},quietKeepError:function(t,r){M(t),k(r);try{const n=t();return m(n)?n.catch(t=>r.push(t)):n}catch(t){r.push(t)}}},Y={defer:Z,delay:function(t,r){h(t)?(r=t,t=Promise.resolve()):null==t&&null==r&&(r=1,t=Promise.resolve());null!=t&&R(t),C(r=r??1e3);const n=Z(),e=Date.now();return t.then((...t)=>{const o=Date.now()-e;o<r?setTimeout(()=>n.resolve(...t),r-o):n.resolve(...t)}).catch(t=>{const o=Date.now()-e;o<r?setTimeout(()=>n.reject(t),r-o):n.reject(t)}),n.promise},timeout:function(t,r,n){R(t),C(r=r??1);const e=Z(r,n),o=Date.now();return t.then((...t)=>{Date.now()-o<=r?e.resolve(...t):e.reject(new Error(n??`Promise Timeout: ${r}ms`))}).catch(t=>{!e.resolved&&!e.rejected&&e.reject(t)}),e.promise},allSettled:_,returnValuePromised:tt,series:async function(t){k(t);const r=[];for(const n of t)M(n),r.push(await n());return r},seriesAllSettled:async function(t){k(t);const r=[];for(const n of t){M(n);try{r.push({ok:!0,result:await n()})}catch(t){r.push({ok:!1,result:t})}}return r},parallel:async function(t,r=5){if(k(t),C(r),r<=0)throw new Error(`Invalid maxParallel: ${r}, should > 0`);t.forEach(t=>M(t));const n=[];if(t.length<=r){const r=await Promise.all(t.map(t=>tt(t)));return n.push(...r),n}const e=[];for(const o of t)if(M(o),e.push(o),e.length>=r){const t=await Promise.all(e.map(t=>tt(t)));n.push(...t),e.length=0}if(e.length>0&&e.length<r){const t=await Promise.all(e.map(t=>tt(t)));n.push(...t)}return n},parallelAllSettled:async function(t,r=5){if(k(t),C(r),r<=0)throw new Error(`Invalid maxParallel: ${r}, should > 0`);t.forEach(t=>M(t));const n=[];if(t.length<=r){const r=await _(t.map(t=>tt(t)));return n.push(...r),n}const e=[];for(const o of t)if(M(o),e.push(o),e.length>=r){const t=await _(e.map(t=>tt(t)));n.push(...t),e.length=0}if(e.length>0&&e.length<r){const t=await _(e.map(t=>tt(t)));n.push(...t)}return n}};function Z(t=-1,r){C(t);const n={};let e;return t>=0&&(n.timerHandler=e=setTimeout(()=>{clearTimeout(e),n.timerCleared=!0,n.reject(new Error(r??`Promise Timeout: ${t}ms`))},t)),n.promise=new Promise((t,r)=>{n.resolve=r=>{null!=e&&(clearTimeout(e),n.timerCleared=!0),n.resolved=!0,t(r)},n.reject=t=>{null!=e&&(clearTimeout(e),n.timerCleared=!0),n.rejected=!0,r(t)}}),n.promise.cancel=()=>{null!=e&&(clearTimeout(e),n.timerCleared=!0),n.rejected=!0,n.canceled=n.promise.canceled=!0,n.reject(new Error(\"Cancelled\"))},n}async function _(t){k(t);const r=await Promise.allSettled(t),n=[];for(const t of r)\"fulfilled\"===t.status&&n.push({ok:!0,result:t.value}),\"rejected\"===t.status&&n.push({ok:!1,result:t.reason});return n}function tt(t){try{const r=t();return m(r)?r:Promise.resolve(r)}catch(t){return Promise.reject(t)}}const{isPlainObject:rt}=o;var nt={proxy:et,newProxyInstance:function(t,r,n,e=!0){const o=et(t,n,e);return Reflect.construct(o,r??[])}};function et(t,r,n=!0){if(\"function\"!=typeof t)throw new TypeError(`Not Class: type=${typeof t}, value=${JSON.stringify(t)}`);if(null!=r){if(!rt(r))throw new TypeError(`Not PropertyHandler: type=${typeof r}, value=${JSON.stringify(r)}`);const{get:t,set:n}=r;if(null!=t&&\"function\"!=typeof t)throw new TypeError(`Not PropertyHandler.get: type=${typeof t}, value=${JSON.stringify(t)}`);if(null!=n&&\"function\"!=typeof n)throw new TypeError(`Not PropertyHandler.set: type=${typeof n}, value=${JSON.stringify(n)}`)}const e={construct(t,e,o){const i=Reflect.construct(t,e);return new Proxy(n?Object.preventExtensions(i):i,r??{})}};return new Proxy(t,e)}var ot={proxy:function(t,r,n=!0){if(a(t)||!w(t)||i(t))throw new TypeError(`Not Object: type=${typeof t}, value=${JSON.stringify(t)}`);return new Proxy(n?Object.preventExtensions(t):t,r??{})}};function it(t){F(t,\"obj\");const r=new Set;let n=t;for(;n&&n!==Object.prototype;){const e=Object.getOwnPropertyNames(n);for(const n of e)\"constructor\"!==n&&\"function\"==typeof t[n]&&r.add(n);n=Object.getPrototypeOf(n)}return[...new Set(r)]}var st={getMethodsOfClass:function(t){M(t,\"cls\");const r=new Set;let n=t.prototype;for(;n&&n!==Object.prototype;){const t=Object.getOwnPropertyNames(n);for(const e of t)\"constructor\"!==e&&\"function\"==typeof n[e]&&r.add(e);n=Object.getPrototypeOf(n)}return[...new Set(r)]},getStaticMethodsOfClass:function(t){M(t,\"cls\");const r=new Set;let n=t;for(;n&&n!==Object.getPrototypeOf(Object);){const t=Object.getOwnPropertyNames(n);for(const e of t)\"function\"==typeof n[e]&&r.add(e);n=Object.getPrototypeOf(n)}return[...r]},getMethods:it,getMethodsOfObject:it},ut={startsWith:function(t,r){W(t,\"src\"),W(r,\"searching\");return at(t.subarray(0,r.length),r)},isSameType:ft,equals:at};function ft(t,n){return W(t,\"src\"),W(n,\"target\"),r(t)===r(n)}function at(t,r){if(W(t,\"src\"),W(r,\"target\"),!ft(t,r))return!1;if(t.byteLength!==r.byteLength)return!1;const n=new DataView(t.buffer,t.byteOffset,t.byteLength),e=new DataView(r.buffer,r.byteOffset,r.byteLength);for(let r=0;r<t.byteLength;r++)if(n.getUint8(r)!==e.getUint8(r))return!1;return!0}var ct={readString:function(t,r=0,n){if(V(t),D(r),r>=t.byteLength)return;let e=null;null!=n?(q(n),e=r+n>=t.byteLength?new Uint8Array(t,r):new Uint8Array(t,r,n)):e=new Uint8Array(t,r);return lt.decode(e)},writeString:function(t,r,n=0){V(t,\"buffer\"),J(r,\"str\"),D(n,\"offset\");const e=yt.encode(r),o=e.byteLength;if(n+o>t.byteLength)throw new Error(`offset + str.byteLength > buffer.byteLength:${n+o} > ${t.byteLength}`);new Uint8Array(t,n,e.byteLength).set(e)},writeArrayBuffer:function(t,r,n=0,e=0,o){V(t),V(r),C(n),C(e);const i=t.byteLength;if(n<-1*i)n=0;else if(n<0)n+=i;else if(n>=i)throw new Error(`Out of target Bounds: targetOffset(${n}) >= targetLength(${i})`);const s=r.byteLength;if(e<-1*s)e=0;else if(e<0)e+=s;else if(e>=s)throw new Error(`Out of data Bounds: dataOffset(${e}) >= dataArrayBufferLength(${s})`);null!=o&&(q(o,\"dataLength\"),e+o>s&&(o=void 0));const u=new Uint8Array(r,e,o);if(u.byteLength>i-n)throw new Error(`Out of target Bounds: from targetOffset(${n}), No Space to store dataArrayBuffer(${e}, ${o??\"NoLimit\"})`);new Uint8Array(t).set(u,n)}};const lt=new TextDecoder,yt=new TextEncoder;const pt=1e6;var gt={s2ns:1e9,ms2ns:pt,timestamp64:ht,lapseNano:wt,lapseMillis:dt,timeoutNano:function(t,r){return wt(t)>r},timeoutMillis:function(t,r){return dt(t)>r}};function ht(){if(\"undefined\"!=typeof performance&&\"number\"==typeof performance.timeOrigin){const t=performance.timeOrigin,r=performance.now();return BigInt((t+r)*pt)}return BigInt(Date.now()*pt)}function wt(t,r){return(r??ht())-t}function dt(t,r){r=r??ht();return BigInt(r-t)/BigInt(pt)}var mt={first:function(t,r){return k(t,\"arr\"),t[0]??r},last:function(t,r){return k(t,\"arr\"),t[t.length-1]??r},equals:function(t,r,n){if(!Array.isArray(t)||!Array.isArray(r))return!1;if(t.length!==r.length)return!1;for(let e=0;e<t.length;e++)if(n){if(0!==n(t[e],r[e]))return!1}else if(t[e]!==r[e])return!1;return!0},equalsIgnoreOrder:function(t,r,n){if(!Array.isArray(t)||!Array.isArray(r))return!1;if(t.length!==r.length)return!1;t.sort(n),r.sort(n);for(let e=0;e<t.length;e++)if(n){if(0!==n(t[e],r[e]))return!1}else if(t[e]!==r[e])return!1;return!0}};var bt={LangUtils:t,StringUtils:H,TypeUtils:o,TypeAssert:L,ExecUtils:X,PromiseUtils:Y,Lang:t,Type:o,Exec:X,ClassProxyUtils:nt,InstanceProxyUtils:ot,ReflectUtils:st,TypedArrayUtils:ut,ArrayBufferUtils:ct,TimeUtils:gt,ArrayUtils:mt};export{ct as ArrayBufferUtils,mt as ArrayUtils,nt as ClassProxyUtils,X as Exec,X as ExecUtils,ot as InstanceProxyUtils,t as Lang,t as LangUtils,Y as PromiseUtils,st as ReflectUtils,H as StringUtils,gt as TimeUtils,o as Type,L as TypeAssert,o as TypeUtils,ut as TypedArrayUtils,bt as default};\n//# sourceMappingURL=index-min.js.map\n","// internal\n// owned\nimport { TypeAssert } from '@creejs/commons-lang'\n\n/**\n * @typedef {{\n * value: any,\n * prev: Node|undefined,\n * next: Node|undefined\n * }} Node\n */\n\n// module vars\nconst { assertPositive } = TypeAssert\n\n/**\n * A set that has a fixed capacity and automatically removes the oldest element when the capacity is reached.\n *\n * @class CappedSet\n */\nexport default class CappedSet {\n /**\n * Creates a new CappedSet instance with a fixed capacity.\n * @constructor\n * @param {number} capacity - The maximum number of elements the set can hold (must be > 0)\n * @throws {Error} If capacity is less than or equal to 0\n */\n constructor (capacity) {\n assertPositive(capacity, 'capacity')\n this.capacity = capacity\n /**\n * @type {Map<any, Node>}\n */\n this._set = new Map()\n /**\n * @type {Node|undefined}\n */\n this._head = undefined\n /**\n * @type {Node|undefined}\n */\n this._tail = undefined\n }\n\n get size () {\n return this._set.size\n }\n\n // 获取最旧的元素\n get oldest () {\n return this._head?.value\n }\n\n // 获取最新的元素\n get newest () {\n return this._tail?.value\n }\n\n [Symbol.iterator] () {\n return this._set.keys()\n }\n\n /**\n * Adds a value to the capped set. If the value already exists, it will be moved to the most recent position.\n * If the set is at capacity, the oldest element will be removed before adding the new value.\n * @param {*} value - The value to add to the set\n */\n add (value) {\n if (this._set.has(value)) {\n const node = this._set.get(value)\n node && this._removeNode(node)\n } else if (this.size >= this.capacity) {\n this._removeOldest()\n }\n this._addNew(value)\n }\n\n /**\n * Checks if the value exists in the set.\n * @param {*} value - The value to check for existence.\n * @returns {boolean} True if the value exists, false otherwise.\n */\n has (value) {\n return this._set.has(value)\n }\n\n /**\n * Deletes a value from the capped set.\n * @param {*} value - The value to remove from the set.\n * @returns {boolean} True if the value was found and removed, false otherwise.\n */\n delete (value) {\n if (this._set.has(value)) {\n const node = this._set.get(value)\n node && this._removeNode(node)\n return true\n }\n return false\n }\n\n clear () {\n this._set.clear()\n this._head = undefined\n this._tail = undefined\n }\n\n /**\n * Returns an iterator of the values in the set.\n * @returns {Iterator<any>} An iterator object that yields the values of the set.\n */\n values () {\n return this._set.keys()\n }\n\n /**\n * Adds a new value to the set by creating a node and appending it to the tail.\n * Updates the linked list structure and maintains the set's size.\n * @private\n * @param {*} value - The value to be added to the set.\n */\n _addNew (value) {\n /**\n * @type {Node}\n */\n const node = { value, prev: this._tail, next: undefined }\n\n if (this._tail) {\n this._tail.next = node\n } else {\n this._head = node\n }\n\n this._tail = node\n this._set.set(value, node)\n }\n\n /**\n * Removes a node from the linked list and the internal Set.\n * Updates head/tail pointers and maintains list consistency.\n * @param {Node} node - The node to be removed\n * @private\n */\n _removeNode (node) {\n if (node.prev) {\n node.prev.next = node.next\n } else {\n this._head = node.next\n }\n\n if (node.next) {\n node.next.prev = node.prev\n } else {\n this._tail = node.prev\n }\n\n this._set.delete(node.value)\n }\n\n _removeOldest () {\n if (this._head) {\n this._removeNode(this._head)\n }\n }\n}\n\nexport { CappedSet }\n","import CappedSet from './capped-set.js'\n\nexport default { CappedSet }\nexport { CappedSet }\n"],"names":["L","assertPositive","t","r","h","c","Error","TextDecoder","TextEncoder","TypeAssert","CappedSet","constructor","capacity","this","_set","Map","_head","undefined","_tail","size","oldest","value","newest","Symbol","iterator","keys","add","has","node","get","_removeNode","_removeOldest","_addNew","clear","values","prev","next","set","delete","index"],"mappings":"kPAA6uG,IAAIA,EAAE,CAAgBC,eAAy5F,SAAWC,EAAEC,GAAG,IAAnjI,SAAWD,GAAG,QAAiJ,SAAWA,GAAG,OAAO,MAAMA,GAAG,iBAAiBA,CAAC,CAAzLE,CAAEF,IAAIA,EAAE,CAAC,CAAwhIG,CAAEH,GAAG,MAAM,IAAII,MAAM,GAAGH,EAAE,IAAIA,EAAE,KAAK,oBAAoBD,IAAI,GAA4/S,IAAIK,YAAe,IAAIC,YCahwf,MAAMP,eAAEA,GAAmBQ,EAOZ,MAAMC,EAOnB,WAAAC,CAAaC,GACXX,EAAeW,EAAU,YACzBC,KAAKD,SAAWA,EAIhBC,KAAKC,KAAO,IAAIC,IAIhBF,KAAKG,WAAQC,EAIbJ,KAAKK,WAAQD,CACf,CAEA,QAAIE,GACF,OAAON,KAAKC,KAAKK,IACnB,CAGA,UAAIC,GACF,OAAOP,KAAKG,OAAOK,KACrB,CAGA,UAAIC,GACF,OAAOT,KAAKK,OAAOG,KACrB,CAEA,CAACE,OAAOC,YACN,OAAOX,KAAKC,KAAKW,MACnB,CAOA,GAAAC,CAAKL,GACH,GAAIR,KAAKC,KAAKa,IAAIN,GAAQ,CACxB,MAAMO,EAAOf,KAAKC,KAAKe,IAAIR,GAC3BO,GAAQf,KAAKiB,YAAYF,EAC3B,MAAWf,KAAKM,MAAQN,KAAKD,UAC3BC,KAAKkB,gBAEPlB,KAAKmB,QAAQX,EACf,CAOA,GAAAM,CAAKN,GACH,OAAOR,KAAKC,KAAKa,IAAIN,EACvB,CAOA,OAAQA,GACN,GAAIR,KAAKC,KAAKa,IAAIN,GAAQ,CACxB,MAAMO,EAAOf,KAAKC,KAAKe,IAAIR,GAE3B,OADAO,GAAQf,KAAKiB,YAAYF,IAClB,CACT,CACA,OAAO,CACT,CAEA,KAAAK,GACEpB,KAAKC,KAAKmB,QACVpB,KAAKG,WAAQC,EACbJ,KAAKK,WAAQD,CACf,CAMA,MAAAiB,GACE,OAAOrB,KAAKC,KAAKW,MACnB,CAQA,OAAAO,CAASX,GAIP,MAAMO,EAAO,CAAEP,QAAOc,KAAMtB,KAAKK,MAAOkB,UAAMnB,GAE1CJ,KAAKK,MACPL,KAAKK,MAAMkB,KAAOR,EAElBf,KAAKG,MAAQY,EAGff,KAAKK,MAAQU,EACbf,KAAKC,KAAKuB,IAAIhB,EAAOO,EACvB,CAQA,WAAAE,CAAaF,GACPA,EAAKO,KACPP,EAAKO,KAAKC,KAAOR,EAAKQ,KAEtBvB,KAAKG,MAAQY,EAAKQ,KAGhBR,EAAKQ,KACPR,EAAKQ,KAAKD,KAAOP,EAAKO,KAEtBtB,KAAKK,MAAQU,EAAKO,KAGpBtB,KAAKC,KAAKwB,OAAOV,EAAKP,MACxB,CAEA,aAAAU,GACMlB,KAAKG,OACPH,KAAKiB,YAAYjB,KAAKG,MAE1B,EChKF,IAAAuB,EAAe,CAAE7B"}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@creejs/commons-collection",
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "Commons Collection",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"commons",
|
|
7
|
+
"creejs",
|
|
8
|
+
"collection"
|
|
9
|
+
],
|
|
10
|
+
"private": false,
|
|
11
|
+
"type": "module",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist/",
|
|
14
|
+
"types/"
|
|
15
|
+
],
|
|
16
|
+
"types": "types/index.d.ts",
|
|
17
|
+
"main": "./dist/esm/index-min.js",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"import": {
|
|
21
|
+
"development": "./dist/esm/index-dev.js",
|
|
22
|
+
"production": "./dist/esm/index-min.js",
|
|
23
|
+
"default": "./dist/esm/index-min.js"
|
|
24
|
+
},
|
|
25
|
+
"require": {
|
|
26
|
+
"development": "./dist/cjs/index-dev.cjs",
|
|
27
|
+
"production": "./dist/cjs/index-min.cjs",
|
|
28
|
+
"default": "./dist/cjs/index-min.cjs"
|
|
29
|
+
},
|
|
30
|
+
"browser": {
|
|
31
|
+
"development": "./dist/umd/index-dev.js",
|
|
32
|
+
"production": "./dist/umd/index-min.js",
|
|
33
|
+
"default": "./dist/cjs/index-min.js"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/frameworkee/commons.git"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"dts": "npx tsc",
|
|
46
|
+
"generate-docs": "../../node_modules/.bin/jsdoc -c ./jsdoc.json",
|
|
47
|
+
"clean": "rm -rf dist && rm -rf types",
|
|
48
|
+
"build": "npm run clean && npm run dts && rollup -c"
|
|
49
|
+
},
|
|
50
|
+
"author": "rodney.vin@gmail.com",
|
|
51
|
+
"license": "Apache-2.0",
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@creejs/commons-lang": "^2.1.2"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A set that has a fixed capacity and automatically removes the oldest element when the capacity is reached.
|
|
3
|
+
*
|
|
4
|
+
* @class CappedSet
|
|
5
|
+
*/
|
|
6
|
+
export default class CappedSet {
|
|
7
|
+
/**
|
|
8
|
+
* Creates a new CappedSet instance with a fixed capacity.
|
|
9
|
+
* @constructor
|
|
10
|
+
* @param {number} capacity - The maximum number of elements the set can hold (must be > 0)
|
|
11
|
+
* @throws {Error} If capacity is less than or equal to 0
|
|
12
|
+
*/
|
|
13
|
+
constructor(capacity: number);
|
|
14
|
+
capacity: number;
|
|
15
|
+
/**
|
|
16
|
+
* @type {Map<any, Node>}
|
|
17
|
+
*/
|
|
18
|
+
_set: Map<any, Node>;
|
|
19
|
+
/**
|
|
20
|
+
* @type {Node|undefined}
|
|
21
|
+
*/
|
|
22
|
+
_head: Node | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* @type {Node|undefined}
|
|
25
|
+
*/
|
|
26
|
+
_tail: Node | undefined;
|
|
27
|
+
get size(): number;
|
|
28
|
+
get oldest(): any;
|
|
29
|
+
get newest(): any;
|
|
30
|
+
/**
|
|
31
|
+
* Adds a value to the capped set. If the value already exists, it will be moved to the most recent position.
|
|
32
|
+
* If the set is at capacity, the oldest element will be removed before adding the new value.
|
|
33
|
+
* @param {*} value - The value to add to the set
|
|
34
|
+
*/
|
|
35
|
+
add(value: any): void;
|
|
36
|
+
/**
|
|
37
|
+
* Checks if the value exists in the set.
|
|
38
|
+
* @param {*} value - The value to check for existence.
|
|
39
|
+
* @returns {boolean} True if the value exists, false otherwise.
|
|
40
|
+
*/
|
|
41
|
+
has(value: any): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Deletes a value from the capped set.
|
|
44
|
+
* @param {*} value - The value to remove from the set.
|
|
45
|
+
* @returns {boolean} True if the value was found and removed, false otherwise.
|
|
46
|
+
*/
|
|
47
|
+
delete(value: any): boolean;
|
|
48
|
+
clear(): void;
|
|
49
|
+
/**
|
|
50
|
+
* Returns an iterator of the values in the set.
|
|
51
|
+
* @returns {Iterator<any>} An iterator object that yields the values of the set.
|
|
52
|
+
*/
|
|
53
|
+
values(): Iterator<any>;
|
|
54
|
+
/**
|
|
55
|
+
* Adds a new value to the set by creating a node and appending it to the tail.
|
|
56
|
+
* Updates the linked list structure and maintains the set's size.
|
|
57
|
+
* @private
|
|
58
|
+
* @param {*} value - The value to be added to the set.
|
|
59
|
+
*/
|
|
60
|
+
private _addNew;
|
|
61
|
+
/**
|
|
62
|
+
* Removes a node from the linked list and the internal Set.
|
|
63
|
+
* Updates head/tail pointers and maintains list consistency.
|
|
64
|
+
* @param {Node} node - The node to be removed
|
|
65
|
+
* @private
|
|
66
|
+
*/
|
|
67
|
+
private _removeNode;
|
|
68
|
+
_removeOldest(): void;
|
|
69
|
+
[Symbol.iterator](): MapIterator<any>;
|
|
70
|
+
}
|
|
71
|
+
export type Node = {
|
|
72
|
+
value: any;
|
|
73
|
+
prev: Node | undefined;
|
|
74
|
+
next: Node | undefined;
|
|
75
|
+
};
|