flat-pair 1.2.0 → 1.3.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 -2
- package/dist/index.d.ts +22 -1
- package/dist/index.mjs +1 -1
- package/package.json +2 -20
package/README.md
CHANGED
|
@@ -37,8 +37,8 @@ import { FlatPair, FlatPairOperator, add, get, find ...others } from 'flat-pair'
|
|
|
37
37
|
```typescript
|
|
38
38
|
// userId - detail pair
|
|
39
39
|
const pairs = new FlatPair<number, Detail>();
|
|
40
|
-
pairs.add(1, { name: 'Alice', age: 30 });
|
|
41
|
-
pairs.
|
|
40
|
+
pairs.add(1, { name: 'Alice', age: 30 }); // won't change value when key exists
|
|
41
|
+
pairs.set(2, { name: 'Bob', age: 25 });
|
|
42
42
|
pairs.remove(1);
|
|
43
43
|
pairs.find((value, key) => value.age > 20);
|
|
44
44
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -10,8 +10,13 @@ declare class FlatPair<K, V> {
|
|
|
10
10
|
get array(): any[];
|
|
11
11
|
/**
|
|
12
12
|
* Will check if the key already exists, if so then do nothing.
|
|
13
|
+
* - different from Map.set, **won't** change value if key exists
|
|
13
14
|
*/
|
|
14
15
|
add(key: K, value: V): this;
|
|
16
|
+
/**
|
|
17
|
+
* Same as Map.set
|
|
18
|
+
*/
|
|
19
|
+
set(key: K, value: V): this;
|
|
15
20
|
hasByValue(value: V): boolean;
|
|
16
21
|
remove(key: K): boolean;
|
|
17
22
|
removeByValue(value: V): boolean;
|
|
@@ -32,7 +37,15 @@ declare class FlatPair<K, V> {
|
|
|
32
37
|
* Creates an static operator
|
|
33
38
|
*/
|
|
34
39
|
declare class FlatPairOperator<K, V> {
|
|
40
|
+
/**
|
|
41
|
+
* Will check if the key already exists, if so then do nothing.
|
|
42
|
+
* - different from Map.set, **won't** change value if key exists
|
|
43
|
+
*/
|
|
35
44
|
add(items: any[], key: K, value: V): void;
|
|
45
|
+
/**
|
|
46
|
+
* Same as Map.set
|
|
47
|
+
*/
|
|
48
|
+
set(items: any[], key: K, value: V): void;
|
|
36
49
|
remove(items: any[], key: K): boolean;
|
|
37
50
|
get(items: any[], key: K): V | undefined;
|
|
38
51
|
getByValue(items: any[], value: V): K | undefined;
|
|
@@ -49,7 +62,15 @@ declare class FlatPairOperator<K, V> {
|
|
|
49
62
|
}
|
|
50
63
|
|
|
51
64
|
declare function size(items: any[]): number;
|
|
65
|
+
/**
|
|
66
|
+
* Will check if the key already exists, if so then do nothing.
|
|
67
|
+
* - different from Map.set, **won't** change value if key exists
|
|
68
|
+
*/
|
|
52
69
|
declare function add<K, V>(items: any[], key: K, value: V): void;
|
|
70
|
+
/**
|
|
71
|
+
* Same as Map.set
|
|
72
|
+
*/
|
|
73
|
+
declare function set<K, V>(items: any[], key: K, value: V): void;
|
|
53
74
|
declare function has<K>(items: any[], key: K): boolean;
|
|
54
75
|
declare function hasByValue<V>(items: any[], value: V): boolean;
|
|
55
76
|
declare function get<K, V>(items: any[], key: K): V | undefined;
|
|
@@ -66,4 +87,4 @@ declare function clear(items: any[]): void;
|
|
|
66
87
|
declare function find<K, V>(items: any[], predicate: (value: V, key: K, index: number, array: any[]) => boolean): [K, V] | undefined;
|
|
67
88
|
declare function findIndex<K, V>(items: any[], predicate: (value: V, key: K, index: number, array: any[]) => boolean): number;
|
|
68
89
|
|
|
69
|
-
export { FlatPair, FlatPairOperator, add, clear, find, findIndex, forEach, get, getByValue, has, hasByValue, remove, removeByValue, size };
|
|
90
|
+
export { FlatPair, FlatPairOperator, add, clear, find, findIndex, forEach, get, getByValue, has, hasByValue, remove, removeByValue, set, size };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const t=t=>{if(t%2!=0)throw new Error(`[FlatPair] Invalid length: ${t}. Length must be even.`)},r=function(t,r){return t===r||t!=t&&r!=r};function e(r){const e=r.length;return t(e),e/2}function n(e,n,i){const u=e.length;t(u);for(let t=0;t<u;t+=2)if(r(e[t],n))return;e.push(n,i)}function i(e,n,i){const u=e.length;t(u);for(let t=0;t<u;t+=2)if(r(e[t],n))return void(e[t+1]=i);e.push(n,i)}function u(e,n){const i=e.length;t(i);for(let t=0;t<i;t+=2)if(r(e[t],n))return!0;return!1}function o(e,n){const i=e.length;t(i);for(let t=1;t<i;t+=2)if(r(e[t],n))return!0;return!1}function s(e,n){const i=e.length;t(i);for(let t=0;t<i;t+=2)if(r(e[t],n))return e[t+1]}function f(e,n){const i=e.length;t(i);for(let t=1;t<i;t+=2)if(r(e[t],n))return e[t-1]}function c(e,n){const i=e.length;t(i);for(let t=0;t<i;t+=2)if(r(e[t],n))return e.splice(t,2),!0;return!1}function l(e,n){const i=e.length;t(i);for(let t=1;t<i;t+=2)if(r(e[t],n))return e.splice(t-1,2),!0;return!1}function h(r,e,n){const i=r.length;t(i);for(let t=0;t<i;t+=2)t in r&&e.call(n,r[t+1],r[t],t,r)}function a(t){t.length=0}function d(r,e){const n=r.length;t(n);for(let t=0;t<n;t+=2){if(e(r[t+1],r[t],t,r))return[r[t],r[t+1]]}}function y(r,e){const n=r.length;t(n);for(let t=0;t<n;t+=2){if(e(r[t+1],r[t],t,r))return t}return-1}class m{static from(t){if("[object Map]"!==Object.prototype.toString.call(t))throw new TypeError("[FlatPair: __func__] Argument must be a Map");const r=[];return t.forEach((t,e)=>r.push(e,t)),new m(r)}t=[];constructor(r){const e=r.length;t(e),this.t=r.slice()}get size(){return this.t.length/2}get array(){return this.t}add(t,r){return n(this.t,t,r),this}set(t,r){return i(this.t,t,r),this}hasByValue(t){return o(this.t,t)}remove(t){return c(this.t,t)}removeByValue(t){return l(this.t,t)}get(t){return s(this.t,t)}getByValue(t){return f(this.t,t)}find(t){return d(this.t,t)}findIndex(t){return y(this.t,t)}clear(){this.t.length=0}has(t){return u(this.t,t)}forEach(t,r){h(this.t,t,r)}*keys(){for(let t=0;t<this.t.length;t+=2)yield this.t[t]}*values(){for(let t=1;t<this.t.length;t+=2)yield this.t[t]}*entries(){for(let t=0;t<this.t.length;t+=2)yield[this.t[t],this.t[t+1]]}[Symbol.iterator](){return this.entries()}}class g{add(t,r,e){n(t,r,e)}set(t,r,e){i(t,r,e)}remove(t,r){return c(t,r)}get(t,r){return s(t,r)}getByValue(t,r){return f(t,r)}find(t,r){return d(t,r)}findIndex(t,r){return y(t,r)}removeByValue(t,r){return l(t,r)}forEach(t,r,e){h(t,r,e)}*keys(t){for(let r=0;r<t.length;r+=2)yield t[r]}*values(t){for(let r=1;r<t.length;r+=2)yield t[r]}*entries(t){for(let r=0;r<t.length;r+=2)yield[t[r],t[r+1]]}clear(t){t.length=0}has(t,r){return u(t,r)}hasByValue(t,r){return o(t,r)}}export{m as FlatPair,g as FlatPairOperator,n as add,a as clear,d as find,y as findIndex,h as forEach,s as get,f as getByValue,u as has,o as hasByValue,c as remove,l as removeByValue,i as set,e as size};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flat-pair",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Kasukabe Tsumugi",
|
|
6
6
|
"email": "futami16237@gmail.com"
|
|
@@ -35,23 +35,5 @@
|
|
|
35
35
|
"build": "node ./.scripts/rollup.mjs"
|
|
36
36
|
},
|
|
37
37
|
"license": "MIT",
|
|
38
|
-
"devDependencies": {
|
|
39
|
-
"@rollup/plugin-alias": "^5.1.1",
|
|
40
|
-
"@rollup/plugin-commonjs": "^28.0.6",
|
|
41
|
-
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
42
|
-
"@rollup/plugin-replace": "^6.0.2",
|
|
43
|
-
"@rollup/plugin-terser": "^0.4.4",
|
|
44
|
-
"@rollup/plugin-typescript": "^12.1.4",
|
|
45
|
-
"@types/node": "^24.6.2",
|
|
46
|
-
"@vitest/coverage-v8": "^3.2.4",
|
|
47
|
-
"oxlint": "^1.19.0",
|
|
48
|
-
"prettier": "^3.6.2",
|
|
49
|
-
"rimraf": "^6.0.1",
|
|
50
|
-
"rollup": "^4.52.4",
|
|
51
|
-
"rollup-plugin-dts": "^6.2.3",
|
|
52
|
-
"rollup-plugin-func-macro": "^1.1.0",
|
|
53
|
-
"tslib": "^2.8.1",
|
|
54
|
-
"typescript": "^5.9.3",
|
|
55
|
-
"vitest": "^3.2.4"
|
|
56
|
-
}
|
|
38
|
+
"devDependencies": {}
|
|
57
39
|
}
|