@whitesev/utils 1.0.0 → 1.0.2

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.umd.js CHANGED
@@ -121,157 +121,6 @@
121
121
  }
122
122
  }
123
123
 
124
- class UtilsDictionary {
125
- items = {};
126
- /**
127
- * 检查是否有某一个键
128
- * @param key 键
129
- */
130
- has(key) {
131
- return this.items.hasOwnProperty(key);
132
- }
133
- /**
134
- * 检查已有的键中是否以xx开头
135
- * @param key 需要匹配的键
136
- */
137
- startsWith(key) {
138
- let allKeys = this.keys();
139
- for (const keyName of allKeys) {
140
- if (keyName.startsWith(key)) {
141
- return true;
142
- }
143
- }
144
- return false;
145
- }
146
- /**
147
- * 获取以xx开头的键的值
148
- * @param key 需要匹配的键
149
- */
150
- getStartsWith(key) {
151
- let allKeys = this.keys();
152
- for (const keyName of allKeys) {
153
- if (keyName.startsWith(key)) {
154
- return this.getItems()[keyName];
155
- }
156
- }
157
- }
158
- /**
159
- * 为字典添加某一个值
160
- * @param key 键
161
- * @param val 值,默认为""
162
- */
163
- set(key, val) {
164
- if (key === void 0) {
165
- throw new Error("Utils.Dictionary().set 参数 key 不能为空");
166
- }
167
- this.items[key] = val;
168
- }
169
- /**
170
- * 删除某一个键
171
- * @param key 键
172
- */
173
- delete(key) {
174
- if (this.has(key)) {
175
- Reflect.deleteProperty(this.items, key);
176
- return true;
177
- }
178
- return false;
179
- }
180
- /**
181
- * 获取某个键的值
182
- * @param key 键
183
- */
184
- get(key) {
185
- return this.getItems()[key];
186
- }
187
- /**
188
- * 返回字典中的所有值
189
- */
190
- values() {
191
- let resultList = [];
192
- for (let prop in this.items) {
193
- if (this.has(prop)) {
194
- resultList.push(this.items[prop]);
195
- }
196
- }
197
- return resultList;
198
- }
199
- /**
200
- * 清空字典
201
- */
202
- clear() {
203
- this.items = void 0;
204
- this.items = {};
205
- }
206
- /**
207
- * 获取字典的长度
208
- */
209
- size() {
210
- return Object.keys(this.items).length;
211
- }
212
- /**
213
- * 获取字典所有的键
214
- */
215
- keys() {
216
- return Object.keys(this.items);
217
- }
218
- /**
219
- * 返回字典本身
220
- * @returns
221
- */
222
- getItems() {
223
- return this.items;
224
- }
225
- /**
226
- * 合并另一个字典
227
- * @param data 需要合并的字典
228
- */
229
- concat(data) {
230
- this.items = utils.assign(this.items, data.getItems());
231
- }
232
- /**
233
- * 循环字典
234
- */
235
- forEach(callbackfn) {
236
- for (const key in this.getItems()) {
237
- callbackfn(this.get(key), key, this.getItems());
238
- }
239
- }
240
- /**
241
- * 获取字典的长度,同this.size
242
- */
243
- get length() {
244
- return this.size();
245
- }
246
- /**
247
- * 迭代器
248
- */
249
- get entries() {
250
- let that = this;
251
- return function* () {
252
- let itemKeys = Object.keys(that.getItems());
253
- for (const keyName of itemKeys) {
254
- yield [keyName, that.get(keyName)];
255
- }
256
- };
257
- }
258
- /**
259
- * 是否可遍历
260
- */
261
- get [Symbol.iterator]() {
262
- let that = this;
263
- return function () {
264
- return that.entries();
265
- };
266
- }
267
- /**
268
- * .toString()和.toLocaleString()输出的字符串
269
- */
270
- get [Symbol.toStringTag]() {
271
- return "UtilsDictionary";
272
- }
273
- }
274
-
275
124
  class GBKEncoder {
276
125
  #data = [];
277
126
  #U2Ghash = {};
@@ -525,12 +374,10 @@
525
374
  }
526
375
  }
527
376
 
528
- // ==UserScript==
529
377
  // @name ajaxHooker
530
378
  // @author cxxjackie
531
379
  // @version 1.4.1
532
380
  // @supportURL https://bbs.tampermonkey.net.cn/thread-3284-1-1.html
533
- // ==/UserScript==
534
381
 
