@whitesev/utils 2.11.12 → 2.11.13

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.
@@ -83,9 +83,20 @@ export declare class UtilsDictionary<K, V> {
83
83
  concat(data: UtilsDictionary<K, V>): void;
84
84
  /**
85
85
  * 迭代字典
86
- * @param callbackfn 回调函数
86
+ * @param cb 回调函数
87
87
  */
88
- forEach(callbackfn: (value: V, key: K, dictionary: UtilsDictionary<K, V>) => void): void;
88
+ forEach(cb: (value: V, key: K, dictionary: UtilsDictionary<K, V>) => void): void;
89
+ /**
90
+ * 找到字典中对应的键和值
91
+ * @param cb 回调函数
92
+ */
93
+ find(cb: (value: V, key: K, dictionary: UtilsDictionary<K, V>) => {
94
+ key: K;
95
+ value: V;
96
+ } | void): {
97
+ key: K;
98
+ value: V;
99
+ } | undefined;
89
100
  /**
90
101
  * 检查已有的键中是否以xx开头
91
102
  * @param key 需要匹配的键
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@whitesev/utils",
4
- "version": "2.11.12",
4
+ "version": "2.11.13",
5
5
  "description": "一个常用的工具库",
6
6
  "keywords": [
7
7
  "ScriptCat",
package/src/Dictionary.ts CHANGED
@@ -167,13 +167,34 @@ export class UtilsDictionary<K, V> {
167
167
  }
168
168
  /**
169
169
  * 迭代字典
170
- * @param callbackfn 回调函数
170
+ * @param cb 回调函数
171
171
  */
172
- forEach(callbackfn: (value: V, key: K, dictionary: UtilsDictionary<K, V>) => void) {
172
+ forEach(cb: (value: V, key: K, dictionary: UtilsDictionary<K, V>) => void) {
173
173
  this.items.forEach((value, key) => {
174
- callbackfn(value, key, this);
174
+ cb(value, key, this);
175
175
  });
176
176
  }
177
+ /**
178
+ * 找到字典中对应的键和值
179
+ * @param cb 回调函数
180
+ */
181
+ find(
182
+ cb: (
183
+ value: V,
184
+ key: K,
185
+ dictionary: UtilsDictionary<K, V>
186
+ ) => {
187
+ key: K;
188
+ value: V;
189
+ } | void
190
+ ) {
191
+ for (const [key, value] of this.items.entries()) {
192
+ const result = cb(value, key, this);
193
+ if (result) {
194
+ return result;
195
+ }
196
+ }
197
+ }
177
198
  /**
178
199
  * 检查已有的键中是否以xx开头
179
200
  * @param key 需要匹配的键