flat-pair 1.3.0 → 1.3.3

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.
Files changed (2) hide show
  1. package/dist/index.mjs +208 -1
  2. package/package.json +35 -56
package/dist/index.mjs CHANGED
@@ -1 +1,208 @@
1
- const e=function(e,r){return e===r||e!=e&&r!=r};function r(e){const r=e.length;if(r%2!=0)throw new TypeError("[FlatPair: size] items length must be even number");return r/2}function t(r,t,n){const i=r.length;if(i%2!=0)throw new TypeError("[FlatPair: add] items length must be even number");for(let n=0;n<i;n+=2)if(e(r[n],t))return;r.push(t,n)}function n(r,t,n){const i=r.length;if(i%2!=0)throw new TypeError("[FlatPair: set] items length must be even number");for(let u=0;u<i;u+=2)if(e(r[u],t))return void(r[u+1]=n);r.push(t,n)}function i(r,t){const n=r.length;if(n%2!=0)throw new TypeError("[FlatPair: has] items length must be even number");for(let i=0;i<n;i+=2)if(e(r[i],t))return!0;return!1}function u(r,t){const n=r.length;if(n%2!=0)throw new TypeError("[FlatPair: hasByValue] items length must be even number");for(let i=1;i<n;i+=2)if(e(r[i],t))return!0;return!1}function o(r,t){const n=r.length;if(n%2!=0)throw new TypeError("[FlatPair: get] items length must be even number");for(let i=0;i<n;i+=2)if(e(r[i],t))return r[i+1]}function s(r,t){const n=r.length;if(n%2!=0)throw new TypeError("[FlatPair: getByValue] items length must be even number");for(let i=1;i<n;i+=2)if(e(r[i],t))return r[i-1]}function f(r,t){const n=r.length;if(n%2!=0)throw new TypeError("[FlatPair: remove] items length must be even number");for(let i=0;i<n;i+=2)if(e(r[i],t))return r.splice(i,2),!0;return!1}function l(r,t){const n=r.length;if(n%2!=0)throw new TypeError("[FlatPair: removeByValue] items length must be even number");for(let i=1;i<n;i+=2)if(e(r[i],t))return r.splice(i-1,2),!0;return!1}function a(e,r,t){const n=e.length;if(n%2!=0)throw new TypeError("[FlatPair: forEach] items length must be even number");for(let i=0;i<n;i+=2)i in e&&r.call(t,e[i+1],e[i],i,e)}function h(e){e.length=0}function m(e,r){const t=e.length;if(t%2!=0)throw new TypeError("[FlatPair: find] items length must be even number");for(let n=0;n<t;n+=2){if(r(e[n+1],e[n],n,e))return[e[n],e[n+1]]}}function c(e,r){const t=e.length;if(t%2!=0)throw new TypeError("[FlatPair: findIndex] items length must be even number");for(let n=0;n<t;n+=2){if(r(e[n+1],e[n],n,e))return n}return-1}class y{static from(e){if("[object Map]"!==Object.prototype.toString.call(e))throw new TypeError("[FlatPair: from] Argument must be a Map");const r=[];return e.forEach((e,t)=>r.push(t,e)),new y(r)}t=[];constructor(e){if(e.length%2!=0)throw new TypeError("[FlatPair: constructor] items length must be even number");this.t=e.slice()}get size(){return this.t.length/2}get array(){return this.t}add(e,r){return t(this.t,e,r),this}set(e,r){return n(this.t,e,r),this}hasByValue(e){return u(this.t,e)}remove(e){return f(this.t,e)}removeByValue(e){return l(this.t,e)}get(e){return o(this.t,e)}getByValue(e){return s(this.t,e)}find(e){return m(this.t,e)}findIndex(e){return c(this.t,e)}clear(){this.t.length=0}has(e){return i(this.t,e)}forEach(e,r){a(this.t,e,r)}*keys(){for(let e=0;e<this.t.length;e+=2)yield this.t[e]}*values(){for(let e=1;e<this.t.length;e+=2)yield this.t[e]}*entries(){for(let e=0;e<this.t.length;e+=2)yield[this.t[e],this.t[e+1]]}[Symbol.iterator](){return this.entries()}}class b{add(e,r,n){t(e,r,n)}set(e,r,t){n(e,r,t)}remove(e,r){return f(e,r)}get(e,r){return o(e,r)}getByValue(e,r){return s(e,r)}find(e,r){return m(e,r)}findIndex(e,r){return c(e,r)}removeByValue(e,r){return l(e,r)}forEach(e,r,t){a(e,r,t)}*keys(e){for(let r=0;r<e.length;r+=2)yield e[r]}*values(e){for(let r=1;r<e.length;r+=2)yield e[r]}*entries(e){for(let r=0;r<e.length;r+=2)yield[e[r],e[r+1]]}clear(e){e.length=0}has(e,r){return i(e,r)}hasByValue(e,r){return u(e,r)}}export{y as FlatPair,b as FlatPairOperator,t as add,h as clear,m as find,c as findIndex,a as forEach,o as get,s as getByValue,i as has,u as hasByValue,f as remove,l as removeByValue,n as set,r as size};
1
+ const t = t => {
2
+ if (t % 2 != 0) throw new Error(`[FlatPair] Invalid length: ${t}. Length must be even.`);
3
+ }, r = function(t, r) {
4
+ return t === r || t != t && r != r;
5
+ };
6
+
7
+ function e(r) {
8
+ const e = r.length;
9
+ return t(e), e / 2;
10
+ }
11
+
12
+ function n(e, n, i) {
13
+ const u = e.length;
14
+ t(u);
15
+ for (let t = 0; t < u; t += 2) if (r(e[t], n)) return;
16
+ e.push(n, i);
17
+ }
18
+
19
+ function i(e, n, i) {
20
+ const u = e.length;
21
+ t(u);
22
+ for (let t = 0; t < u; t += 2) if (r(e[t], n)) return void (e[t + 1] = i);
23
+ e.push(n, i);
24
+ }
25
+
26
+ function u(e, n) {
27
+ const i = e.length;
28
+ t(i);
29
+ for (let t = 0; t < i; t += 2) if (r(e[t], n)) return !0;
30
+ return !1;
31
+ }
32
+
33
+ function o(e, n) {
34
+ const i = e.length;
35
+ t(i);
36
+ for (let t = 1; t < i; t += 2) if (r(e[t], n)) return !0;
37
+ return !1;
38
+ }
39
+
40
+ function s(e, n) {
41
+ const i = e.length;
42
+ t(i);
43
+ for (let t = 0; t < i; t += 2) if (r(e[t], n)) return e[t + 1];
44
+ }
45
+
46
+ function f(e, n) {
47
+ const i = e.length;
48
+ t(i);
49
+ for (let t = 1; t < i; t += 2) if (r(e[t], n)) return e[t - 1];
50
+ }
51
+
52
+ function c(e, n) {
53
+ const i = e.length;
54
+ t(i);
55
+ for (let t = 0; t < i; t += 2) if (r(e[t], n)) return e.splice(t, 2), !0;
56
+ return !1;
57
+ }
58
+
59
+ function l(e, n) {
60
+ const i = e.length;
61
+ t(i);
62
+ for (let t = 1; t < i; t += 2) if (r(e[t], n)) return e.splice(t - 1, 2), !0;
63
+ return !1;
64
+ }
65
+
66
+ function h(r, e, n) {
67
+ const i = r.length;
68
+ t(i);
69
+ for (let t = 0; t < i; t += 2) t in r && e.call(n, r[t + 1], r[t], t, r);
70
+ }
71
+
72
+ function a(t) {
73
+ t.length = 0;
74
+ }
75
+
76
+ function d(r, e) {
77
+ const n = r.length;
78
+ t(n);
79
+ for (let t = 0; t < n; t += 2) {
80
+ if (e(r[t + 1], r[t], t, r)) return [ r[t], r[t + 1] ];
81
+ }
82
+ }
83
+
84
+ function y(r, e) {
85
+ const n = r.length;
86
+ t(n);
87
+ for (let t = 0; t < n; t += 2) {
88
+ if (e(r[t + 1], r[t], t, r)) return t;
89
+ }
90
+ return -1;
91
+ }
92
+
93
+ class m {
94
+ static from(t) {
95
+ if ("[object Map]" !== Object.prototype.toString.call(t)) throw new TypeError("[FlatPair: __func__] Argument must be a Map");
96
+ const r = [];
97
+ return t.forEach((t, e) => r.push(e, t)), new m(r);
98
+ }
99
+ t=[];
100
+ constructor(r) {
101
+ const e = r.length;
102
+ t(e), this.t = r.slice();
103
+ }
104
+ get size() {
105
+ return this.t.length / 2;
106
+ }
107
+ get array() {
108
+ return this.t;
109
+ }
110
+ add(t, r) {
111
+ return n(this.t, t, r), this;
112
+ }
113
+ set(t, r) {
114
+ return i(this.t, t, r), this;
115
+ }
116
+ hasByValue(t) {
117
+ return o(this.t, t);
118
+ }
119
+ remove(t) {
120
+ return c(this.t, t);
121
+ }
122
+ removeByValue(t) {
123
+ return l(this.t, t);
124
+ }
125
+ get(t) {
126
+ return s(this.t, t);
127
+ }
128
+ getByValue(t) {
129
+ return f(this.t, t);
130
+ }
131
+ find(t) {
132
+ return d(this.t, t);
133
+ }
134
+ findIndex(t) {
135
+ return y(this.t, t);
136
+ }
137
+ clear() {
138
+ this.t.length = 0;
139
+ }
140
+ has(t) {
141
+ return u(this.t, t);
142
+ }
143
+ forEach(t, r) {
144
+ h(this.t, t, r);
145
+ }
146
+ * keys() {
147
+ for (let t = 0; t < this.t.length; t += 2) yield this.t[t];
148
+ }
149
+ * values() {
150
+ for (let t = 1; t < this.t.length; t += 2) yield this.t[t];
151
+ }
152
+ * entries() {
153
+ for (let t = 0; t < this.t.length; t += 2) yield [ this.t[t], this.t[t + 1] ];
154
+ }
155
+ [Symbol.iterator]() {
156
+ return this.entries();
157
+ }
158
+ }
159
+
160
+ class g {
161
+ add(t, r, e) {
162
+ n(t, r, e);
163
+ }
164
+ set(t, r, e) {
165
+ i(t, r, e);
166
+ }
167
+ remove(t, r) {
168
+ return c(t, r);
169
+ }
170
+ get(t, r) {
171
+ return s(t, r);
172
+ }
173
+ getByValue(t, r) {
174
+ return f(t, r);
175
+ }
176
+ find(t, r) {
177
+ return d(t, r);
178
+ }
179
+ findIndex(t, r) {
180
+ return y(t, r);
181
+ }
182
+ removeByValue(t, r) {
183
+ return l(t, r);
184
+ }
185
+ forEach(t, r, e) {
186
+ h(t, r, e);
187
+ }
188
+ * keys(t) {
189
+ for (let r = 0; r < t.length; r += 2) yield t[r];
190
+ }
191
+ * values(t) {
192
+ for (let r = 1; r < t.length; r += 2) yield t[r];
193
+ }
194
+ * entries(t) {
195
+ for (let r = 0; r < t.length; r += 2) yield [ t[r], t[r + 1] ];
196
+ }
197
+ clear(t) {
198
+ t.length = 0;
199
+ }
200
+ has(t, r) {
201
+ return u(t, r);
202
+ }
203
+ hasByValue(t, r) {
204
+ return o(t, r);
205
+ }
206
+ }
207
+
208
+ 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,57 +1,36 @@
1
1
  {
2
- "name": "flat-pair",
3
- "version": "1.3.0",
4
- "author": {
5
- "name": "Kasukabe Tsumugi",
6
- "email": "futami16237@gmail.com"
7
- },
8
- "purpose": "npm",
9
- "description": "Using array to save pairs. Serializable and easier to find, locate by value. Provide static methods, use it at 0 cost!",
10
- "description_zh": "用数组来保存键值对。可序列化且更容易通过值查找、定位。提供静态方法,0成本使用!",
11
- "type": "module",
12
- "module": "./dist/index.mjs",
13
- "types": "./dist/index.d.ts",
14
- "exports": {
15
- "types": "./dist/index.d.ts",
16
- "import": "./dist/index.mjs",
17
- "default": "./dist/index.mjs"
18
- },
19
- "files": [
20
- "dist"
21
- ],
22
- "homepage": "https://github.com/baendlorel/flat-pair#readme",
23
- "repository": {
24
- "type": "git",
25
- "url": "https://github.com/baendlorel/flat-pair"
26
- },
27
- "keywords": [
28
- "typescript",
29
- "javascript"
30
- ],
31
- "scripts": {
32
- "test": "clear & vitest",
33
- "lint": "oxlint .",
34
- "cover": "clear & vitest --coverage",
35
- "build": "node ./.scripts/rollup.mjs"
36
- },
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
- }
57
- }
2
+ "name": "flat-pair",
3
+ "version": "1.3.3",
4
+ "author": {
5
+ "name": "Kasukabe Tsumugi",
6
+ "email": "futami16237@gmail.com"
7
+ },
8
+ "purpose": "npm",
9
+ "description": "Using array to save pairs. Serializable and easier to find, locate by value. Provide static methods, use it at 0 cost!",
10
+ "description_zh": "用数组来保存键值对。可序列化且更容易通过值查找、定位。提供静态方法,0成本使用!",
11
+ "type": "module",
12
+ "module": "./dist/index.mjs",
13
+ "types": "./dist/index.d.ts",
14
+ "exports": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.mjs",
17
+ "default": "./dist/index.mjs"
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "homepage": "https://github.com/baendlorel/kt-packages/tree/main/packages/flat-pair#readme",
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/baendlorel/kt-packages.git",
26
+ "directory": "packages/flat-pair"
27
+ },
28
+ "keywords": [
29
+ "typescript",
30
+ "javascript"
31
+ ],
32
+ "license": "MIT",
33
+ "bugs": {
34
+ "url": "https://github.com/baendlorel/kt-packages/issues"
35
+ }
36
+ }