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