flat-pair 1.0.0 → 1.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/dist/index.d.ts +12 -7
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -11,9 +11,9 @@ declare class FlatPair<K, V> {
|
|
|
11
11
|
removeByValue(value: V): boolean;
|
|
12
12
|
find(key: K): V | undefined;
|
|
13
13
|
findByValue(value: V): K | undefined;
|
|
14
|
-
at(
|
|
14
|
+
at(pairIndex: number): [K, V] | undefined;
|
|
15
15
|
clear(): void;
|
|
16
|
-
forEach(callback: (value: V, key: K,
|
|
16
|
+
forEach(callback: (value: V, key: K, pairIndex: number, array: any[]) => void, thisArg?: any): void;
|
|
17
17
|
keys(): IterableIterator<K>;
|
|
18
18
|
values(): IterableIterator<V>;
|
|
19
19
|
entries(): IterableIterator<[K, V]>;
|
|
@@ -29,8 +29,8 @@ declare class FlatPairOperator<K, V> {
|
|
|
29
29
|
find(items: any[], key: K): V | undefined;
|
|
30
30
|
findByValue(items: any[], value: V): K | undefined;
|
|
31
31
|
removeByValue(items: any[], value: V): boolean;
|
|
32
|
-
forEach(items: any[], callback: (value: V, key: K,
|
|
33
|
-
at(items: any[],
|
|
32
|
+
forEach(items: any[], callback: (value: V, key: K, pairIndex: number, array: any[]) => void, thisArg?: any): void;
|
|
33
|
+
at(items: any[], pairIndex: number): [K, V] | undefined;
|
|
34
34
|
keys(items: any[]): IterableIterator<K>;
|
|
35
35
|
values(items: any[]): IterableIterator<V>;
|
|
36
36
|
entries(items: any[]): IterableIterator<[K, V]>;
|
|
@@ -42,9 +42,14 @@ declare function size(items: any[]): number;
|
|
|
42
42
|
declare function find<K, V>(items: any[], key: K): V | undefined;
|
|
43
43
|
declare function findByValue<K, V>(items: any[], value: V): K | undefined;
|
|
44
44
|
declare function remove<K>(items: any[], key: K): boolean;
|
|
45
|
-
declare function removeByValue<
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
declare function removeByValue<V>(items: any[], value: V): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Behaviors are similar to `Array.prototype.forEach`, caches length and checks index existence.
|
|
48
|
+
*
|
|
49
|
+
* - `callback`: real index in the `arr` is `2 * pairIndex`.
|
|
50
|
+
*/
|
|
51
|
+
declare function forEach<K, V>(items: any[], callback: (value: V, key: K, pairIndex: number, array: any[]) => void, thisArg?: any): void;
|
|
52
|
+
declare function at<K, V>(items: any[], pairIndex: number): [K, V] | undefined;
|
|
48
53
|
declare function clear(items: any[]): void;
|
|
49
54
|
|
|
50
55
|
export { FlatPair, FlatPairOperator, add, at, clear, find, findByValue, forEach, remove, removeByValue, size };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function t(t,r
|
|
1
|
+
function t(t,e,r){const n=t.length;for(let r=0;r<n;r+=2)if(t[r]===e)return;t.push(e,r)}function e(t){const e=t.length;if(e%2!=0)throw new Error("Invalid items length, must be even number");return e/2}function r(t,e){const r=t.length;for(let n=0;n<r;n+=2)if(t[n]===e)return t[n+1]}function n(t,e){const r=t.length;for(let n=1;n<r;n+=2)if(t[n]===e)return t[n-1]}function i(t,e){const r=t.length;for(let n=0;n<r;n+=2)if(t[n]===e)return t.splice(n,2),!0;return!1}function o(t,e){const r=t.length;for(let n=1;n<r;n+=2)if(t[n]===e)return t.splice(n-1,2),!0;return!1}function s(t,e,r){let n=0;const i=t.length;for(let o=0;o<i;o+=2)o in t&&e.call(r,t[o+1],t[o],n,t),n++}function u(t,e){if(e<0)return;const r=2*e;return r+1>=t.length?void 0:[t[r],t[r+1]]}function f(t){t.length=0}class l{static from(t){if("[object Map]"!==Object.prototype.toString.call(t))throw new TypeError("[FlatPair: __func__] Argument must be a Map");const e=[];return t.forEach((t,r)=>e.push(r,t)),new l(e)}items=[];constructor(t){if(t.length%2!=0)throw new TypeError("FlatPair items length must be even");this.items=t}get size(){return this.items.length/2}add(e,r){return t(this.items,e,r),this}remove(t){return i(this.items,t)}removeByValue(t){return o(this.items,t)}find(t){return r(this.items,t)}findByValue(t){return n(this.items,t)}at(t){return u(this.items,t)}clear(){this.items.length=0}forEach(t,e){s(this.items,t,e)}*keys(){for(let t=0;t<this.items.length;t+=2)yield this.items[t]}*values(){for(let t=1;t<this.items.length;t+=2)yield this.items[t]}*entries(){for(let t=0;t<this.items.length;t+=2)yield[this.items[t],this.items[t+1]]}[Symbol.iterator](){return this.entries()}}class c{add(e,r,n){t(e,r,n)}remove(t,e){return i(t,e)}find(t,e){return r(t,e)}findByValue(t,e){return n(t,e)}removeByValue(t,e){return o(t,e)}forEach(t,e,r){s(t,e,r)}at(t,e){return u(t,e)}*keys(t){for(let e=0;e<t.length;e+=2)yield t[e]}*values(t){for(let e=1;e<t.length;e+=2)yield t[e]}*entries(t){for(let e=0;e<t.length;e+=2)yield[t[e],t[e+1]]}clear(t){t.length=0}}export{l as FlatPair,c as FlatPairOperator,t as add,u as at,f as clear,r as find,n as findByValue,s as forEach,i as remove,o as removeByValue,e as size};
|