535
382
  var ajaxHooker = (function () {
536
383
  const version = "1.4.1";
@@ -3194,6 +3041,162 @@
3194
3041
  return tryCatchObj;
3195
3042
  };
3196
3043
 
3044
+ class UtilsDictionary {
3045
+ items = {};
3046
+ /**
3047
+ * 检查是否有某一个键
3048
+ * @param {string} key 键
3049
+ * @returns {boolean}
3050
+ */
3051
+ has(key) {
3052
+ return this.items.hasOwnProperty(key);
3053
+ }
3054
+ /**
3055
+ * 检查已有的键中是否以xx开头
3056
+ * @param {string} key 需要匹配的键
3057
+ * @returns {boolean}
3058
+ */
3059
+ startsWith(key) {
3060
+ let allKeys = this.keys();
3061
+ for (const keyName of allKeys) {
3062
+ if (keyName.startsWith(key)) {
3063
+ return true;
3064
+ }
3065
+ }
3066
+ return false;
3067
+ }
3068
+ /**
3069
+ * 获取以xx开头的键的值
3070
+ * @param {string} key 需要匹配的键
3071
+ * @returns {any}
3072
+ */
3073
+ getStartsWith(key) {
3074
+ let allKeys = this.keys();
3075
+ for (const keyName of allKeys) {
3076
+ if (keyName.startsWith(key)) {
3077
+ return this.items[keyName];
3078
+ }
3079
+ }
3080
+ }
3081
+ /**
3082
+ * 为字典添加某一个值
3083
+ * @param {string} key 键
3084
+ * @param {any} val 值,默认为""
3085
+ */
3086
+ set(key, val = "") {
3087
+ if (key === void 0) {
3088
+ throw new Error("Utils.Dictionary().set 参数 key 不能为空");
3089
+ }
3090
+ this.items[key] = val;
3091
+ }
3092
+ /**
3093
+ * 删除某一个键
3094
+ * @param {string} key 键
3095
+ * @returns {boolean}
3096
+ */
3097
+ delete(key) {
3098
+ if (this.has(key)) {
3099
+ Reflect.deleteProperty(this.items, key);
3100
+ return true;
3101
+ }
3102
+ return false;
3103
+ }
3104
+ /**
3105
+ * 获取某个键的值
3106
+ * @param {string} key 键
3107
+ * @returns {any}
3108
+ */
3109
+ get(key) {
3110
+ return this.has(key) ? this.items[key] : void 0;
3111
+ }
3112
+ /**
3113
+ * 返回字典中的所有值
3114
+ * @returns {any[]}
3115
+ */
3116
+ values() {
3117
+ let resultList = [];
3118
+ for (let prop in this.items) {
3119
+ if (this.has(prop)) {
3120
+ resultList.push(this.items[prop]);
3121
+ }
3122
+ }
3123
+ return resultList;
3124
+ }
3125
+ /**
3126
+ * 清空字典
3127
+ */
3128
+ clear() {
3129
+ this.items = null;
3130
+ this.items = {};
3131
+ }
3132
+ /**
3133
+ * 获取字典的长度
3134
+ * @returns {number}
3135
+ */
3136
+ size() {
3137
+ return Object.keys(this.items).length;
3138
+ }
3139
+ /**
3140
+ * 获取字典所有的键
3141
+ */
3142
+ keys() {
3143
+ return Object.keys(this.items);
3144
+ }
3145
+ /**
3146
+ * 返回字典本身
3147
+ * @returns {object}
3148
+ */
3149
+ getItems() {
3150
+ return this.items;
3151
+ }
3152
+ /**
3153
+ * 合并另一个字典
3154
+ * @param {object} data 需要合并的字典
3155
+ */
3156
+ concat(data) {
3157
+ this.items = Utils.assign(this.items, data.getItems());
3158
+ }
3159
+ forEach(callbackfn) {
3160
+ for (const key in this.items) {
3161
+ callbackfn(this.get(key), key, this.items);
3162
+ }
3163
+ }
3164
+ /**
3165
+ * 获取字典的长度,同this.size
3166
+ * @returns {number}
3167
+ */
3168
+ get length() {
3169
+ return this.size();
3170
+ }
3171
+ /**
3172
+ * 迭代器
3173
+ */
3174
+ get entries() {
3175
+ let that = this;
3176
+ return function* () {
3177
+ let itemKeys = Object.keys(that.getItems());
3178
+ for (const keyName of itemKeys) {
3179
+ yield [keyName, that.get(keyName)];
3180
+ }
3181
+ };
3182
+ }
3183
+ /**
3184
+ * 是否可遍历
3185
+ */
3186
+ get [Symbol.iterator]() {
3187
+ let that = this;
3188
+ return function () {
3189
+ return that.entries();
3190
+ };
3191
+ }
3192
+ /**
3193
+ * .toString()和.toLocaleString()输出的字符串
3194
+ */
3195
+ get [Symbol.toStringTag]() {
3196
+ return "UtilsDictionary";
3197
+ }
3198
+ }
3199
+
3197
3200
  let Utils$1 = class Utils {
3198
3201
  /** 版本号 */
3199
3202
  version = "2024.5.24";